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;
    }