Search code examples
javascriptgraphqlapolloapollo-server

Get child args in parent in GraphQL


I have graphQL query as mentioned below

{ parent { child(childArgs: "myname") } } }

I want to access childArgs value in the parent, is there any way to access childArgs parent.


Solution

  • Yes, using the resolveInfo argument to your resolver function you can check whether the child field is queried on your parent object and what arguments it will have. Given you have to work with the query AST (and might have to resolve variables etc), I recommend using the grapqhl-parse-resolve-info package.