How to "Join" to subgraphs? #5640
-
I have two existing services: People: extend type Person @key(fields: "id") {
id: ID!
name: String!
} Shows: type Show @key(fields: "id") {
id: ID!
name: String!
} I want to add a third, that extends each of these: ShowHosts. extend type Person @key(fields: "id") {
id: ID! @external
shows: [Show]
}
extend type Show @key(fields: "id") {
id: ID! @external
people: [Person]
} I can't work out what my resolver for this would look like. Could someone please help me out? |
Beta Was this translation helpful? Give feedback.
Answered by
kamilkisiela
Oct 5, 2024
Replies: 1 comment 1 reply
-
What GraphQL server are you using for the subgraph? I will assume it's JS-based like https://the-guild.dev/graphql/yoga-server . In the {
Person: {
__resolveReference(key: { id: string }) {
const shows = getShowsOfPerson(key.id);
if (shows == null) { return null }
return { id: key.id, shows };
// if you prefer, you can also return `{ id }` and add `shows` function to the object (Person.shows()).
}
}
} |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
rawkode
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What GraphQL server are you using for the subgraph?
I will assume it's JS-based like https://the-guild.dev/graphql/yoga-server .
In the
resolvers
object: