Helper
in package
Contains functionality that could be re-used by various server implementations
Table of Contents
- emitResponse() : mixed
- executeBatch() : ExecutionResult|array<string|int, ExecutionResult>|Promise
- Executes batched GraphQL operations with shared promise queue (thus, effectively batching deferreds|promises of all queries at once)
- executeOperation() : ExecutionResult|Promise
- Executes GraphQL operation with given server configuration and returns execution result (or promise when promise adapter is different from SyncPromiseAdapter)
- parseHttpRequest() : OperationParams|array<string|int, OperationParams>
- Parses HTTP request using PHP globals and returns GraphQL OperationParams contained in this request. For batched requests it returns an array of OperationParams.
- parsePsrRequest() : array<string|int, OperationParams>|OperationParams
- Converts PSR-7 request to OperationParams[]
- parseRequestParams() : OperationParams|array<string|int, OperationParams>
- Parses normalized request params and returns instance of OperationParams or array of OperationParams in case of batch operation.
- sendResponse() : mixed
- 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)
- decodeContent() : array<string, mixed>
- doConvertToPsrResponse() : mixed
- doSendResponse() : mixed
- loadPersistedQuery() : mixed
- promiseToExecuteOperation() : Promise
- readRawBody() : bool|string
- resolveContextValue() : mixed
- resolveHttpStatus() : int
- resolveRootValue() : mixed
- resolveValidationRules() : array<string|int, mixed>|null
Methods
emitResponse()
public
emitResponse(array<string|int, mixed>|JsonSerializable $jsonSerializable, int $httpStatus, bool $exitWhenDone) : mixed
Parameters
- $jsonSerializable : array<string|int, mixed>|JsonSerializable
- $httpStatus : int
- $exitWhenDone : bool
Return values
mixed —executeBatch()
Executes batched 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) : ExecutionResult|array<string|int, ExecutionResult>|Promise
Parameters
- $config : ServerConfig
- $operations : array<string|int, OperationParams>
Return values
ExecutionResult|array<string|int, ExecutionResult>|Promise —executeOperation()
Executes 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
Return values
ExecutionResult|Promise —parseHttpRequest()
Parses HTTP request using PHP globals and returns GraphQL OperationParams contained in this request. For batched requests it returns an array of OperationParams.
public
parseHttpRequest([callable|null $readRawBodyFn = null ]) : OperationParams|array<string|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<string|int, OperationParams> —parsePsrRequest()
Converts PSR-7 request to OperationParams[]
public
parsePsrRequest(RequestInterface $request) : array<string|int, OperationParams>|OperationParams
Parameters
- $request : RequestInterface
Tags
Return values
array<string|int, OperationParams>|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<string|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<string|int, OperationParams> —sendResponse()
Send response using standard PHP `header()` and `echo`.
public
sendResponse(Promise|ExecutionResult|array<string|int, ExecutionResult> $result[, bool $exitWhenDone = false ]) : mixed
Parameters
- $result : Promise|ExecutionResult|array<string|int, ExecutionResult>
- $exitWhenDone : bool = false
Return values
mixed —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
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> —decodeContent()
protected
decodeContent(string $rawBody, string $contentType) : array<string, mixed>
Parameters
- $rawBody : string
- $contentType : string
Tags
Return values
array<string, mixed> —doConvertToPsrResponse()
private
doConvertToPsrResponse(mixed $result, ResponseInterface $response, StreamInterface $writableBodyStream) : mixed
Parameters
- $result : mixed
- $response : ResponseInterface
- $writableBodyStream : StreamInterface
Return values
mixed —doSendResponse()
private
doSendResponse(mixed $result, mixed $exitWhenDone) : mixed
Parameters
- $result : mixed
- $exitWhenDone : mixed
Return values
mixed —loadPersistedQuery()
private
loadPersistedQuery(ServerConfig $config, OperationParams $operationParams) : mixed
Parameters
- $config : ServerConfig
- $operationParams : OperationParams
Tags
Return values
mixed —promiseToExecuteOperation()
private
promiseToExecuteOperation(PromiseAdapter $promiseAdapter, ServerConfig $config, OperationParams $op[, bool $isBatch = false ]) : Promise
Parameters
- $promiseAdapter : PromiseAdapter
- $config : ServerConfig
- $op : OperationParams
- $isBatch : bool = false
Return values
Promise —readRawBody()
private
readRawBody() : bool|string
Return values
bool|string —resolveContextValue()
private
resolveContextValue(ServerConfig $config, OperationParams $params, DocumentNode $doc, string $operationType) : mixed
Parameters
- $config : ServerConfig
- $params : OperationParams
- $doc : DocumentNode
- $operationType : string
Return values
mixed —resolveHttpStatus()
private
resolveHttpStatus(ExecutionResult|array<string|int, mixed> $result) : int
Parameters
- $result : ExecutionResult|array<string|int, mixed>
Return values
int —resolveRootValue()
private
resolveRootValue(ServerConfig $config, OperationParams $params, DocumentNode $doc, string $operationType) : mixed
Parameters
- $config : ServerConfig
- $params : OperationParams
- $doc : DocumentNode
- $operationType : string
Return values
mixed —resolveValidationRules()
private
resolveValidationRules(ServerConfig $config, OperationParams $params, DocumentNode $doc, string $operationType) : array<string|int, mixed>|null
Parameters
- $config : ServerConfig
- $params : OperationParams
- $doc : DocumentNode
- $operationType : string