|
1 | 1 | package graphql |
2 | 2 |
|
3 | 3 | import graphql.language.SourceLocation |
4 | | -import graphql.schema.GraphQLArgument |
5 | 4 | import graphql.schema.GraphQLFieldDefinition |
| 5 | +import graphql.schema.GraphQLNonNull |
6 | 6 | import graphql.schema.GraphQLObjectType |
7 | 7 | import graphql.schema.GraphQLSchema |
| 8 | +import graphql.validation.ValidationErrorType |
8 | 9 | import spock.lang.Specification |
9 | 10 |
|
10 | 11 | import static graphql.Scalars.GraphQLString |
| 12 | +import static graphql.schema.GraphQLArgument.newArgument |
11 | 13 | import static graphql.schema.GraphQLFieldDefinition.newFieldDefinition |
12 | 14 | import static graphql.schema.GraphQLObjectType.newObject |
13 | 15 | import static graphql.schema.GraphQLSchema.newSchema |
@@ -77,7 +79,7 @@ class GraphQLTest extends Specification { |
77 | 79 | GraphQLFieldDefinition fieldDefinition = newFieldDefinition() |
78 | 80 | .name("hello") |
79 | 81 | .type(GraphQLString) |
80 | | - .argument(GraphQLArgument.newArgument().name("arg").type(GraphQLString).build()) |
| 82 | + .argument(newArgument().name("arg").type(GraphQLString).build()) |
81 | 83 | .staticValue("world") |
82 | 84 | .build() |
83 | 85 | GraphQLSchema schema = newSchema().query( |
@@ -127,4 +129,30 @@ class GraphQLTest extends Specification { |
127 | 129 | errors[0].errorType == ErrorType.InvalidSyntax |
128 | 130 | errors[0].sourceLocations == [new SourceLocation(1, 7)] |
129 | 131 | } |
| 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 | + } |
130 | 158 | } |
0 commit comments