Skip to content

Commit

Permalink
graphql#82 add support for interface extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
realdoug committed Sep 29, 2019
1 parent 9ca3937 commit 785254a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
4 changes: 4 additions & 0 deletions ast/ast.ast
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ O SchemaDefinition
O ScalarTypeDefinition
O ObjectTypeDefinition
O InterfaceTypeDefinition
O InterfaceExtensionDefinition
O UnionTypeDefinition
O EnumTypeDefinition
O InputObjectTypeDefinition
Expand Down Expand Up @@ -175,6 +176,9 @@ S Name name
P? Directive directives
P FieldDefinition fields

T InterfaceExtensionDefinition
S InterfaceTypeDefinition definition

T UnionTypeDefinition
S Name name
P? Directive directives
Expand Down
7 changes: 7 additions & 0 deletions parser.ypp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ using facebook::graphql::ast::SchemaDefinition;
using facebook::graphql::ast::ScalarTypeDefinition;
using facebook::graphql::ast::ObjectTypeDefinition;
using facebook::graphql::ast::InterfaceTypeDefinition;
using facebook::graphql::ast::InterfaceExtensionDefinition;
using facebook::graphql::ast::UnionTypeDefinition;
using facebook::graphql::ast::EnumTypeDefinition;
using facebook::graphql::ast::InputObjectTypeDefinition;
Expand Down Expand Up @@ -125,6 +126,7 @@ union yystype { \
ScalarTypeDefinition *scalarTypeDefinition; \
ObjectTypeDefinition *objectTypeDefinition; \
InterfaceTypeDefinition *interfaceTypeDefinition; \
InterfaceExtensionDefinition *interfaceExtensionDefinition; \
UnionTypeDefinition *unionTypeDefinition; \
EnumTypeDefinition *enumTypeDefinition; \
InputObjectTypeDefinition *inputObjectTypeDefinition; \
Expand Down Expand Up @@ -266,6 +268,7 @@ union yystype { \
%type <scalarTypeDefinition> scalar_type_definition;
%type <objectTypeDefinition> object_type_definition;
%type <interfaceTypeDefinition> interface_type_definition;
%type <interfaceExtensionDefinition> interface_extension_definition;
%type <unionTypeDefinition> union_type_definition;
%type <enumTypeDefinition> enum_type_definition;
%type <inputObjectTypeDefinition> input_object_type_definition;
Expand Down Expand Up @@ -360,6 +363,7 @@ schema_gate: schema_definition { $$ = static_cast<Definition *>($1); }
| enum_type_definition { $$ = static_cast<Definition *>($1); }
| input_object_type_definition { $$ = static_cast<Definition *>($1); }
| type_extension_definition { $$ = static_cast<Definition *>($1); }
| interface_extension_definition { $$ = static_cast<Definition *>($1); }
| directive_definition { $$ = static_cast<Definition *>($1); }
;

Expand Down Expand Up @@ -644,6 +648,9 @@ input_value_definition: name ":" type default_value_opt directives_opt { $$ = ne
interface_type_definition: INTERFACE name directives_opt "{" field_definition_list "}" { $$ = new InterfaceTypeDefinition(@$, $2, $3, $5); }
;

interface_extension_definition: EXTEND interface_type_definition { $$ = new InterfaceExtensionDefinition(@$, $2); }
;

union_type_definition: UNION name directives_opt "=" union_members { $$ = new UnionTypeDefinition(@$, $2, $3, $5); }
;

Expand Down
2 changes: 2 additions & 0 deletions test/ParserTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,8 @@ TEST(SchemaParserTests, SimpleSchema) {
"otherField: otherType }");
expectSchemaParsing("extend type SomeType " DIRECTIVES
"{ anotherField : AnotherType }");
expectSchemaParsing("extend interface SomeInterface " DIRECTIVES
"{ anotherField : AnotherType }");
expectSchemaParsing("directive @somedirective(a1 : t1 = 1 " DIRECTIVES
", a2 : t2) on foo | bar");
}
11 changes: 6 additions & 5 deletions test/schema-kitchen-sink.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type Foo implements Bar {
three(argument: InputType, other: String): Int
four(argument: String = "string"): String
five(argument: [String] = ["string", "string"]): String
six(argument: InputType = {key: "value"}): Type
six(argument: InputType = { key: "value" }): Type
seven(argument: Int = null): Type
}

Expand Down Expand Up @@ -64,6 +64,10 @@ extend type Foo {
seven(argument: [String]): Type
}

extend interface Bar {
name: String
}

# NOTE: out-of-spec test cases commented out until the spec is clarified; see
# https://github.com/graphql/graphql-js/issues/650 .
# extend type Foo @onType {}
Expand All @@ -72,7 +76,4 @@ extend type Foo {

directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT

directive @include(if: Boolean!)
on FIELD
| FRAGMENT_SPREAD
| INLINE_FRAGMENT
directive @include(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
2 changes: 1 addition & 1 deletion test/schema-kitchen-sink.json

Large diffs are not rendered by default.

0 comments on commit 785254a

Please sign in to comment.