Skip to content

Commit

Permalink
feat: allow interfaces implementing interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
gabotechs authored and gabotechs committed Feb 6, 2023
1 parent f379d85 commit 9a95c3e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
10 changes: 10 additions & 0 deletions graphqxl_parser/src/ast_block_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,16 @@ mod tests {
)
}

#[test]
fn test_interface_implements_interface() {
assert_eq!(
parse_input("interface A implements B { foo: String }"),
Ok(BlockDef::interface_def("A")
.implements(Implements::from("B"))
.field(BlockField::build("foo").string()))
)
}

#[test]
fn test_incorrect_input_no_different_field_types() {
parse_input("enum MyEnum { Field1: String Field2 }").unwrap_err();
Expand Down
7 changes: 4 additions & 3 deletions graphqxl_parser/src/grammar.pest
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ schema_def = { description? ~ "schema" ~ directive* ~ schema_selection_set }
schema_field = { schema_key ~ ":" ~ identifier }
generic_type_def = { description_variables? ~ description? ~ "type " ~ identifier ~ directive* ~ "=" ~ modified_ref }
type_def = { description_variables? ~ description? ~ "type " ~ identifier ~ generic? ~ implements? ~ directive* ~ type_selection_set }
implements = { "implements" ~ identifier ~ ("&" ~ identifier)* }
type_selection_set = { "{" ~ (field_with_args | spread_reference)* ~ "}" }
generic_input_def = { description_variables? ~ description? ~ "input " ~ identifier ~ directive* ~ "=" ~ modified_ref }
input_def = { description_variables? ~ description? ~ "input " ~ identifier ~ generic? ~ directive* ~ input_selection_set }
input_selection_set = { "{" ~ (field_without_args | spread_reference)* ~ "}" }
enum_def = { description? ~ "enum " ~ identifier ~ directive* ~ enum_selection_set }
enum_selection_set = { "{" ~ (field_without_args_without_value | spread_reference)* ~ "}" }
interface_def = { description? ~ "interface " ~ identifier ~ directive* ~ interface_selection_set }
interface_selection_set = { "{" ~ field_with_args* ~ "}" }
interface_def = { description? ~ "interface " ~ identifier ~ implements? ~ directive* ~ interface_selection_set }
interface_selection_set = { "{" ~ (spread_reference | field_with_args)* ~ "}" }
scalar_def = { description? ~ "scalar " ~ identifier ~ directive* }
union_def = { description? ~ "union " ~ identifier ~ directive* ~ "=" ~ identifier ~ ("|" ~ identifier )* }

directive_def = { description? ~"directive" ~ "@" ~ identifier ~ arguments? ~ directive_repeatable? ~ "on" ~ directive_location ~ ("|" ~ directive_location)* }
directive_repeatable = @{ "repeatable" }
directive_location = @{
Expand All @@ -46,6 +46,7 @@ directive_def = { description? ~"directive" ~ "@" ~ identifier ~ arguments? ~ di
"VARIABLE_DEFINITION"
}

implements = { "implements" ~ identifier ~ ("&" ~ identifier)* }
field_with_args = { description? ~ identifier ~ arguments? ~ ":" ~ value_type ~ directive* }
field_without_args = { description? ~ identifier ~ ":" ~ value_type ~ directive* }
field_without_args_without_value = { description? ~ identifier ~ directive* }
Expand Down
9 changes: 7 additions & 2 deletions src/test/types-interfaces.graphqxl
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
interface Foo {
a: Int!
}

"description"
interface Interface {
interface Interface implements Foo {
...Foo
"foo description"
foo: String!
"bar description"
bar: Int!
}

type Type implements Interface {
type Type implements Interface & Foo {
...Interface
}

10 changes: 8 additions & 2 deletions src/test/types-interfaces.graphqxl.result
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
interface Foo {
a: Int!
}

"description"
interface Interface {
interface Interface implements Foo {
a: Int!
"foo description"
foo: String!
"bar description"
bar: Int!
}

type Type implements Interface {
type Type implements Interface & Foo {
a: Int!
"foo description"
foo: String!
"bar description"
Expand Down

0 comments on commit 9a95c3e

Please sign in to comment.