GraphQL\Type\Definition\ResolveInfo::getFieldSelection PHP Method

getFieldSelection() public method

query AppHomeRoute{viewer{id,..._0c28183ce}} fragment _0c28183ce on Viewer{id,profile{firstName,id,locations{id}}} Example: query MyQuery{ { root { id, nested { nested1 nested2 { nested3 } } } } Given this ResolveInfo instance is a part of "root" field resolution, and $depth === 1, method will return: [ 'id' => true, 'nested' => [ nested1 => true, nested2 => true ] ]
public getFieldSelection ( integer $depth ) : array
$depth integer How many levels to include in output
return array
    public function getFieldSelection($depth = 0)
    {
        $fields = [];
        /** @var FieldNode $fieldNode */
        foreach ($this->fieldNodes as $fieldNode) {
            $fields = array_merge_recursive($fields, $this->foldSelectionSet($fieldNode->selectionSet, $depth));
        }
        return $fields;
    }

Usage Example

 /**
  * Select only certain fields on queries instead of all fields.
  *
  * @param ResolveInfo $info
  * @return array
  */
 protected function getSelectFields(ResolveInfo $info)
 {
     $camel = config('relay.camel_case');
     $fields = array_get($info->getFieldSelection(2), 'edges.node');
     return collect($fields)->reject(function ($value) {
         is_array($value);
     })->keys()->transform(function ($value) use($camel) {
         return $camel ? snake_case($value) : $value;
     })->toArray();
 }
All Usage Examples Of GraphQL\Type\Definition\ResolveInfo::getFieldSelection