Skip to content

Commit 1bc1810

Browse files
committed
add test for non-null argument
1 parent 4592d89 commit 1bc1810

1 file changed

Lines changed: 30 additions & 2 deletions

File tree

src/test/groovy/graphql/GraphQLTest.groovy

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package graphql
22

33
import graphql.language.SourceLocation
4-
import graphql.schema.GraphQLArgument
54
import graphql.schema.GraphQLFieldDefinition
5+
import graphql.schema.GraphQLNonNull
66
import graphql.schema.GraphQLObjectType
77
import graphql.schema.GraphQLSchema
8+
import graphql.validation.ValidationErrorType
89
import spock.lang.Specification
910

1011
import static graphql.Scalars.GraphQLString
12+
import static graphql.schema.GraphQLArgument.newArgument
1113
import static graphql.schema.GraphQLFieldDefinition.newFieldDefinition
1214
import static graphql.schema.GraphQLObjectType.newObject
1315
import static graphql.schema.GraphQLSchema.newSchema
@@ -77,7 +79,7 @@ class GraphQLTest extends Specification {
7779
GraphQLFieldDefinition fieldDefinition = newFieldDefinition()
7880
.name("hello")
7981
.type(GraphQLString)
80-
.argument(GraphQLArgument.newArgument().name("arg").type(GraphQLString).build())
82+
.argument(newArgument().name("arg").type(GraphQLString).build())
8183
.staticValue("world")
8284
.build()
8385
GraphQLSchema schema = newSchema().query(
@@ -127,4 +129,30 @@ class GraphQLTest extends Specification {
127129
errors[0].errorType == ErrorType.InvalidSyntax
128130
errors[0].sourceLocations == [new SourceLocation(1, 7)]
129131
}
132+
133+
def "non null argument is missing"() {
134+
given:
135+
GraphQLSchema schema = newSchema().query(
136+
newObject()
137+
.name("RootQueryType")
138+
.field(newFieldDefinition()
139+
.name("field")
140+
.type(GraphQLString)
141+
.argument(newArgument()
142+
.name("arg")
143+
.type(new GraphQLNonNull(GraphQLString))
144+
.build())
145+
.build())
146+
.build()
147+
).build()
148+
149+
when:
150+
def errors = new GraphQL(schema).execute('{ field }').errors
151+
152+
then:
153+
errors.size() == 1
154+
errors[0].errorType == ErrorType.ValidationError
155+
errors[0].validationErrorType == ValidationErrorType.MissingFieldArgument
156+
errors[0].sourceLocations == [new SourceLocation(1, 3)]
157+
}
130158
}

0 commit comments

Comments
 (0)