Get list of requested fields inside resolver #14
Labels
No Milestone
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: OSS/graphql#14
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Hi!
I'm not super familiar with the GraphQL terminology, so this question might sound a bit nonsensical. When a GQL query is received, the request might only ask for a subset of the available fields. Is there any way for a
Resolve
monad to ask for the list of available fields?Get requested values inside resolverto Get list of requested fields inside resolverNo, currently the resolver context contains only the field arguments and the value returned by the parent resolver. The fields requested can be seen only in the parsed query.
I find such a feature useful, I just don't use it in my application, so I haven't looked into implementing it. In my resolvers I always rely on the fact that if the field was requested, its resolver will be called, and I load the data in that resolver if needed. Not sure if it is useful for your use case, but I'll try to give an example.
Now if the user queries the projects, my root resolver returns the following:
So only the "id" of the
Worker
object is returned. Now themanager
resolver is only called if the user requests it. So in this resolver I have access to the ID from the parent resolver and can query the remaining fields of themanager
. The query will be executed only if the user requests some of themanager
fields.Sorry for the long explanation if it's not useful for you use case.
@belka My usecase is that sometimes certain fields return errors (in my case, int overflow errors), but the query should still go through when those fields are not asked for.