Skip to content

Commit c467a02

Browse files
committed
Add extra test to demonstrate all operations are checked in a document
1 parent 896440c commit c467a02

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

src/test/groovy/graphql/ParseAndValidateTest.groovy

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,4 +207,32 @@ class ParseAndValidateTest extends Specification {
207207
error.message == "Validation error (UnknownOperation): The 'Subscription' operation is not supported by the schema"
208208
error.locations == [new SourceLocation(1, 1)]
209209
}
210+
211+
def "known operation validation rule checks all operations in document"() {
212+
def sdl = '''
213+
type Query {
214+
myQuery : String!
215+
}
216+
'''
217+
218+
def registry = new SchemaParser().parse(sdl)
219+
def schema = UnExecutableSchemaGenerator.makeUnExecutableSchema(registry)
220+
String request = "mutation MyMutation { myMutation } subscription MySubscription { mySubscription }"
221+
222+
when:
223+
Document inputDocument = new Parser().parseDocument(request)
224+
List<ValidationError> errors = ParseAndValidate.validate(schema, inputDocument)
225+
226+
then:
227+
errors.size() == 2
228+
def error1 = errors.get(0)
229+
error1.validationErrorType == ValidationErrorType.UnknownOperation
230+
error1.message == "Validation error (UnknownOperation): The 'Mutation' operation is not supported by the schema"
231+
error1.locations == [new SourceLocation(1, 1)]
232+
233+
def error2 = errors.get(1)
234+
error2.validationErrorType == ValidationErrorType.UnknownOperation
235+
error2.message == "Validation error (UnknownOperation): The 'Subscription' operation is not supported by the schema"
236+
error2.locations == [new SourceLocation(1, 36)]
237+
}
210238
}

0 commit comments

Comments
 (0)