Skip to content
This repository has been archived by the owner on Feb 10, 2019. It is now read-only.

What does the parameters of resolve($root, $args, SelectFields $fields, ResolveInfo $info) method mean? #381

Open
zwl1619 opened this issue Sep 11, 2018 · 1 comment

Comments

@zwl1619
Copy link

zwl1619 commented Sep 11, 2018

What does the parameters of resolve($root, $args, SelectFields $fields, ResolveInfo $info) method mean?

    public function resolve($root, $args, SelectFields $fields, ResolveInfo $info)
    {
        return [];
    }

as follow:
1、$root
2、$args
3、SelectFields $fields
4、ResolveInfo $info

@mfn
Copy link

mfn commented Sep 11, 2018

Resolving is a GraphQL context to retrieve data; see also the docs for the underlying library: http://webonyx.github.io/graphql-php/data-fetching/

You're question is a bit light on the surrounding context, but I'll give it a shot:

  • $root refers to the "parent" type; it's empty if there's none. For example you query { user { orders { … you can access user from your orders resolve()
  • $args are the arguments passed to the node, e.g. user(arg1: value1)
  • $fields is ... I don't know where you got this from exactly, it's supposed to be the $context. The default Folklore context is the authenticated user but you can override it to be anything
  • $info is directly from http://webonyx.github.io/ to access the current node (AST?) tree to extract (look ahead) further information

I rarely do need $root, $args is a no-brainer, $context is very important (authentication) and for complex optimizations I need to access $info (via \GraphQL\Type\Definition\ResolveInfo::getFieldSelection)

If you're new to the whole GraphQL world I recommend getting acquainted with the architecture in general => http://facebook.github.io/graphql/

HTH

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants