Skip to content

Introduce query plan as a replacement for ResolveInfo::getFieldSelection #65

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
vladar opened this issue Nov 4, 2016 · 3 comments
Closed

Comments

@vladar
Copy link
Member

vladar commented Nov 4, 2016

Currently we have ResolveInfo::getFieldSelection() to do simple look-aheads. But it is too limited for real-world scenarios and provides little help when resolving field of union or interface type. Better tool has to address more use-cases. Basically it should provide convenient interface to answer following questions:

  1. What sub-fields were requested (regardless of fragment types)?
  2. What types were referenced by fragments?
  3. What sub-fields were requested for given type?
  4. What args/directives were set for given field?

Current getFieldSelection only answers question 1.

The syntax for this could be something like this:

function resolve($value, $args, $context, ResolveInfo $info) {
    $queryPlan = $info->lookAhead();

    // Answers #1:
    $fields = $queryPlan->subFields();
    $deepFieldRequested = $queryPlan->has(['nested', 'deeper', 'evenDeeper']);

    // Answers #2:
    $types = $queryPlan->referencedTypes();

    // Answers #3:
    $typeSpecificFields = $queryPlan->subFields('TypeReferencedByFragment');
}

This needs further design with regards to nested syntax + things may get quite complicated for type-dependent deep fields.

@decebal
Copy link
Contributor

decebal commented Mar 16, 2017

@vladar I had to write a wrapper around ResolveInfo In my use case that answers #4 in a similar way foldSelectionSet does.

I can submit a pull-request with the wrapper in case you find it useful or maybe inspiring. Our use case is slightly different as we are not solving the fields one by one, rather using a top-down approach resolving the whole request at once and leaving it to this library to process the resulting array.

@vladar
Copy link
Member Author

vladar commented Jul 10, 2017

@decebal Oh, sorry I missed your comment somehow.

I'd appreciate your PR. Can't guarantee that I'll merge it (since we still need complete solution that answers all questions), but it will be useful anyway (as insight, or as direct solution for item 4 from this list).

@decebal
Copy link
Contributor

decebal commented Jul 10, 2017

@vladar sure thing, I'll do the pull request asap (this week), while I really need to start working on this for my project as it currently has some ugly hacks in order to cover for missing type definitions in resolveInfo

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

No branches or pull requests

2 participants