Possible to check for requested output in resolver
See original GitHub issueIs it possible to check what is being requested in the resolver for a query? For example, if I have the following schema:
type Query {
getUser(username: ID){
email: String
phone: String
}
}
Can I create a resolver like this?
...
@query.field("getUser")
def get_user(obj, info, username):
requested_data = ... # This is what I'm looking for
response = {}
if "email" in requested_data:
response["email"] = get_email(username)
if "phone" in requested_data:
response["phone"] = get_phone(username)
return response
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Resolver Output and Voltage - Dynapar Encoders
Check the input voltage. If the resolver input voltage is not high enough, the output voltage will be low. Check the resolver for...
Read more >How to get requested fields inside GraphQL resolver?
First, I need to get the requested fields. I can already get the whole query as a string. For example, in the resolver,...
Read more >Resolvers - Apollo GraphQL Docs
Apollo Server needs to know how to populate data for every field in your schema so that it can respond to requests for...
Read more >TRACE RESOLVER - IBM
When the trace resolver output has been collected, check the following in the trace output: Fix or check any problems reported at the...
Read more >Test and debug resolvers (VTL) - AWS AppSync
When a GraphQL resolver is invoked, it contains a context object that has relevant information about the request for you to program against....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Closing this one. Feel free to ping me back @tbsf if you feel there’s something else to add.
Potentially we could have a guide on our docs showing how one can introspect which fields are asked in resolver to, say, eagerly fetch data needed in child resolver
Adding some information for other people that stumble here:
First of all, this is probably what you’re looking for:
“Why the loop around the inner (more obvious) loop” you might ask…
Taking this example
will output:
Which a) is kinda efficient - Ariadne doesn’t call the
getUserName
twice but rather once with all the required arguments and b) means only thefield_nodes
that actually map togetUserName
are in this list.