I'm using Apollo GraphQL on my server, and I'm trying to design my GraphQL API. One question I'm having is whether I should prefer nested queries over root queries or not.
Let's examine both in this example where the current user, me
, has many invitations
.
Root queries
me {
id
name
}
invitations {
id
message
}
The resolver for invitations
returns invitations for the current user.
Nested query
me {
id
name
invitations {
id
message
}
}
These should achieve the same result, except invitations being nested in the user object me
using the latter approach. My concern is though if this works smoothly with Apollo Client in keeping the cache consistent.
What is the recommended way to design GraphQL queries?