graphitation
graphitation copied to clipboard
[supermassive] Deal with conditional resolving AOT
If we do AOT compilation of some sort, we can do some of the work that resolvers sometimes do at runtime where they reflect on the request AST to determine what fields are selected and if all data is already available or needs to be fetched from a [remote] I/O bound source.
A contrived example is when only an id
field of an object is selected, in which case we wouldn't need to fetch the full user object:
type User {
id: ID!
name: String!
}
type Query {
user(id: ID!): User
}
query {
user(id: 42) {
id
}
}
function userResolver(_source, args, context, info) {
if (onlyNeedsIdField(info)) {
return { id: args.id }
} else {
return getUser(args.id)
}
}
Also see this post by @andrewingram https://andrewingram.net/posts/optimising-your-graphql-request-waterfalls/