Skip to content

Commit bd86537

Browse files
authored
fix: accept empty lists for non-null list items (#1600)
## Summary - Accept empty list defaults for GraphQL list types with non-null items in operation-level validation. - Preserve validation of invalid non-empty list elements. - Add regression coverage for `[]` defaults and invalid enum-list defaults. ## Links - **Linear**: https://linear.app/wundergraph/issue/ENG-9882/string-cannot-represent-value - **Cosmo issue**: wundergraph/cosmo#3095 ## Verification - `go test ./pkg/astvalidation/reference/testsgo -run "^TestValuesOfCorrectTypeRule$" -count=1` - `go test ./...` from `v2` - Cosmo staged regression and race test passed against this fixed local module revision.
1 parent bbb3db1 commit bd86537

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

v2/pkg/astvalidation/operation_rule_values.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ func (v *valuesVisitor) valueSatisfiesOperationListType(value ast.Value, operati
140140

141141
if v.operation.Types[listItemType].TypeKind == ast.TypeKindNonNull {
142142
if len(v.operation.ListValues[value.Ref].Refs) == 0 {
143-
v.handleOperationTypeError(value, operationTypeRef)
144-
return false
143+
// [] empty list is a valid input for [item!] lists
144+
return true
145145
}
146146
listItemType = v.operation.Types[listItemType].OfType
147147
}

v2/pkg/astvalidation/reference/testsgo/ValuesOfCorrectTypeRule_test.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,9 +1010,13 @@ func TestValuesOfCorrectTypeRule(t *testing.T) {
10101010
$a: Int = 1,
10111011
$b: String = "ok",
10121012
$c: ComplexInput = { requiredField: true, intField: 3 }
1013-
$d: Int! = 123
1013+
$d: Int! = 123,
1014+
$values: [String!] = []
10141015
) {
10151016
dog { name }
1017+
complicatedArgs {
1018+
stringListNonNullArgField(stringListNonNullArg: $values)
1019+
}
10161020
}
10171021
`)
10181022
})
@@ -1059,7 +1063,8 @@ func TestValuesOfCorrectTypeRule(t *testing.T) {
10591063
query InvalidDefaultValues(
10601064
$a: Int = "one",
10611065
$b: String = 4,
1062-
$c: ComplexInput = "NotVeryComplex"
1066+
$c: ComplexInput = "NotVeryComplex",
1067+
$commands: [DogCommand!] = [INVALID]
10631068
) {
10641069
dog { name }
10651070
}
@@ -1076,6 +1081,10 @@ func TestValuesOfCorrectTypeRule(t *testing.T) {
10761081
message: `Expected value of type "ComplexInput", found "NotVeryComplex".`,
10771082
locations: []Loc{{line: 5, column: 30}},
10781083
},
1084+
{
1085+
message: `Value "INVALID" does not exist in "DogCommand" enum.`,
1086+
locations: []Loc{{line: 6, column: 39}},
1087+
},
10791088
})
10801089
})
10811090

0 commit comments

Comments
 (0)