Skip to content

Commit 9a95c3e

Browse files
gabotechsgabotechs
authored andcommitted
feat: allow interfaces implementing interfaces
1 parent f379d85 commit 9a95c3e

File tree

4 files changed

+29
-7
lines changed

4 files changed

+29
-7
lines changed

graphqxl_parser/src/ast_block_def.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,16 @@ mod tests {
453453
)
454454
}
455455

456+
#[test]
457+
fn test_interface_implements_interface() {
458+
assert_eq!(
459+
parse_input("interface A implements B { foo: String }"),
460+
Ok(BlockDef::interface_def("A")
461+
.implements(Implements::from("B"))
462+
.field(BlockField::build("foo").string()))
463+
)
464+
}
465+
456466
#[test]
457467
fn test_incorrect_input_no_different_field_types() {
458468
parse_input("enum MyEnum { Field1: String Field2 }").unwrap_err();

graphqxl_parser/src/grammar.pest

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ schema_def = { description? ~ "schema" ~ directive* ~ schema_selection_set }
1111
schema_field = { schema_key ~ ":" ~ identifier }
1212
generic_type_def = { description_variables? ~ description? ~ "type " ~ identifier ~ directive* ~ "=" ~ modified_ref }
1313
type_def = { description_variables? ~ description? ~ "type " ~ identifier ~ generic? ~ implements? ~ directive* ~ type_selection_set }
14-
implements = { "implements" ~ identifier ~ ("&" ~ identifier)* }
1514
type_selection_set = { "{" ~ (field_with_args | spread_reference)* ~ "}" }
1615
generic_input_def = { description_variables? ~ description? ~ "input " ~ identifier ~ directive* ~ "=" ~ modified_ref }
1716
input_def = { description_variables? ~ description? ~ "input " ~ identifier ~ generic? ~ directive* ~ input_selection_set }
1817
input_selection_set = { "{" ~ (field_without_args | spread_reference)* ~ "}" }
1918
enum_def = { description? ~ "enum " ~ identifier ~ directive* ~ enum_selection_set }
2019
enum_selection_set = { "{" ~ (field_without_args_without_value | spread_reference)* ~ "}" }
21-
interface_def = { description? ~ "interface " ~ identifier ~ directive* ~ interface_selection_set }
22-
interface_selection_set = { "{" ~ field_with_args* ~ "}" }
20+
interface_def = { description? ~ "interface " ~ identifier ~ implements? ~ directive* ~ interface_selection_set }
21+
interface_selection_set = { "{" ~ (spread_reference | field_with_args)* ~ "}" }
2322
scalar_def = { description? ~ "scalar " ~ identifier ~ directive* }
2423
union_def = { description? ~ "union " ~ identifier ~ directive* ~ "=" ~ identifier ~ ("|" ~ identifier )* }
24+
2525
directive_def = { description? ~"directive" ~ "@" ~ identifier ~ arguments? ~ directive_repeatable? ~ "on" ~ directive_location ~ ("|" ~ directive_location)* }
2626
directive_repeatable = @{ "repeatable" }
2727
directive_location = @{
@@ -46,6 +46,7 @@ directive_def = { description? ~"directive" ~ "@" ~ identifier ~ arguments? ~ di
4646
"VARIABLE_DEFINITION"
4747
}
4848

49+
implements = { "implements" ~ identifier ~ ("&" ~ identifier)* }
4950
field_with_args = { description? ~ identifier ~ arguments? ~ ":" ~ value_type ~ directive* }
5051
field_without_args = { description? ~ identifier ~ ":" ~ value_type ~ directive* }
5152
field_without_args_without_value = { description? ~ identifier ~ directive* }

src/test/types-interfaces.graphqxl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1+
interface Foo {
2+
a: Int!
3+
}
4+
15
"description"
2-
interface Interface {
6+
interface Interface implements Foo {
7+
...Foo
38
"foo description"
49
foo: String!
510
"bar description"
611
bar: Int!
712
}
813

9-
type Type implements Interface {
14+
type Type implements Interface & Foo {
1015
...Interface
1116
}
1217

src/test/types-interfaces.graphqxl.result

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1+
interface Foo {
2+
a: Int!
3+
}
4+
15
"description"
2-
interface Interface {
6+
interface Interface implements Foo {
7+
a: Int!
38
"foo description"
49
foo: String!
510
"bar description"
611
bar: Int!
712
}
813

9-
type Type implements Interface {
14+
type Type implements Interface & Foo {
15+
a: Int!
1016
"foo description"
1117
foo: String!
1218
"bar description"

0 commit comments

Comments
 (0)