File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed
Sources/GraphQL/Utilities
Tests/GraphQLTests/UtilitiesTests Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,10 @@ func valueFromAST(
2323 variables: [ String : Map ] = [ : ]
2424) throws -> Map {
2525 if let nonNull = type as? GraphQLNonNull {
26+ guard !( valueAST is NullValue ) else {
27+ throw GraphQLError ( message: " Null value provided to non-nullable type " )
28+ }
29+
2630 // Note: we're not checking that the result of valueFromAST is non-null.
2731 // We're assuming that this query has been validated and the value used
2832 // here is of the correct type.
@@ -32,6 +36,10 @@ func valueFromAST(
3236 return try valueFromAST ( valueAST: valueAST, type: nonNullType, variables: variables)
3337 }
3438
39+ guard !( valueAST is NullValue ) else {
40+ return . null
41+ }
42+
3543 if let variable = valueAST as? Variable {
3644 let variableName = variable. name. value
3745
Original file line number Diff line number Diff line change @@ -1186,4 +1186,23 @@ import Testing
11861186 // 'mutation' operation.
11871187 #expect( schema. mutationType == nil )
11881188 }
1189+
1190+ @Test func supportsNullLiterals( ) throws {
1191+ let sdl = """
1192+ input MyInput {
1193+ nullLiteral: String!
1194+ }
1195+
1196+ type Query {
1197+ field(in: MyInput = null): String
1198+ }
1199+ """
1200+ try #expect( cycleSDL ( sdl: sdl) == sdl)
1201+
1202+ let schema = try buildSchema ( source: sdl)
1203+
1204+ let rootFields = try #require( schema. getType ( name: " Query " ) as? GraphQLObjectType )
1205+ . getFields ( )
1206+ #expect( rootFields [ " field " ] ? . args [ 0 ] . defaultValue == . null)
1207+ }
11891208}
You can’t perform that action at this time.
0 commit comments