Documentation

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

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
throws
RequestError
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<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
throws
RequestError
Return values
OperationParams|array<string|int, OperationParams>

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
throws
RequestError
Return values
array<string, mixed>

doSendResponse()

private doSendResponse(mixed $result, mixed $exitWhenDone) : mixed
Parameters
$result : mixed
$exitWhenDone : mixed
Return values
mixed

readRawBody()

private readRawBody() : bool|string
Return values
bool|string

resolveHttpStatus()

private resolveHttpStatus(ExecutionResult|array<string|int, mixed> $result) : int
Parameters
$result : ExecutionResult|array<string|int, mixed>
Return values
int

Search results