This commit is contained in:
Sunli 2020-11-10 11:46:56 +08:00
parent ec4aba62ec
commit 80d6ec05dd
4 changed files with 23 additions and 3 deletions

View File

@ -47,8 +47,8 @@ object_type = {
implements_interfaces = { "implements" ~ "&"? ~ name ~ ("&" ~ name)* }
interface_type = {
string? ~ "interface" ~ name ~ const_directives? ~ fields_definition?
| extend ~ "interface" ~ name ~ (const_directives? ~ fields_definition | const_directives)
string? ~ "interface" ~ name ~ implements_interfaces? ~ const_directives? ~ fields_definition?
| extend ~ "interface" ~ name ~ implements_interfaces? ~ (const_directives? ~ fields_definition | const_directives)
}
fields_definition = { "{" ~ field_definition+ ~ "}" }

View File

@ -149,12 +149,26 @@ fn parse_type_definition(
)
}
Rule::interface_type => {
let implements = parse_if_rule(&mut pairs, Rule::implements_interfaces, |pair| {
debug_assert_eq!(pair.as_rule(), Rule::implements_interfaces);
pair.into_inner()
.map(|pair| parse_name(pair, pc))
.collect::<Result<_>>()
})?;
let directives = parse_opt_const_directives(&mut pairs, pc)?;
let fields = parse_if_rule(&mut pairs, Rule::fields_definition, |pair| {
parse_fields_definition(pair, pc)
})?
.unwrap_or_default();
(directives, TypeKind::Interface(InterfaceType { fields }))
(
directives,
TypeKind::Interface(InterfaceType {
implements: implements.unwrap_or_default(),
fields,
}),
)
}
Rule::union_type => {
let directives = parse_opt_const_directives(&mut pairs, pc)?;

View File

@ -112,6 +112,8 @@ pub struct FieldDefinition {
/// [Reference](https://spec.graphql.org/June2018/#InterfaceType).
#[derive(Debug, Clone)]
pub struct InterfaceType {
/// The interfaces implemented by the interface.
pub implements: Vec<Positioned<Name>>,
/// The fields of the interface type.
pub fields: Vec<Positioned<FieldDefinition>>,
}

View File

@ -1,3 +1,7 @@
type Type1 implements IOne
type Type1 implements IOne & ITwo
interface Type1 implements IOne
interface Type1 implements IOne & ITwo