Skip to content

Commit

Permalink
fix: fix values validation list compatibility check (#1082)
Browse files Browse the repository at this point in the history
  • Loading branch information
devsergiy authored Feb 19, 2025
1 parent ffae4ba commit 541be0d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
9 changes: 3 additions & 6 deletions v2/pkg/astvalidation/operation_rule_values.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package astvalidation

import (
"bytes"

"github.com/wundergraph/graphql-go-tools/v2/pkg/federation"

"github.com/wundergraph/graphql-go-tools/v2/pkg/ast"
Expand Down Expand Up @@ -222,12 +223,8 @@ func (v *valuesVisitor) valueSatisfiesListType(value ast.Value, definitionTypeRe
}

expectedType := v.importer.ImportType(listItemType, v.definition, v.operation)
if v.operation.Types[actualType].TypeKind == ast.TypeKindNonNull {
actualType = v.operation.Types[actualType].OfType
}
if v.operation.Types[actualType].TypeKind == ast.TypeKindList {
actualType = v.operation.Types[actualType].OfType
}
actualType = v.operation.ResolveUnderlyingType(actualType)

if !v.operation.TypesAreEqualDeep(expectedType, actualType) {
v.handleVariableHasIncompatibleTypeError(value, definitionTypeRef)
return false
Expand Down
27 changes: 26 additions & 1 deletion v2/pkg/astvalidation/operation_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package astvalidation

import (
"fmt"
"testing"

"github.com/wundergraph/graphql-go-tools/v2/pkg/apollocompatibility"
"github.com/wundergraph/graphql-go-tools/v2/pkg/errorcodes"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -3947,6 +3948,30 @@ func TestExecutionValidation(t *testing.T) {
`Variable "$a" of type "Boolean" used in position expecting type "[String]"`,
))
})

t.Run("complex nested optionalListOfOptionalStrings of type [String] should accept more restrictive type [String!]!", func(t *testing.T) {
runWithDefinition(t, `
scalar String
schema {
query: Query
}
type Query {
nested(input: NestedInput): String
}
input NestedInput {
optionalListOfOptionalStrings: [String]
}
`, `
query Q($a: [String!]!) {
nested(input: {
optionalListOfOptionalStrings: $a
})
}
`, Values(), Valid)
})
})
})
}
Expand Down

0 comments on commit 541be0d

Please sign in to comment.