|
8 | 8 | use Laminas\Diactoros\ServerRequestFactory; |
9 | 9 | use Laminas\Diactoros\StreamFactory; |
10 | 10 | use Laminas\Diactoros\UploadedFileFactory; |
| 11 | +use LogicException; |
11 | 12 | use Symfony\Bridge\PsrHttpMessage\Factory\PsrHttpFactory; |
| 13 | +use TheCodingMachine\GraphQLite\Bundle\UploadMiddlewareUtils\DummyResponseWithRequest; |
| 14 | +use TheCodingMachine\GraphQLite\Bundle\UploadMiddlewareUtils\RequestExtractorMiddleware; |
12 | 15 | use TheCodingMachine\GraphQLite\Http\HttpCodeDecider; |
13 | 16 | use TheCodingMachine\GraphQLite\Http\HttpCodeDeciderInterface; |
14 | | -use function array_map; |
15 | 17 | use GraphQL\Executor\ExecutionResult; |
16 | 18 | use GraphQL\Server\ServerConfig; |
17 | 19 | use GraphQL\Server\StandardServer; |
18 | 20 | use GraphQL\Upload\UploadMiddleware; |
19 | | -use function class_exists; |
20 | | -use function json_decode; |
21 | 21 | use Psr\Http\Message\ServerRequestInterface; |
22 | 22 | use RuntimeException; |
23 | 23 | use Symfony\Bridge\PsrHttpMessage\HttpMessageFactoryInterface; |
|
28 | 28 | use Symfony\Component\Routing\RouteCollection; |
29 | 29 | use TheCodingMachine\GraphQLite\Bundle\Context\SymfonyGraphQLContext; |
30 | 30 |
|
| 31 | +use function array_map; |
| 32 | +use function class_exists; |
| 33 | +use function get_class; |
| 34 | +use function json_decode; |
| 35 | + |
31 | 36 | /** |
32 | | - * Listens to every single request and forward Graphql requests to Graphql Webonix standardServer. |
| 37 | + * Listens to every single request and forwards GraphQL requests to Webonyx's {@see \GraphQL\Server\StandardServer}. |
33 | 38 | */ |
34 | 39 | class GraphQLiteController |
35 | 40 | { |
36 | | - /** |
37 | | - * @var HttpMessageFactoryInterface |
38 | | - */ |
39 | | - private $httpMessageFactory; |
40 | | - /** @var int */ |
41 | | - private $debug; |
42 | | - /** |
43 | | - * @var ServerConfig |
44 | | - */ |
45 | | - private $serverConfig; |
46 | | - /** |
47 | | - * @var HttpCodeDeciderInterface |
48 | | - */ |
49 | | - private $httpCodeDecider; |
| 41 | + private HttpMessageFactoryInterface $httpMessageFactory; |
| 42 | + private int $debug; |
| 43 | + private ServerConfig $serverConfig; |
| 44 | + private HttpCodeDeciderInterface $httpCodeDecider; |
50 | 45 |
|
51 | 46 | public function __construct(ServerConfig $serverConfig, ?HttpMessageFactoryInterface $httpMessageFactory = null, ?int $debug = null, ?HttpCodeDeciderInterface $httpCodeDecider = null) |
52 | 47 | { |
@@ -90,10 +85,14 @@ public function handleRequest(Request $request): Response |
90 | 85 | $psr7Request = $psr7Request->withParsedBody($parsedBody); |
91 | 86 | } |
92 | 87 |
|
93 | | - // Let's parse the request and adapt it for file uploads. |
| 88 | + // Let's parse the request and adapt it for file uploads by extracting it from the middleware. |
94 | 89 | if (class_exists(UploadMiddleware::class)) { |
95 | 90 | $uploadMiddleware = new UploadMiddleware(); |
96 | | - $psr7Request = $uploadMiddleware->processRequest($psr7Request); |
| 91 | + $dummyResponseWithRequest = $uploadMiddleware->process($psr7Request, new RequestExtractorMiddleware()); |
| 92 | + if (! $dummyResponseWithRequest instanceof DummyResponseWithRequest) { |
| 93 | + throw new LogicException(DummyResponseWithRequest::class . ' expect, got ' . get_class($dummyResponseWithRequest)); |
| 94 | + } |
| 95 | + $psr7Request = $dummyResponseWithRequest->getRequest(); |
97 | 96 | } |
98 | 97 |
|
99 | 98 | return $this->handlePsr7Request($psr7Request, $request); |
|
0 commit comments