I have two subgraphs: Sub1, Sub2, and Gateway.
Sub1 implements:
type Category {
id: ID!
name: String!
# and many other fields
}
I want to add Sub2 that provides a part of Category
:
extend type Category @key(fields: "id") {
id: ID! @external
name: String! @external
}
interface I {
category: Category! @provides(fields: "name")
}
type B implements I {
category: Category! @provides(fields: "name")
}
# there are many other types that implement I
union Sub2Data = A | B | C;
type Sub2Response {
count: Int!
data: [Sub2Data!]!
}
type Query {
sub2Query: Sub2Response!
}
I want to query:
query Sub2Query {
sub2Query {
count
data {
... on I {
category {
name
}
}
}
}
When I send the query to Gateway, the Gateway sends the _entities
query to Sub1:
query GW_Test($representations: [_Any!]!) {
_entities(representations: $representations) {
... on Category {
name
}
}
}
And, Sub1 errors out with
Error: Cannot return null for non-nullable field Category.name.
When I send the same query (sub2Query
) to Sub2 directly, it’s successful.
How can I make Category.name
to come from Sub2 when I’m querying sub2Query
?
Thanks.
Sam
Edit:
When I put category
field out of the interface to concrete types, it works:
What works:
interface I {}
type B implements I {
category: Category! @provides(fields: "name")
}
And change the query to:
query Sub2Query {
sub2Query {
count
data {
... on A {
category {
name
}
}
... on B {
category {
name
}
}
... on C {
category {
name
}
}
}
}
This makes query cumbersome. Is there way to make @provides
work on interface?