WooCommerce Code Reference

Helper
in package

Contains functionality that could be re-used by various server implementations.

Tags
see
HelperTest

Table of Contents

executeBatch()  : array<int, ExecutionResult>|Promise
Executes batched Automattic\WooCommerce\Vendor\GraphQL operations with shared promise queue (thus, effectively batching deferreds|promises of all queries at once).
executeOperation()  : ExecutionResult|Promise
Executes Automattic\WooCommerce\Vendor\GraphQL operation with given server configuration and returns execution result (or promise when promise adapter is different from SyncPromiseAdapter).
parseHttpRequest()  : OperationParams|array<int, OperationParams>
Parses HTTP request using PHP globals and returns Automattic\WooCommerce\Vendor\GraphQL OperationParams contained in this request. For batched requests it returns an array of OperationParams.
parsePsrRequest()  : OperationParams|array<string|int, OperationParams>
Converts PSR-7 request to OperationParams or an array thereof.
parseRequestParams()  : OperationParams|array<int, OperationParams>
Parses normalized request params and returns instance of OperationParams or array of OperationParams in case of batch operation.
sendResponse()  : void
Send response using standard PHP `header()` and `echo`.
toPsrResponse()  : Promise|ResponseInterface
Converts query execution result to PSR-7 response.
validateOperationParams()  : array<int, RequestError>
Checks validity of OperationParams extracted from HTTP request and returns an array of errors if params are invalid (or empty array when params are valid).
assertJsonObjectOrArray()  : void
decodeContent()  : array<string|int, mixed>
decodeJson()  : mixed
doConvertToPsrResponse()  : ResponseInterface
emitResponse()  : void
loadPersistedQuery()  : mixed
promiseToExecuteOperation()  : Promise
readRawBody()  : string
resolveContextValue()  : mixed
resolveRootValue()  : mixed
resolveValidationRules()  : array<string|int, mixed>|null

Methods

executeBatch()

Executes batched Automattic\WooCommerce\Vendor\GraphQL operations with shared promise queue (thus, effectively batching deferreds|promises of all queries at once).

public executeBatch(ServerConfig $config, array<string|int, OperationParams$operations) : array<int, ExecutionResult>|Promise
Parameters
$config : ServerConfig
$operations : array<string|int, OperationParams>
Tags
throws
Exception
throws
InvariantViolation
Return values
array<int, ExecutionResult>|Promise

parseHttpRequest()

Parses HTTP request using PHP globals and returns Automattic\WooCommerce\Vendor\GraphQL OperationParams contained in this request. For batched requests it returns an array of OperationParams.

public parseHttpRequest([callable|null $readRawBodyFn = null ]) : OperationParams|array<int, OperationParams>

This function does not check validity of these params (validation is performed separately in validateOperationParams() method).

If $readRawBodyFn argument is not provided - will attempt to read raw request body from php://input stream.

Internally it normalizes input to $method, $bodyParams and $queryParams and calls parseRequestParams() to produce actual return value.

For PSR-7 request parsing use parsePsrRequest() instead.

Parameters
$readRawBodyFn : callable|null = null
Tags
throws
RequestError
Return values
OperationParams|array<int, OperationParams>

parseRequestParams()

Parses normalized request params and returns instance of OperationParams or array of OperationParams in case of batch operation.

public parseRequestParams(string $method, array<string|int, mixed> $bodyParams, array<string|int, mixed> $queryParams) : OperationParams|array<int, OperationParams>

Returned value is a suitable input for executeOperation or executeBatch (if array)

Parameters
$method : string
$bodyParams : array<string|int, mixed>
$queryParams : array<string|int, mixed>
Tags
throws
RequestError
Return values
OperationParams|array<int, OperationParams>

toPsrResponse()

Converts query execution result to PSR-7 response.

public toPsrResponse(Promise|ExecutionResult|array<string|int, ExecutionResult$result, ResponseInterface $response, StreamInterface $writableBodyStream) : Promise|ResponseInterface
Parameters
$result : Promise|ExecutionResult|array<string|int, ExecutionResult>
$response : ResponseInterface
$writableBodyStream : StreamInterface
Tags
throws
InvalidArgumentException
throws
JsonException
throws
RuntimeException
Return values
Promise|ResponseInterface

decodeContent()

protected decodeContent(string $rawBody) : array<string|int, mixed>
Parameters
$rawBody : string
Return values
array<string|int, mixed>

doConvertToPsrResponse()

protected doConvertToPsrResponse(ExecutionResult|array<string|int, ExecutionResult$result, ResponseInterface $response, StreamInterface $writableBodyStream) : ResponseInterface
Parameters
$result : ExecutionResult|array<string|int, ExecutionResult>
$response : ResponseInterface
$writableBodyStream : StreamInterface
Tags
throws
InvalidArgumentException
throws
JsonException
throws
RuntimeException
Return values
ResponseInterface

emitResponse()

protected emitResponse(array<string|int, mixed>|JsonSerializable $jsonSerializable) : void
Parameters
$jsonSerializable : array<string|int, mixed>|JsonSerializable
Tags
throws
JsonException
Return values
void