File tree Expand file tree Collapse file tree 4 files changed +46
-6
lines changed
test/groovy/graphql/parser Expand file tree Collapse file tree 4 files changed +46
-6
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ operationType : SUBSCRIPTION | MUTATION | QUERY;
44
55description : stringValue;
66
7- enumValue : name ;
7+ enumValue : enumValueName ;
88
99
1010arrayValue : ' [' value* ' ]' ;
@@ -28,7 +28,11 @@ arguments : '(' argument+ ')';
2828
2929argument : name ' :' valueWithVariable;
3030
31- name : NAME | FRAGMENT | QUERY | MUTATION | SUBSCRIPTION | SCHEMA | SCALAR | TYPE | INTERFACE | IMPLEMENTS | ENUM | UNION | INPUT | EXTEND | DIRECTIVE ;
31+ baseName : NAME | FRAGMENT | QUERY | MUTATION | SUBSCRIPTION | SCHEMA | SCALAR | TYPE | INTERFACE | IMPLEMENTS | ENUM | UNION | INPUT | EXTEND | DIRECTIVE ;
32+ fragmentName : baseName | BooleanValue | NullValue;
33+ enumValueName : baseName | ON_KEYWORD ;
34+
35+ name : baseName | BooleanValue | NullValue | ON_KEYWORD ;
3236
3337value :
3438stringValue |
@@ -86,6 +90,7 @@ UNION: 'union';
8690INPUT : ' input' ;
8791EXTEND : ' extend' ;
8892DIRECTIVE : ' directive' ;
93+ ON_KEYWORD : ' on' ;
8994NAME : [_A -Za-z][_0 -9A-Za-z]*;
9095
9196
Original file line number Diff line number Diff line change @@ -23,13 +23,11 @@ alias : name ':';
2323
2424
2525
26-
2726fragmentSpread : ' ...' fragmentName directives?;
2827
2928inlineFragment : ' ...' typeCondition? directives? selectionSet;
3029
31- fragmentDefinition : ' fragment ' fragmentName typeCondition directives? selectionSet;
30+ fragmentDefinition : FRAGMENT fragmentName typeCondition directives? selectionSet;
3231
33- fragmentName : name;
3432
35- typeCondition : ' on ' typeName;
33+ typeCondition : ON_KEYWORD typeName;
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ import graphql.language.OperationTypeDefinition
3030import graphql.language.ScalarTypeDefinition
3131import graphql.language.ScalarTypeExtensionDefinition
3232import graphql.language.SchemaDefinition
33+ import graphql.language.TypeDefinition
3334import graphql.language.TypeName
3435import graphql.language.UnionTypeDefinition
3536import graphql.language.UnionTypeExtensionDefinition
@@ -811,5 +812,26 @@ input Gun {
811812 assert asClass == definition. getClass(), " Could not find expected definition of type " + asClass. getName() + " but was " + definition. getClass(). getName()
812813 return asClass. cast(definition)
813814 }
815+
816+ def " able to allow special names for field names" () {
817+ given :
818+
819+ def input = """
820+ type Query {
821+ true: String
822+ fragment: String
823+ false: String
824+ on: String
825+ null: String
826+ }
827+ """
828+ when :
829+ Document document = Parser . parse(input)
830+ String name = (document. definitions[0 ] as TypeDefinition ). name
831+
832+ then :
833+ name == " Query"
834+ }
835+
814836}
815837
Original file line number Diff line number Diff line change @@ -718,4 +718,19 @@ triple3 : """edge cases \\""" "" " \\"" \\" edge cases"""
718718 ((FloatValue ) argumentValue). value. toString() == " 1.7976931348155E+308"
719719 }
720720
721+ def " parse fragment definition" () {
722+ given :
723+ def input = """
724+ fragment Foo on Bar {
725+ hello
726+ }
727+ """
728+ when :
729+ Document document = Parser . parse(input)
730+ FragmentDefinition fragmentDefinition = (document. definitions[0 ] as FragmentDefinition )
731+
732+ then :
733+ fragmentDefinition. name == " Foo"
734+
735+ }
721736}
You can’t perform that action at this time.
0 commit comments