22
33namespace GraphQL \Server ;
44
5- use GraphQL \Error \DebugFlag ;
6- use GraphQL \Error \FormattedError ;
75use GraphQL \Error \InvariantViolation ;
86use GraphQL \Executor \ExecutionResult ;
97use GraphQL \Executor \Promise \Promise ;
1210use Psr \Http \Message \RequestInterface ;
1311use Psr \Http \Message \ResponseInterface ;
1412use Psr \Http \Message \StreamInterface ;
15- use Throwable ;
1613
1714/**
1815 * GraphQL server compatible with both: [express-graphql](https://github.com/graphql/express-graphql)
3734 */
3835class StandardServer
3936{
40- private ServerConfig $ config ;
37+ protected ServerConfig $ config ;
4138
42- private Helper $ helper ;
39+ protected Helper $ helper ;
4340
4441 /**
45- * Converts and exception to error and sends spec-compliant HTTP 500 error.
46- * Useful when an exception is thrown somewhere outside of server execution context
47- * (e.g. during schema instantiation).
48- *
49- * @api
50- */
51- public static function send500Error (Throwable $ error , int $ debug = DebugFlag::NONE ): void
52- {
53- $ helper = new Helper ();
54- $ helper ->emitResponse (
55- [
56- 'errors ' => [FormattedError::createFromException ($ error , $ debug )],
57- ],
58- 500 ,
59- );
60- }
61-
62- /**
63- * Creates new instance of a standard GraphQL HTTP server.
64- *
6542 * @param ServerConfig|array<string, mixed> $config
6643 *
6744 * @api
@@ -84,12 +61,12 @@ public function __construct($config)
8461 /**
8562 * Parses HTTP request, executes and emits response (using standard PHP `header` function and `echo`).
8663 *
87- * By default (when $parsedBody is not set) it uses PHP globals to parse a request.
64+ * When $parsedBody is not set, it uses PHP globals to parse a request.
8865 * It is possible to implement request parsing elsewhere (e.g. using framework Request instance)
8966 * and then pass it to the server.
9067 *
91- * See `executeRequest()` if you prefer to emit response yourself
92- * (e.g. using Response object of some framework)
68+ * See `executeRequest()` if you prefer to emit the response yourself
69+ * (e.g. using the Response object of some framework).
9370 *
9471 * @param OperationParams|array<OperationParams> $parsedBody
9572 *
@@ -102,19 +79,17 @@ public function handleRequest($parsedBody = null): void
10279 }
10380
10481 /**
105- * Executes GraphQL operation and returns execution result
82+ * Executes a GraphQL operation and returns an execution result
10683 * (or promise when promise adapter is different from SyncPromiseAdapter).
10784 *
108- * By default (when $parsedBody is not set) it uses PHP globals to parse a request.
85+ * When $parsedBody is not set, it uses PHP globals to parse a request.
10986 * It is possible to implement request parsing elsewhere (e.g. using framework Request instance)
11087 * and then pass it to the server.
11188 *
11289 * PSR-7 compatible method executePsrRequest() does exactly this.
11390 *
11491 * @param OperationParams|array<OperationParams> $parsedBody
11592 *
116- * @throws InvariantViolation
117- *
11893 * @return ExecutionResult|array<int, ExecutionResult>|Promise
11994 *
12095 * @api
@@ -166,15 +141,4 @@ public function executePsrRequest(RequestInterface $request)
166141
167142 return $ this ->executeRequest ($ parsedBody );
168143 }
169-
170- /**
171- * Returns an instance of Server helper, which contains most of the actual logic for
172- * parsing / validating / executing request (which could be re-used by other server implementations).
173- *
174- * @api
175- */
176- public function getHelper (): Helper
177- {
178- return $ this ->helper ;
179- }
180144}
0 commit comments