StandardServer
in package
GraphQL server compatible with both: [express-graphql](https://github.com/graphql/express-graphql) and [Apollo Server](https://github.com/apollographql/graphql-server).
Usage Example:
$server = new StandardServer([
'schema' => $mySchema
]);
$server->handleRequest();
Or using ServerConfig instance:
$config = GraphQL\Server\ServerConfig::create()
->setSchema($mySchema)
->setContext($myContext);
$server = new GraphQL\Server\StandardServer($config);
$server->handleRequest();
See dedicated section in docs for details.
Table of Contents
- $config : ServerConfig
- $helper : Helper
- __construct() : mixed
- Creates new instance of a standard GraphQL HTTP server
- executePsrRequest() : ExecutionResult|array<string|int, ExecutionResult>|Promise
- Executes GraphQL operation and returns execution result (or promise when promise adapter is different from SyncPromiseAdapter)
- executeRequest() : ExecutionResult|array<string|int, ExecutionResult>|Promise
- Executes GraphQL operation and returns execution result (or promise when promise adapter is different from SyncPromiseAdapter).
- getHelper() : Helper
- Returns an instance of Server helper, which contains most of the actual logic for parsing / validating / executing request (which could be re-used by other server implementations)
- handleRequest() : mixed
- Parses HTTP request, executes and emits response (using standard PHP `header` function and `echo`)
- processPsrRequest() : ResponseInterface|Promise
- Executes PSR-7 request and fulfills PSR-7 response.
- send500Error() : mixed
- Converts and exception to error and sends spec-compliant HTTP 500 error.
Properties
$config
private
ServerConfig
$config
$helper
private
Helper
$helper
Methods
__construct()
Creates new instance of a standard GraphQL HTTP server
public
__construct(ServerConfig|array<string|int, mixed> $config) : mixed
Parameters
- $config : ServerConfig|array<string|int, mixed>
Return values
mixed —executePsrRequest()
Executes GraphQL operation and returns execution result (or promise when promise adapter is different from SyncPromiseAdapter)
public
executePsrRequest(RequestInterface $request) : ExecutionResult|array<string|int, ExecutionResult>|Promise
Parameters
- $request : RequestInterface
Return values
ExecutionResult|array<string|int, ExecutionResult>|Promise —executeRequest()
Executes GraphQL operation and returns execution result (or promise when promise adapter is different from SyncPromiseAdapter).
public
executeRequest([OperationParams|array<string|int, OperationParams> $parsedBody = null ]) : ExecutionResult|array<string|int, ExecutionResult>|Promise
By default (when $parsedBody is not set) it uses PHP globals to parse a request. It is possible to implement request parsing elsewhere (e.g. using framework Request instance) and then pass it to the server.
PSR-7 compatible method executePsrRequest() does exactly this.
Parameters
- $parsedBody : OperationParams|array<string|int, OperationParams> = null
Tags
Return values
ExecutionResult|array<string|int, ExecutionResult>|Promise —getHelper()
Returns an instance of Server helper, which contains most of the actual logic for parsing / validating / executing request (which could be re-used by other server implementations)
public
getHelper() : Helper
Return values
Helper —handleRequest()
Parses HTTP request, executes and emits response (using standard PHP `header` function and `echo`)
public
handleRequest([OperationParams|array<string|int, OperationParams> $parsedBody = null ][, bool $exitWhenDone = false ]) : mixed
By default (when $parsedBody is not set) it uses PHP globals to parse a request. It is possible to implement request parsing elsewhere (e.g. using framework Request instance) and then pass it to the server.
See executeRequest()
if you prefer to emit response yourself
(e.g. using Response object of some framework)
Parameters
- $parsedBody : OperationParams|array<string|int, OperationParams> = null
- $exitWhenDone : bool = false
Return values
mixed —processPsrRequest()
Executes PSR-7 request and fulfills PSR-7 response.
public
processPsrRequest(RequestInterface $request, ResponseInterface $response, StreamInterface $writableBodyStream) : ResponseInterface|Promise
See executePsrRequest()
if you prefer to create response yourself
(e.g. using specific JsonResponse instance of some framework).
Parameters
- $request : RequestInterface
- $response : ResponseInterface
- $writableBodyStream : StreamInterface
Return values
ResponseInterface|Promise —send500Error()
Converts and exception to error and sends spec-compliant HTTP 500 error.
public
static send500Error(Throwable $error[, int $debug = DebugFlag::NONE ][, bool $exitWhenDone = false ]) : mixed
Useful when an exception is thrown somewhere outside of server execution context (e.g. during schema instantiation).
Parameters
- $error : Throwable
- $debug : int = DebugFlag::NONE
- $exitWhenDone : bool = false