2
2
3
3
namespace GraphQL \Server ;
4
4
5
- use GraphQL \Error \DebugFlag ;
6
- use GraphQL \Error \FormattedError ;
7
5
use GraphQL \Error \InvariantViolation ;
8
6
use GraphQL \Executor \ExecutionResult ;
9
7
use GraphQL \Executor \Promise \Promise ;
12
10
use Psr \Http \Message \RequestInterface ;
13
11
use Psr \Http \Message \ResponseInterface ;
14
12
use Psr \Http \Message \StreamInterface ;
15
- use Throwable ;
16
13
17
14
/**
18
15
* GraphQL server compatible with both: [express-graphql](https://github.com/graphql/express-graphql)
37
34
*/
38
35
class StandardServer
39
36
{
40
- private ServerConfig $ config ;
37
+ protected ServerConfig $ config ;
41
38
42
- private Helper $ helper ;
39
+ protected Helper $ helper ;
43
40
44
41
/**
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
- *
65
42
* @param ServerConfig|array<string, mixed> $config
66
43
*
67
44
* @api
@@ -84,12 +61,12 @@ public function __construct($config)
84
61
/**
85
62
* Parses HTTP request, executes and emits response (using standard PHP `header` function and `echo`).
86
63
*
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.
88
65
* It is possible to implement request parsing elsewhere (e.g. using framework Request instance)
89
66
* and then pass it to the server.
90
67
*
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).
93
70
*
94
71
* @param OperationParams|array<OperationParams> $parsedBody
95
72
*
@@ -102,19 +79,17 @@ public function handleRequest($parsedBody = null): void
102
79
}
103
80
104
81
/**
105
- * Executes GraphQL operation and returns execution result
82
+ * Executes a GraphQL operation and returns an execution result
106
83
* (or promise when promise adapter is different from SyncPromiseAdapter).
107
84
*
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.
109
86
* It is possible to implement request parsing elsewhere (e.g. using framework Request instance)
110
87
* and then pass it to the server.
111
88
*
112
89
* PSR-7 compatible method executePsrRequest() does exactly this.
113
90
*
114
91
* @param OperationParams|array<OperationParams> $parsedBody
115
92
*
116
- * @throws InvariantViolation
117
- *
118
93
* @return ExecutionResult|array<int, ExecutionResult>|Promise
119
94
*
120
95
* @api
@@ -166,15 +141,4 @@ public function executePsrRequest(RequestInterface $request)
166
141
167
142
return $ this ->executeRequest ($ parsedBody );
168
143
}
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
- }
180
144
}
0 commit comments