PHP Class Youshido\GraphQL\Execution\Reducer

Show file Open project: youshido/graphql Class Usage Examples

Public Methods

Method Description
reduceQuery ( Youshido\GraphQL\Execution\Context\ExecutionContextInterface $executionContext, array $reducers ) Apply all of $reducers to this query. Example reducer operations: checking for maximum query complexity, performing look-ahead query planning, etc.

Protected Methods

Method Description
doVisit ( Query $query, AbstractType $currentLevelSchema, AbstractQueryVisitor $reducer ) Entry point for the walkQuery routine. Execution bounces between here, where the reducer's ->visit() method is invoked, and walkQuery where we send in the scores from the visit call.
walkQuery ( Query | Field | Youshido\GraphQL\Parser\Ast\Interfaces\FragmentInterface $queryNode, Youshido\GraphQL\Field\FieldInterface $currentLevelAST ) : Generator Coroutine to walk the query and schema in DFS manner (see AbstractQueryVisitor docs for more info) and yield a tuple of (queryNode, schemaNode, childScore)

Method Details

doVisit() protected method

Entry point for the walkQuery routine. Execution bounces between here, where the reducer's ->visit() method is invoked, and walkQuery where we send in the scores from the visit call.
protected doVisit ( Query $query, AbstractType $currentLevelSchema, AbstractQueryVisitor $reducer )
$query Youshido\GraphQL\Parser\Ast\Query
$currentLevelSchema Youshido\GraphQL\Type\AbstractType
$reducer Youshido\GraphQL\Execution\Visitor\AbstractQueryVisitor

reduceQuery() public method

Apply all of $reducers to this query. Example reducer operations: checking for maximum query complexity, performing look-ahead query planning, etc.
public reduceQuery ( Youshido\GraphQL\Execution\Context\ExecutionContextInterface $executionContext, array $reducers )
$executionContext Youshido\GraphQL\Execution\Context\ExecutionContextInterface
$reducers array

walkQuery() protected method

childScore costs are accumulated via values sent into the coroutine. Most of the branching in this function is just to handle the different types in a query: Queries, Unions, Fragments (anonymous and named), and Fields. The core of the function is simple: recurse until we hit the base case of a Field and yield that back up to the visitor up in doVisit.
protected walkQuery ( Query | Field | Youshido\GraphQL\Parser\Ast\Interfaces\FragmentInterface $queryNode, Youshido\GraphQL\Field\FieldInterface $currentLevelAST ) : Generator
$queryNode Youshido\GraphQL\Parser\Ast\Query | Youshido\GraphQL\Field\Field | Youshido\GraphQL\Parser\Ast\Interfaces\FragmentInterface
$currentLevelAST Youshido\GraphQL\Field\FieldInterface
return Generator