|
1 | 1 | package graphql |
2 | 2 |
|
3 | 3 | import graphql.language.Document |
| 4 | +import graphql.language.SourceLocation |
4 | 5 | import graphql.parser.InvalidSyntaxException |
5 | 6 | import graphql.parser.Parser |
6 | | -import graphql.schema.GraphQLSchema |
7 | 7 | import graphql.schema.idl.SchemaParser |
8 | | -import graphql.schema.idl.TypeDefinitionRegistry |
9 | 8 | import graphql.schema.idl.UnExecutableSchemaGenerator |
10 | 9 | import graphql.validation.ValidationError |
11 | 10 | import graphql.validation.ValidationErrorType |
@@ -162,29 +161,50 @@ class ParseAndValidateTest extends Specification { |
162 | 161 | !rs.errors.isEmpty() // all rules apply - we have errors |
163 | 162 | } |
164 | 163 |
|
165 | | - def "issue 2740 - evidence of not working"() { |
| 164 | + def "validation error raised if mutation operation does not exist in schema"() { |
166 | 165 | def sdl = ''' |
167 | 166 | type Query { |
168 | | - myquery : String! |
| 167 | + myQuery : String! |
169 | 168 | } |
170 | 169 | ''' |
171 | 170 |
|
172 | 171 | def registry = new SchemaParser().parse(sdl) |
173 | 172 | def schema = UnExecutableSchemaGenerator.makeUnExecutableSchema(registry) |
174 | | - def graphQL = GraphQL.newGraphQL(schema).build() |
175 | | - |
176 | | - String request = "mutation MyMutation { mymutation }" |
| 173 | + String request = "mutation MyMutation { myMutation }" |
177 | 174 |
|
178 | 175 | when: |
179 | | - def er = graphQL.execute(request) |
| 176 | + Document inputDocument = new Parser().parseDocument(request) |
| 177 | + List<ValidationError> errors = ParseAndValidate.validate(schema, inputDocument) |
| 178 | + |
180 | 179 | then: |
181 | | - er.errors.size() == 1 |
| 180 | + errors.size() == 1 |
| 181 | + def error = errors.first() |
| 182 | + error.validationErrorType == ValidationErrorType.UnknownOperation |
| 183 | + error.message == "Validation error (UnknownOperation): The 'MUTATION' operation is not supported by the schema" |
| 184 | + error.locations == [new SourceLocation(1, 1)] |
| 185 | + } |
| 186 | + |
| 187 | + def "validation error raised if subscription operation does not exist in schema"() { |
| 188 | + def sdl = ''' |
| 189 | + type Query { |
| 190 | + myQuery : String! |
| 191 | + } |
| 192 | + ''' |
| 193 | + |
| 194 | + def registry = new SchemaParser().parse(sdl) |
| 195 | + def schema = UnExecutableSchemaGenerator.makeUnExecutableSchema(registry) |
| 196 | + |
| 197 | + String request = "subscription MySubscription { mySubscription }" |
182 | 198 |
|
183 | 199 | when: |
184 | 200 | Document inputDocument = new Parser().parseDocument(request) |
185 | 201 | List<ValidationError> errors = ParseAndValidate.validate(schema, inputDocument) |
186 | 202 |
|
187 | 203 | then: |
188 | 204 | errors.size() == 1 |
| 205 | + def error = errors.first() |
| 206 | + error.validationErrorType == ValidationErrorType.UnknownOperation |
| 207 | + error.message == "Validation error (UnknownOperation): The 'SUBSCRIPTION' operation is not supported by the schema" |
| 208 | + error.locations == [new SourceLocation(1, 1)] |
189 | 209 | } |
190 | 210 | } |
0 commit comments