Hello,
I’m trying to use the @requires
directive to extend a type between two subgraphs and running into some trouble.
I have two subgraphs, user and group. The user subgraph knows about users, their details and their demographic information, but does not know what groups they belong to. The group subgraphs knows about groups and which users belong to those groups but does not have any further information about those users.
The feature request is to allow to query for the range of all ages of the users in the group. This should be doable.
user subgraph
type User @key(fields: "id") {
id: ID!
...
}
type Group @key(fields: "id") {
id: ID!
members: [User!]! @external
ageRange: String! @requires(fields: "members { id }")
}
group subgraph
type Group @key(fields: "id") {
id: ID!
members: [User!]!
}
So for any Group that we query, we ask for the member ids so that we can pull their birth date and calculate the age range.
However, when we try to do this we get an error:
The schema is not a valid GraphQL schema
Caused by:
[<unnamed>] On field "ageRange", for @requires(fields: "members { id }"): field "Member.id" should not be part of a @requires since it is already "effectively" provided by this subgraph (while it is marked @external, it is a @key field of an extension type)
As I stated earlier, the user subgraph has no idea what users belong to what groups and no way to get that information. It cannot provide this field. Hence it is marked @external
. It relies on the subgraph that defined the members field in the first place, where it is not @external
, the group subgraph.
I can get around this by resolving out the memberIds on the Group
object as just an array field and then requiring that, but I’d really rather not do that. Is there a way to make this work as the docs imply this is possible?