Automattic\WooCommerce\Vendor\GraphQL\Server

Helper::promiseToExecuteOperation │ protected │ WC 1.0

Method of the class: Helper{}

No Hooks.

Returns

null. Nothing (null).

Usage

// protected - for code of main (parent) or child class
$result = $this->promiseToExecuteOperation( $promiseAdapter, $config, $op, $isBatch ): Promise;
$promiseAdapter(PromiseAdapter) (required)
.
$config(ServerConfig) (required)
.
$op(OperationParams) (required)
.
$isBatch(true|false)
.
Default: false

Helper::promiseToExecuteOperation() code WC 11.1.2

protected function promiseToExecuteOperation(
    PromiseAdapter $promiseAdapter,
    ServerConfig $config,
    OperationParams $op,
    bool $isBatch = false
): Promise {
    try {
        if ($config->getSchema() === null) {
            throw new InvariantViolation('Schema is required for the server');
        }

        if ($isBatch && ! $config->getQueryBatching()) {
            throw new BatchedQueriesAreNotSupported('Batched queries are not supported by this server');
        }

        $errors = $this->validateOperationParams($op);

        if ($errors !== []) {
            $locatedErrors = array_map(
                [Error::class, 'createLocatedError'],
                $errors
            );

            return $promiseAdapter->createFulfilled(
                new ExecutionResult(null, $locatedErrors)
            );
        }

        $doc = $op->queryId !== null
            ? $this->loadPersistedQuery($config, $op)
            : $op->query;

        if (! $doc instanceof DocumentNode) {
            $doc = Parser::parse($doc);
        }

        $operationAST = AST::getOperationAST($doc, $op->operation);

        if ($operationAST === null) {
            throw new FailedToDetermineOperationType('Failed to determine operation type');
        }

        $operationType = $operationAST->operation;
        if ($operationType !== 'query' && $op->readOnly) {
            throw new GetMethodSupportsOnlyQueryOperation('GET supports only query operation');
        }

        $result = GraphQL::promiseToExecute(
            $promiseAdapter,
            $config->getSchema(),
            $doc,
            $this->resolveRootValue($config, $op, $doc, $operationType),
            $this->resolveContextValue($config, $op, $doc, $operationType),
            $op->variables,
            $op->operation,
            $config->getFieldResolver(),
            $this->resolveValidationRules($config, $op, $doc, $operationType)
        );
    } catch (RequestError $e) {
        $result = $promiseAdapter->createFulfilled(
            new ExecutionResult(null, [Error::createLocatedError($e)])
        );
    } catch (Error $e) {
        $result = $promiseAdapter->createFulfilled(
            new ExecutionResult(null, [$e])
        );
    }

    $applyErrorHandling = static function (ExecutionResult $result) use ($config): ExecutionResult {
        $result->setErrorsHandler($config->getErrorsHandler());

        $result->setErrorFormatter(
            FormattedError::prepareFormatter(
                $config->getErrorFormatter(),
                $config->getDebugFlag()
            )
        );

        return $result;
    };

    return $result->then($applyErrorHandling);
}