Skip to content

Commit

Permalink
Allow printing interfaces implementing interfaces
Browse files Browse the repository at this point in the history
Summary:
This seems like an oversight: we can define `interface Foo implements Bar` and the Relay SDLSchema can print this representation out, but the IR syntax cannot.

This diff quickly fixes that oversight.

Reviewed By: alunyov

Differential Revision: D49256355

fbshipit-source-id: 0de06ae10c36105bc81305f63846d08997e1441b
  • Loading branch information
mjmahone authored and facebook-github-bot committed Sep 14, 2023
1 parent 3353587 commit 38a08ed
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 10 deletions.
13 changes: 9 additions & 4 deletions compiler/crates/graphql-syntax/src/node/type_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,16 @@ impl fmt::Display for TypeSystemDefinition {
}) => write_object_helper(f, &name.value, interfaces, fields, directives, true),
TypeSystemDefinition::InterfaceTypeDefinition(InterfaceTypeDefinition {
name,
interfaces,
fields,
directives,
..
}) => write_interface_helper(f, &name.value, fields, directives, false),
}) => write_interface_helper(f, &name.value, interfaces, fields, directives, false),
TypeSystemDefinition::InterfaceTypeExtension(InterfaceTypeExtension {
name,
interfaces: _,
interfaces,
fields,
directives,
}) => write_interface_helper(f, &name.value, fields, directives, true),
}) => write_interface_helper(f, &name.value, interfaces, fields, directives, true),
TypeSystemDefinition::UnionTypeDefinition(UnionTypeDefinition {
name,
directives,
Expand Down Expand Up @@ -617,6 +617,7 @@ fn write_object_helper(
fn write_interface_helper(
f: &mut fmt::Formatter<'_>,
name: &StringKey,
interfaces: &[Identifier],
fields: &Option<List<FieldDefinition>>,
directives: &[ConstantDirective],
is_extension: bool,
Expand All @@ -626,6 +627,10 @@ fn write_interface_helper(
}

write!(f, "interface {}", name)?;
if !interfaces.is_empty() {
write!(f, " implements ")?;
write_list(f, interfaces, " & ")?;
}
write_directives(f, directives)?;
if let Some(fields) = fields.as_ref() {
write_fields(f, &fields.items)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,19 @@ type Mutation {
success: boolean
}

interface XIGHuman @source(schema: "instagram", name: "Human") {
interface HasName {
name: String
}

extend interface XIGHuman {
interface HasNickname {
nickname: String
}

interface XIGHuman implements Animal @source(schema: "instagram", name: "Human") {
name: String
}

extend interface XIGHuman implements HasNickname {
nickname: String
}

Expand Down Expand Up @@ -104,11 +112,19 @@ type Mutation {
success: boolean
}

interface XIGHuman @source(schema: "instagram", name: "Human") {
interface HasName {
name: String
}

interface HasNickname {
nickname: String
}

interface XIGHuman implements Animal @source(schema: "instagram", name: "Human") {
name: String
}

extend interface XIGHuman {
extend interface XIGHuman implements HasNickname {
nickname: String
}

Expand Down
12 changes: 10 additions & 2 deletions compiler/crates/graphql-syntax/tests/print/fixtures/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,19 @@ type Mutation {
success: boolean
}

interface XIGHuman @source(schema: "instagram", name: "Human") {
interface HasName {
name: String
}

extend interface XIGHuman {
interface HasNickname {
nickname: String
}

interface XIGHuman implements Animal @source(schema: "instagram", name: "Human") {
name: String
}

extend interface XIGHuman implements HasNickname {
nickname: String
}

Expand Down

0 comments on commit 38a08ed

Please sign in to comment.