Skip to content

Commit

Permalink
Allow extending interface interfaces
Browse files Browse the repository at this point in the history
Summary:
We allow extending an object with new implemented interfaces.

We need to do the same for interfaces, because they can implement new interfaces too.

Reviewed By: ginfung

Differential Revision: D48403027

fbshipit-source-id: 8f4fc322bc3d2bb5d74595f52af8b5df76cbeb70
  • Loading branch information
mjmahone authored and facebook-github-bot committed Aug 16, 2023
1 parent 520b205 commit bacd1ae
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 6 deletions.
11 changes: 10 additions & 1 deletion compiler/crates/schema/src/in_memory/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1420,9 +1420,9 @@ impl InMemorySchema {
},
TypeSystemDefinition::InterfaceTypeExtension(InterfaceTypeExtension {
name,
interfaces,
fields,
directives,
..
}) => match self.type_map.get(&name.value).cloned() {
Some(Type::Interface(id)) => {
let index = id.as_usize();
Expand All @@ -1447,6 +1447,15 @@ impl InMemorySchema {
)?;
self.interfaces[index].fields.extend(client_fields);

let built_interfaces = interfaces
.iter()
.map(|name| self.build_interface_id(name, location_key))
.collect::<DiagnosticsResult<Vec<_>>>()?;
extend_without_duplicates(
&mut self.interfaces[index].interfaces,
built_interfaces,
);

let built_directives = self.build_directive_values(directives);
extend_without_duplicates(
&mut self.interfaces[index].directives,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ extend type User {
nickname: String
client: ClientType
}

interface HasName {
name: String
}

extend interface Node implements HasName {
name: String
}
extend type User implements HasName
==================================== OUTPUT ===================================
Text Schema:Schema {
query_type: Some(
Expand Down Expand Up @@ -174,6 +183,7 @@ Text Schema:Schema {
"Boolean": Scalar(3),
"ClientType": Object(3),
"Float": Scalar(6),
"HasName": Interface(1),
"ID": Scalar(4),
"Int": Scalar(7),
"Location": InputObject(0),
Expand Down Expand Up @@ -448,6 +458,40 @@ Text Schema:Schema {
description: None,
hack_source: None,
},
Field {
name: WithLocation {
location: kitchen-sink.graphql:835:839,
item: "name",
},
is_extension: true,
arguments: [],
type_: Named(
Scalar(8),
),
directives: [],
parent_type: Some(
Interface(1),
),
description: None,
hack_source: None,
},
Field {
name: WithLocation {
location: kitchen-sink.graphql:896:900,
item: "name",
},
is_extension: true,
arguments: [],
type_: Named(
Scalar(8),
),
directives: [],
parent_type: Some(
Interface(0),
),
description: None,
hack_source: None,
},
Field {
name: WithLocation {
location: <generated>:0:0,
Expand Down Expand Up @@ -679,6 +723,27 @@ Text Schema:Schema {
],
fields: [
FieldID(2),
FieldID(11),
],
directives: [],
interfaces: [
InterfaceID(1),
],
description: None,
hack_source: None,
},
Interface {
name: WithLocation {
location: kitchen-sink.graphql:823:830,
item: InterfaceName(
"HasName",
),
},
is_extension: true,
implementing_interfaces: [],
implementing_objects: [],
fields: [
FieldID(10),
],
directives: [],
interfaces: [],
Expand Down Expand Up @@ -720,6 +785,7 @@ Text Schema:Schema {
],
interfaces: [
InterfaceID(0),
InterfaceID(1),
],
directives: [],
description: None,
Expand Down Expand Up @@ -1099,6 +1165,23 @@ fields: [
description: None,
hack_source: None,
},
Field {
name: WithLocation {
location: <generated>:0:0,
item: "name",
},
is_extension: true,
arguments: [],
type_: Named(
Scalar(1),
),
directives: [],
parent_type: Some(
Interface(1),
),
description: None,
hack_source: None,
},
Field {
name: WithLocation {
location: <generated>:0:0,
Expand All @@ -1118,6 +1201,23 @@ fields: [
description: None,
hack_source: None,
},
Field {
name: WithLocation {
location: <generated>:0:0,
item: "name",
},
is_extension: true,
arguments: [],
type_: Named(
Scalar(1),
),
directives: [],
parent_type: Some(
Interface(0),
),
description: None,
hack_source: None,
},
Field {
name: WithLocation {
location: <generated>:0:0,
Expand Down Expand Up @@ -1410,6 +1510,24 @@ input_objects: [
},
]
interfaces: [
Interface {
name: WithLocation {
location: <generated>:0:0,
item: InterfaceName(
"HasName",
),
},
is_extension: true,
implementing_interfaces: [],
implementing_objects: [],
fields: [
FieldID(7),
],
directives: [],
interfaces: [],
description: None,
hack_source: None,
},
Interface {
name: WithLocation {
location: <generated>:0:0,
Expand All @@ -1424,9 +1542,12 @@ interfaces: [
],
fields: [
FieldID(5),
FieldID(6),
],
directives: [],
interfaces: [],
interfaces: [
InterfaceID(1),
],
description: None,
hack_source: None,
},
Expand Down Expand Up @@ -1457,8 +1578,8 @@ objects: [
},
is_extension: false,
fields: [
FieldID(6),
FieldID(7),
FieldID(8),
FieldID(9),
],
interfaces: [],
directives: [],
Expand All @@ -1474,8 +1595,8 @@ objects: [
},
is_extension: false,
fields: [
FieldID(8),
FieldID(9),
FieldID(10),
FieldID(11),
],
interfaces: [],
directives: [],
Expand All @@ -1498,6 +1619,7 @@ objects: [
],
interfaces: [
InterfaceID(0),
InterfaceID(1),
],
directives: [],
description: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,12 @@ extend type User {
nickname: String
client: ClientType
}

interface HasName {
name: String
}

extend interface Node implements HasName {
name: String
}
extend type User implements HasName

0 comments on commit bacd1ae

Please sign in to comment.