Skip to content

Commit 7ca72d4

Browse files
committed
Fixes #903 as well as adds & support for implements declarations
1 parent dbfc085 commit 7ca72d4

File tree

2 files changed

+68
-2
lines changed

2 files changed

+68
-2
lines changed

src/main/antlr/Graphql.g4

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,13 @@ inputObjectTypeDefinition
145145

146146
scalarTypeDefinition : description? SCALAR name directives?;
147147

148-
objectTypeDefinition : description? TYPE name implementsInterfaces? directives? '{' fieldDefinition+ '}';
148+
objectTypeDefinition : description? TYPE name implementsInterfaces? directives? fieldsDefinition?;
149149

150-
implementsInterfaces : IMPLEMENTS typeName+;
150+
implementsInterfaces :
151+
IMPLEMENTS '&'? typeName+ |
152+
implementsInterfaces '&' typeName ;
153+
154+
fieldsDefinition : '{' fieldDefinition+ '}';
151155

152156
fieldDefinition : description? name argumentsDefinition? ':' type directives?;
153157

src/test/groovy/graphql/parser/IDLParserTest.groovy

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,5 +520,67 @@ input Gun {
520520
commentContent(inputValueDefinitions[1].comments) == [" second"]
521521
}
522522

523+
def "empty type definition"() {
524+
525+
def input = """
526+
type EmptyType
527+
528+
extend type EmptyType {
529+
hero : String
530+
}
531+
"""
532+
when:
533+
def document = new Parser().parseDocument(input)
534+
535+
then:
536+
ObjectTypeDefinition typeDef = document.definitions[0] as ObjectTypeDefinition
537+
typeDef.getName() == 'EmptyType'
538+
typeDef.getFieldDefinitions().isEmpty()
539+
540+
TypeExtensionDefinition extTypeDef = document.definitions[1] as TypeExtensionDefinition
541+
extTypeDef.getName() == 'EmptyType'
542+
extTypeDef.getFieldDefinitions().size() == 1
543+
}
544+
545+
def "type implements can have & character for extra names"() {
546+
547+
def input = """
548+
interface Bar {
549+
bar : String
550+
}
551+
552+
interface Baz {
553+
baz : String
554+
}
555+
556+
type Foo implements Bar & Baz {
557+
bar : String
558+
baz : String
559+
}
560+
561+
type Foo2 implements Bar Baz {
562+
bar : String
563+
baz : String
564+
}
565+
566+
"""
567+
when:
568+
def document = new Parser().parseDocument(input)
569+
570+
then:
571+
ObjectTypeDefinition typeDef = document.definitions[2] as ObjectTypeDefinition
572+
typeDef.getName() == 'Foo'
573+
typeDef.getImplements().size() == 2
574+
(typeDef.getImplements()[0] as TypeName).getName() == 'Bar'
575+
(typeDef.getImplements()[1] as TypeName).getName() == 'Baz'
576+
577+
then:
578+
ObjectTypeDefinition typeDef2 = document.definitions[3] as ObjectTypeDefinition
579+
typeDef2.getName() == 'Foo2'
580+
typeDef2.getImplements().size() == 2
581+
(typeDef2.getImplements()[0] as TypeName).getName() == 'Bar'
582+
(typeDef2.getImplements()[1] as TypeName).getName() == 'Baz'
583+
}
584+
523585
}
524586

0 commit comments

Comments
 (0)