Closed
Description
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:
- What sub-fields were requested (regardless of fragment types)?
- What types were referenced by fragments?
- What sub-fields were requested for given type?
- 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.