Helper
in package
Contains functionality that could be re-used by various server implementations.
Tags
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
Return values
array<int, ExecutionResult>|Promise —executeOperation()
Executes Automattic\WooCommerce\Vendor\GraphQL operation with given server configuration and returns execution result (or promise when promise adapter is different from SyncPromiseAdapter).
public
executeOperation(ServerConfig $config, OperationParams $op) : ExecutionResult|Promise
Parameters
- $config : ServerConfig
- $op : OperationParams
Tags
Return values
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
Return values
OperationParams|array<int, OperationParams> —parsePsrRequest()
Converts PSR-7 request to OperationParams or an array thereof.
public
parsePsrRequest(RequestInterface $request) : OperationParams|array<string|int, OperationParams>
Parameters
- $request : RequestInterface
Tags
Return values
OperationParams|array<string|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
Return values
OperationParams|array<int, OperationParams> —sendResponse()
Send response using standard PHP `header()` and `echo`.
public
sendResponse(Promise|ExecutionResult|array<string|int, ExecutionResult> $result) : void
Parameters
- $result : Promise|ExecutionResult|array<string|int, ExecutionResult>
Tags
Return values
void —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
Return values
Promise|ResponseInterface —validateOperationParams()
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).
public
validateOperationParams(OperationParams $params) : array<int, RequestError>
Parameters
- $params : OperationParams
Return values
array<int, RequestError> —assertJsonObjectOrArray()
protected
assertJsonObjectOrArray(mixed $bodyParams) : void
Parameters
- $bodyParams : mixed
Tags
Return values
void —decodeContent()
protected
decodeContent(string $rawBody) : array<string|int, mixed>
Parameters
- $rawBody : string
Return values
array<string|int, mixed> —decodeJson()
protected
decodeJson(string $rawBody) : mixed
Parameters
- $rawBody : string
Tags
Return values
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
Return values
ResponseInterface —emitResponse()
protected
emitResponse(array<string|int, mixed>|JsonSerializable $jsonSerializable) : void
Parameters
- $jsonSerializable : array<string|int, mixed>|JsonSerializable
Tags
Return values
void —loadPersistedQuery()
protected
loadPersistedQuery(ServerConfig $config, OperationParams $operationParams) : mixed
Parameters
- $config : ServerConfig
- $operationParams : OperationParams
Tags
Return values
mixed —promiseToExecuteOperation()
protected
promiseToExecuteOperation(PromiseAdapter $promiseAdapter, ServerConfig $config, OperationParams $op[, bool $isBatch = false ]) : Promise
Parameters
- $promiseAdapter : PromiseAdapter
- $config : ServerConfig
- $op : OperationParams
- $isBatch : bool = false
Tags
Return values
Promise —readRawBody()
protected
readRawBody() : string
Tags
Return values
string —resolveContextValue()
protected
resolveContextValue(ServerConfig $config, OperationParams $params, DocumentNode $doc, string $operationType) : mixed
Parameters
- $config : ServerConfig
- $params : OperationParams
- $doc : DocumentNode
- $operationType : string
Return values
mixed — user definedresolveRootValue()
protected
resolveRootValue(ServerConfig $config, OperationParams $params, DocumentNode $doc, string $operationType) : mixed
Parameters
- $config : ServerConfig
- $params : OperationParams
- $doc : DocumentNode
- $operationType : string
Return values
mixed —resolveValidationRules()
protected
resolveValidationRules(ServerConfig $config, OperationParams $params, DocumentNode $doc, string $operationType) : array<string|int, mixed>|null
Parameters
- $config : ServerConfig
- $params : OperationParams
- $doc : DocumentNode
- $operationType : string
