Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/antlr/GraphqlSDL.g4
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ schemaExtension :
EXTEND SCHEMA directives
;

operationTypeDefinition : description? operationType ':' typeName;
operationTypeDefinition : operationType ':' typeName;

typeDefinition:
scalarTypeDefinition |
Expand Down
61 changes: 60 additions & 1 deletion src/test/groovy/graphql/parser/SDLParserTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """
Expand Down Expand Up @@ -1069,4 +1129,3 @@ directive @myDirective on
e.offendingToken == "<EOF>"
}
}