From 67251faed7d031efe94c44e9c7529c3b30bb562d Mon Sep 17 00:00:00 2001 From: Danuel Date: Sun, 5 Jul 2020 01:35:25 +0900 Subject: [PATCH] Add a specification to implement the interface to the interface. --- async-graphql-parser/src/schema.pest | 2 +- async-graphql-parser/src/schema.rs | 1 + async-graphql-parser/src/schema_parser.rs | 5 +++++ async-graphql-parser/tests/schemas/implements.graphql | 4 ++++ async-graphql-parser/tests/schemas/implements_amp.graphql | 3 +++ .../tests/schemas/implements_amp_canonical.graphql | 4 ++++ 6 files changed, 18 insertions(+), 1 deletion(-) diff --git a/async-graphql-parser/src/schema.pest b/async-graphql-parser/src/schema.pest index 16b2d0f7..dee6be5c 100644 --- a/async-graphql-parser/src/schema.pest +++ b/async-graphql-parser/src/schema.pest @@ -46,7 +46,7 @@ arguments_definition = { "(" ~ input_value_definition* ~ ")" } field_definition = { string? ~ name ~ arguments_definition? ~ ":" ~ type_ ~ directives? } fields_definition = { "{" ~ field_definition* ~ "}" } object_type_definition = { string? ~ extend? ~ "type" ~ name ~ implements_interfaces? ~ directives? ~ fields_definition? } -interface_type_definition = { string? ~ extend? ~ "interface" ~ name ~ directives? ~ fields_definition? } +interface_type_definition = { string? ~ extend? ~ "interface" ~ name ~ implements_interfaces? ~ directives? ~ fields_definition? } union_member_types = { "=" ~ "|"? ~ name ~ ("|" ~ name)* } union_type_definition = { string? ~ extend? ~ "union" ~ name ~ directives? ~ union_member_types? } enum_value_definition = { string? ~ name ~ directives? } diff --git a/async-graphql-parser/src/schema.rs b/async-graphql-parser/src/schema.rs index c595d195..f867ba63 100644 --- a/async-graphql-parser/src/schema.rs +++ b/async-graphql-parser/src/schema.rs @@ -93,6 +93,7 @@ pub struct InterfaceType { pub extend: bool, pub description: Option>, pub name: Positioned, + pub implements_interfaces: Vec>, pub directives: Vec>, pub fields: Vec>, } diff --git a/async-graphql-parser/src/schema_parser.rs b/async-graphql-parser/src/schema_parser.rs index a7d47cac..948d8226 100644 --- a/async-graphql-parser/src/schema_parser.rs +++ b/async-graphql-parser/src/schema_parser.rs @@ -475,6 +475,7 @@ fn parse_interface_type( let mut description = None; let mut extend = false; let mut name = None; + let mut implements_interfaces = None; let mut directives = None; let mut fields = None; @@ -485,6 +486,9 @@ fn parse_interface_type( } Rule::extend => extend = true, Rule::name => name = Some(Positioned::new(pair.as_str().to_string(), pc.step(&pair))), + Rule::implements_interfaces => { + implements_interfaces = Some(parse_implements_interfaces(pair, pc)?) + } Rule::directives => directives = Some(parse_directives(pair, pc)?), Rule::fields_definition => fields = Some(parse_fields_definition(pair, pc)?), _ => unreachable!(), @@ -496,6 +500,7 @@ fn parse_interface_type( extend, description, name: name.unwrap(), + implements_interfaces: implements_interfaces.unwrap_or_default(), directives: directives.unwrap_or_default(), fields: fields.unwrap_or_default(), }, diff --git a/async-graphql-parser/tests/schemas/implements.graphql b/async-graphql-parser/tests/schemas/implements.graphql index a84b001a..473bc7aa 100644 --- a/async-graphql-parser/tests/schemas/implements.graphql +++ b/async-graphql-parser/tests/schemas/implements.graphql @@ -1,3 +1,7 @@ type Type1 implements IOne type Type1 implements IOne & ITwo + +interface Type1 implements IOne + +interface Type1 implements IOne & ITwo diff --git a/async-graphql-parser/tests/schemas/implements_amp.graphql b/async-graphql-parser/tests/schemas/implements_amp.graphql index e4ff2d38..afff22d7 100644 --- a/async-graphql-parser/tests/schemas/implements_amp.graphql +++ b/async-graphql-parser/tests/schemas/implements_amp.graphql @@ -1,2 +1,5 @@ type Type1 implements & IOne & ITwo type Type2 implements & IOne + +interface Type1 implements & IOne & ITwo +interface Type2 implements & IOne diff --git a/async-graphql-parser/tests/schemas/implements_amp_canonical.graphql b/async-graphql-parser/tests/schemas/implements_amp_canonical.graphql index f066126b..6b287d41 100644 --- a/async-graphql-parser/tests/schemas/implements_amp_canonical.graphql +++ b/async-graphql-parser/tests/schemas/implements_amp_canonical.graphql @@ -1,3 +1,7 @@ type Type1 implements IOne & ITwo type Type2 implements IOne + +interface Type1 implements IOne & ITwo + +interface Type2 implements IOne