question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Child resolver args is empty

See original GitHub issue

version: apollo-server 2.0.4

Problem Given the following resolver:

module.exports = {
  Query: {
    myQuery = (parent, args, context) => {
      // args.queryParam is defined
      returns arrayOfItems
    }
  },

  Item: {
    myResolver: async (parent, args, context) => {
      const { queryParam } = args;
      // queryParam is undefined here
      if (queryParam) {
        return { ... omitted }
      }
      return null;
    },
  },
};

query {
  myQuery(queryParam: "mystuff") {
    ...
  }
}

I have checked when myResolver is called and the second params args is always empty. Even when passing the the param when running the query.

I have checked the args of myQuery and it successfully passes the arg there, but it does not show up on myResolver. I was under the intention that myResolver should have this arg as well. I even remember it working before, but it has stopped working for me.

As a workaround I am using myQuery to set the arg in the context and then I can get it from myResolver.context.

Expected myResolver to have the arg queryParam when calling the query with it.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
rv-alakecommented, May 30, 2019

I’m also seeing this on apollo-server-express 2.4.8. The args param is always empty on child resolvers, from what I have seen it is because Item in your case is a type and therefore doesn’t have args. I’m not sure if that is the reason or not but it seems like it would be nice if args were passed down.

0reactions
chnoackcommented, Aug 19, 2020

By intention the query is never passed from the parent resolver to the child resolver, because child resolvers could have their own query. In this case we have a Product resolver with its query (“articleNumber”). It has a child resolver called currentPricing with its own query. In the resolver code for the currentPricing resolver you will only get the “currency” query.

fragment ProductFragment on Product {

  currentPricing(currency: $currency) {
    price {
      value
    }
    cause
  }
}

query getSingleProduct(
  $articleNumber: String
  $currency: Boolean
) {
  product(articleNumber: $articleNumber) {
    ...ProductFragment
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Graphql-Access arguments in child resolvers - Stack Overflow
My question is that how can I access args which is available in root resolver( getTotalVehicals ) in any of the child resolvers?...
Read more >
Resolvers - Apollo GraphQL Docs
A resolver can optionally accept four positional arguments: (parent, args, contextValue, info) . Learn more about these arguments. The args argument is an ......
Read more >
Use the GraphQL Parent Object in a Child Resolver | egghead.io
Data resolved out of a parent resolver can be accessed by a child resolver. ... If we do that, we'll just get null...
Read more >
How to get the args of the parent resolver in the Apollo Server?
There might be different resolvers that return the parent and not all of them might have the given parameter. Using information from these ......
Read more >
Resolvers | Strawberry GraphQL
In Strawberry there are two ways of defining resolvers; the first is to pass a ... between null (maps to None in Python)...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found