Skip to content

Commit fa0b19b

Browse files
committed
null default variable value fix
1 parent 9b5a295 commit fa0b19b

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

‎src/main/java/graphql/validation/rules/VariablesTypesMatcher.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33

44
import graphql.Internal;
5+
import graphql.language.NullValue;
56
import graphql.language.Value;
67
import graphql.schema.GraphQLType;
78

@@ -18,7 +19,7 @@ public boolean doesVariableTypesMatch(GraphQLType variableType, Value variableDe
1819
}
1920

2021
public GraphQLType effectiveType(GraphQLType variableType, Value defaultValue) {
21-
if (defaultValue == null) {
22+
if (defaultValue == null || defaultValue instanceof NullValue) {
2223
return variableType;
2324
}
2425
if (isNonNull(variableType)) {

‎src/test/groovy/graphql/GraphQLTest.groovy‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,5 +1125,22 @@ many lines''']
11251125
11261126
}
11271127
1128+
def "null variable default value produces error for non null argument"() {
1129+
given:
1130+
def spec = """type Query {
1131+
sayHello(name: String!): String
1132+
}"""
1133+
DataFetcher df = { dfe ->
1134+
return dfe.getArgument("name")
1135+
} as DataFetcher
1136+
def graphQL = TestUtil.graphQL(spec, ["Query": ["sayHello": df]]).build()
1137+
1138+
when:
1139+
def errors = graphQL.execute('query($var:String=null){sayHello(name:$var)}').getErrors();
1140+
1141+
then:
1142+
errors.size() == 1
1143+
1144+
}
11281145
11291146
}

0 commit comments

Comments
 (0)