-
Notifications
You must be signed in to change notification settings - Fork 43
👽 Support ecodev/graphql-upload v8 #268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,8 @@ | |
| use Laminas\Diactoros\StreamFactory; | ||
| use Laminas\Diactoros\UploadedFileFactory; | ||
| use Symfony\Bridge\PsrHttpMessage\Factory\PsrHttpFactory; | ||
| use TheCodingMachine\GraphQLite\Bundle\UploadMiddlewareUtils\DummyResponseWithRequest; | ||
| use TheCodingMachine\GraphQLite\Bundle\UploadMiddlewareUtils\RequestExtractorMiddleware; | ||
| use TheCodingMachine\GraphQLite\Http\HttpCodeDecider; | ||
| use TheCodingMachine\GraphQLite\Http\HttpCodeDeciderInterface; | ||
| use GraphQL\Executor\ExecutionResult; | ||
|
|
@@ -30,24 +32,14 @@ | |
| use function json_decode; | ||
|
|
||
| /** | ||
| * Listens to every single request and forward Graphql requests to Graphql Webonix standardServer. | ||
| * Listens to every single request and forwards GraphQL requests to Webonyx's \GraphQL\Server\StandardServer. | ||
| */ | ||
| class GraphQLiteController | ||
| { | ||
| /** | ||
| * @var HttpMessageFactoryInterface | ||
| */ | ||
| private $httpMessageFactory; | ||
| /** @var int */ | ||
| private $debug; | ||
| /** | ||
| * @var ServerConfig | ||
| */ | ||
| private $serverConfig; | ||
| /** | ||
| * @var HttpCodeDeciderInterface | ||
| */ | ||
| private $httpCodeDecider; | ||
| private HttpMessageFactoryInterface $httpMessageFactory; | ||
| private int $debug; | ||
| private ServerConfig $serverConfig; | ||
| private HttpCodeDeciderInterface $httpCodeDecider; | ||
|
|
||
| public function __construct(ServerConfig $serverConfig, ?HttpMessageFactoryInterface $httpMessageFactory = null, ?int $debug = null, ?HttpCodeDeciderInterface $httpCodeDecider = null) | ||
| { | ||
|
|
@@ -98,11 +90,12 @@ public function handleRequest(Request $request): Response | |
| $psr7Request = $psr7Request->withParsedBody($parsedBody); | ||
| } | ||
|
|
||
| // Let's parse the request and adapt it for file uploads. | ||
| // Let's parse the request and adapt it for file uploads by extracting it from the middleware. | ||
| if (class_exists(UploadMiddleware::class)) { | ||
| $uploadMiddleware = new UploadMiddleware(); | ||
| $psr7Request = $uploadMiddleware->processRequest($psr7Request); | ||
| \assert($psr7Request instanceof ServerRequestInterface); | ||
| $dummyResponseWithRequest = $uploadMiddleware->process($psr7Request, new RequestExtractorMiddleware()); | ||
| assert($dummyResponseWithRequest instanceof DummyResponseWithRequest); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code is not so strict as to be sure that you will have a I suggest to use |
||
| $psr7Request = $dummyResponseWithRequest->getRequest(); | ||
| } | ||
|
|
||
| return $this->handlePsr7Request($psr7Request, $request); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| <?php | ||
|
|
||
| namespace TheCodingMachine\GraphQLite\Bundle\UploadMiddlewareUtils; | ||
|
|
||
| use Laminas\Diactoros\Response; | ||
| use Psr\Http\Message\ServerRequestInterface; | ||
|
|
||
| /** | ||
| * Class used to allow extraction of request from PSR-15 middleware | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please mark introduced classes with |
||
| */ | ||
| class DummyResponseWithRequest extends Response | ||
| { | ||
| private ServerRequestInterface $request; | ||
|
|
||
| public function __construct(ServerRequestInterface $request) | ||
| { | ||
| parent::__construct(); | ||
| $this->request = $request; | ||
| } | ||
|
|
||
| public function getRequest(): ServerRequestInterface | ||
| { | ||
| return $this->request; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| <?php | ||
|
|
||
| namespace TheCodingMachine\GraphQLite\Bundle\UploadMiddlewareUtils; | ||
|
|
||
| use Psr\Http\Message\ResponseInterface; | ||
| use Psr\Http\Message\ServerRequestInterface; | ||
| use Psr\Http\Server\RequestHandlerInterface; | ||
|
|
||
| /** | ||
| * Middleware to extract the request from the middleware chain | ||
| */ | ||
| class RequestExtractorMiddleware implements RequestHandlerInterface | ||
| { | ||
| public function handle(ServerRequestInterface $request): ResponseInterface | ||
This comment was marked as resolved.
Sorry, something went wrong. |
||
| { | ||
| return new DummyResponseWithRequest($request); | ||
| } | ||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.