From c90891efe20af07ea95af2991b220e87a27755e1 Mon Sep 17 00:00:00 2001 From: Martin Ficzel Date: Mon, 28 Jun 2021 09:47:22 +0200 Subject: [PATCH 1/2] Allow Neos 7 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 7c9f28f..0f7f00d 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "name": "wwwision/graphql", "license": "MIT", "require": { - "neos/flow": "^6.0", + "neos/flow": "^7.0", "webonyx/graphql-php": "^0.13.0" }, "autoload": { From 05566c2f7fa2d389eab28492984a024ec503585f Mon Sep 17 00:00:00 2001 From: Martin Ficzel Date: Mon, 28 Jun 2021 11:21:30 +0200 Subject: [PATCH 2/2] TASK: Use middleware instead of http components --- Classes/Http/HttpOptionsComponent.php | 41 ----------------------- Classes/Http/HttpOptionsMiddleware.php | 46 ++++++++++++++++++++++++++ Configuration/Settings.yaml | 10 +++--- 3 files changed, 50 insertions(+), 47 deletions(-) delete mode 100644 Classes/Http/HttpOptionsComponent.php create mode 100644 Classes/Http/HttpOptionsMiddleware.php diff --git a/Classes/Http/HttpOptionsComponent.php b/Classes/Http/HttpOptionsComponent.php deleted file mode 100644 index d16d2b7..0000000 --- a/Classes/Http/HttpOptionsComponent.php +++ /dev/null @@ -1,41 +0,0 @@ -getHttpRequest(); - // no OPTIONS request => skip - if ($httpRequest->getMethod() !== 'OPTIONS') { - return; - } - $endpoint = ltrim($httpRequest->getUri()->getPath(), '\/'); - // no matching graphQL endpoint configured => skip - if (!isset($this->endpoints[$endpoint])) { - return; - } - $httpResponse = $componentContext->getHttpResponse(); - $httpResponse = $httpResponse->withHeader('Allow', 'GET, POST'); - $componentContext->replaceHttpResponse($httpResponse); - $componentContext->setParameter(ComponentChain::class, 'cancel', true); - } -} diff --git a/Classes/Http/HttpOptionsMiddleware.php b/Classes/Http/HttpOptionsMiddleware.php new file mode 100644 index 0000000..0032ab3 --- /dev/null +++ b/Classes/Http/HttpOptionsMiddleware.php @@ -0,0 +1,46 @@ + skip + if ($request->getMethod() !== 'OPTIONS') { + return $next->handle($request); + } + $endpoint = ltrim($request->getUri()->getPath(), '\/'); + // no matching graphQL endpoint configured => skip + if (!isset($this->endpoints[$endpoint])) { + return $next->handle($request); + } + return $this->responseFactory->createResponse()->withHeader('Allow', 'GET, POST'); + } +} diff --git a/Configuration/Settings.yaml b/Configuration/Settings.yaml index b95989b..c3eb141 100644 --- a/Configuration/Settings.yaml +++ b/Configuration/Settings.yaml @@ -1,12 +1,10 @@ Neos: Flow: http: - chain: - 'process': - chain: - 'graphQLOptions': - position: 'before routing' - component: 'Wwwision\GraphQL\Http\HttpOptionsComponent' + middlewares: + redirect: + position: 'before routing' + middleware: 'Wwwision\GraphQL\Http\HttpOptionsMidleware' Wwwision: GraphQL: