I discovered some behavior that I can’t find any explicit documentation for, and I want to make sure I’m safe to use it.
This is a simplified example of what I’m doing:
Query: {
person: async (parent, args, context) => {
const { id } = args;
const p = await getPerson(id);
return {
id,
bestFriend: () => {
return getPerson(p.bestFriendId);
}
}
}
}
The bestFriend
property returns a function that resolves an entire Person
type (or many properties of the Person type). From my testing, the function is only called if bestFriend
is requested in the query.
Why do I care? There are cases where one resolver has the id for a related object in scope. If I were to do normal type resolvers, I would have to make one resolver for each field on the Person
type, even if many of the properties can be gathered from a single request/database query.
Is this officially supported functionality?
Thank you!
Using: @apollo/server 4.10.0