src/Executor/Executor.php
protected static function buildExecutionContext(Schema $schema, $root, Document $ast, $operationName = NULL, array $args = NULL, &$errors)
    {
        $operations = [];
        $fragments = [];

        foreach ($ast->get('definitions') as $statement) {
            switch ($statement::KIND) {
                case Node::KIND_OPERATION_DEFINITION:
                    $operations[$statement->get('name') ? $statement->get('name')->get('value') : ''] = $statement;
                    break;

                case Node::KIND_FRAGMENT_DEFINITION:
                    $fragments[$statement->get('name')->get('value')] = $statement;
                    break;
            }
        }

        if (!$operationName && count($operations) !== 1) {
            throw new \Exception('Must provide operation name if query contains multiple operations');
        }

        $name = $operationName ?: key($operations);
        if (!isset($operations[$name])) {
            throw new \Exception('Unknown operation name: ' . $name);
        }

        $operation = $operations[$name];
        $variables = Values::getVariableValues($schema, $operation->get('variableDefinitions') ?: [], $args ?: []);
        $context = new ExecutionContext($schema, $fragments, $root, $operation, $variables, $errors);

        return $context;
    }
protected static function buildExecutionContext(Schema $schema, $root, Document $ast, $operationName = NULL, array $args = NULL, &$errors)
    {
        $operations = [];
        $fragments = [];

        foreach ($ast->get('definitions') as $statement) {
            switch ($statement::KIND) {
                case Node::KIND_OPERATION_DEFINITION:
                    $operations[$statement->get('name') ? $statement->get('name')->get('value') : ''] = $statement;
                    break;

                case Node::KIND_FRAGMENT_DEFINITION:
                    $fragments[$statement->get('name')->get('value')] = $statement;
                    break;
            }
        }

        if (!$operationName && count($operations) !== 1) {
            throw new \Exception('Must provide operation name if query contains multiple operations');
        }

        $name = $operationName ?: key($operations);
        if (!isset($operations[$name])) {
            throw new \Exception('Unknown operation name: ' . $name);
        }

        $operation = $operations[$name];
        $variables = Values::getVariableValues($schema, $operation->get('variableDefinitions') ?: [], $args ?: []);
        $context = new ExecutionContext($schema, $fragments, $root, $operation, $variables, $errors);

        return $context;
    }
protected static function buildExecutionContext ( Schema $ schema , $ root , Document $ ast , $ operationName = NULL , array $ args = NULL , & $ errors ) { $ operations = [ ] ; $ fragments = [ ] ; foreach ( $ ast -> get ( 'definitions' ) as $ statement ) { switch ( $ statement :: KIND ) { case Node :: KIND_OPERATION_DEFINITION : $ operations [ $ statement -> get ( 'name' ) ? $ statement -> get ( 'name' ) -> get ( 'value' ) : '' ] = $ statement ; break ; case Node :: KIND_FRAGMENT_DEFINITION : $ fragments [ $ statement -> get ( 'name' ) -> get ( 'value' ) ] = $ statement ; break ; } } if ( ! $ operationName && count ( $ operations ) !== 1 ) { throw new \ Exception ( 'Must provide operation name if query contains multiple operations' ) ; } $ name = $ operationName ? : key ( $ operations ) ; if ( ! isset ( $ operations [ $ name ] ) ) { throw new \ Exception ( 'Unknown operation name: ' . $ name ) ; } $ operation = $ operations [ $ name ] ; $ variables = Values :: getVariableValues ( $ schema , $ operation -> get ( 'variableDefinitions' ) ? : [ ] , $ args ? : [ ] ) ; $ context = new ExecutionContext ( $ schema , $ fragments , $ root , $ operation , $ variables , $ errors ) ; return $ context ; }
Constructs a ExecutionContext object from the arguments passed to
execute, which we will pass throughout the other execution methods.

@param Schema $schema
@param $root
@param Document $ast
@param string|null $operationName
@param array $args
@param $errors

@return ExecutionContext

@throws \Exception
Constructs a ExecutionContext object from the arguments passed to execute which we will pass throughout the other execution methods .