From 13dc73df5a1178aa24a4deeb237e5c1a51a68b14 Mon Sep 17 00:00:00 2001 From: Andreas Marek Date: Wed, 20 May 2026 18:41:21 +1000 Subject: [PATCH] Disallow descriptions on root operation mappings --- src/main/antlr/GraphqlSDL.g4 | 2 +- .../graphql/parser/SDLParserTest.groovy | 61 ++++++++++++++++++- 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/src/main/antlr/GraphqlSDL.g4 b/src/main/antlr/GraphqlSDL.g4 index 9c4ef2a4f1..93331d3e8f 100644 --- a/src/main/antlr/GraphqlSDL.g4 +++ b/src/main/antlr/GraphqlSDL.g4 @@ -19,7 +19,7 @@ schemaExtension : EXTEND SCHEMA directives ; -operationTypeDefinition : description? operationType ':' typeName; +operationTypeDefinition : operationType ':' typeName; typeDefinition: scalarTypeDefinition | diff --git a/src/test/groovy/graphql/parser/SDLParserTest.groovy b/src/test/groovy/graphql/parser/SDLParserTest.groovy index 928619cf23..fc0c019b8f 100644 --- a/src/test/groovy/graphql/parser/SDLParserTest.groovy +++ b/src/test/groovy/graphql/parser/SDLParserTest.groovy @@ -309,6 +309,66 @@ schema @d1 @d2 { isEqual(document.definitions[0], schema.build()) } + def "schema definition can have a description"() { + given: + def input = ''' +"Schema description" +schema { + query: OpType1 +} +''' + + when: + def document = new Parser().parseDocument(input) + + then: + document.definitions.size() == 1 + SchemaDefinition schemaDefinition = document.definitions[0] as SchemaDefinition + schemaDefinition.description.content == "Schema description" + schemaDefinition.operationTypeDefinitions[0].name == "query" + schemaDefinition.operationTypeDefinitions[0].typeName.name == "OpType1" + } + + def "schema root operation type mapping cannot have a description"() { + given: + def input = ''' +schema { + "Query root operation mapping" + query: Query +} +''' + + when: + new Parser().parseDocument(input) + + then: + def e = thrown(InvalidSyntaxException) + + e.location.line == 3 + e.location.column == 5 + e.offendingToken == '"Query root operation mapping"' + } + + def "schema extension root operation type mapping cannot have a description"() { + given: + def input = ''' +extend schema { + "Query root operation mapping" + query: Query +} +''' + + when: + new Parser().parseDocument(input) + + then: + def e = thrown(InvalidSyntaxException) + + e.location.line == 3 + e.location.column == 5 + e.offendingToken == '"Query root operation mapping"' + } + def "extend schema"() { given: def input = """ @@ -1069,4 +1129,3 @@ directive @myDirective on e.offendingToken == "" } } -