Skip to content

Commit

Permalink
Merge pull request #31 from Sebobo/task/flow-7-compatibility
Browse files Browse the repository at this point in the history
!!! TASK: Flow 7 compatibility
  • Loading branch information
johannessteu committed Dec 31, 2020
2 parents 5dd4068 + 6d50087 commit ea0fde5
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 57 deletions.
46 changes: 0 additions & 46 deletions Classes/Http/HttpOptionsComponent.php

This file was deleted.

40 changes: 40 additions & 0 deletions Classes/Http/HttpOptionsMiddleware.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

namespace t3n\GraphQL\Http;

use GuzzleHttp\Psr7\Response;
use Neos\Flow\Annotations as Flow;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;

class HttpOptionsMiddleware implements MiddlewareInterface
{
/**
* @Flow\InjectConfiguration("endpoints")
*
* @var mixed[]
*/
protected $endpoints;

public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
if ($request->getMethod() !== 'OPTIONS') {
return $handler->handle($request);
}

// We explode the request target because custom routes like /some/custom/route/<endpoint> are
// are common. So we double check here if the last part in the route matches a configured
// endpoint
$endpoint = explode('/', ltrim($request->getRequestTarget(), '\/'));

if (! isset($this->endpoints[end($endpoint)])) {
return $handler->handle($request);
}

return new Response(200, ['Content-Type' => 'application/json', 'Allow' => 'GET, POST'], json_encode(['success' => true]));
}
}
10 changes: 4 additions & 6 deletions Configuration/Settings.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
Neos:
Flow:
http:
chain:
'process':
chain:
'graphQLOptions':
position: 'before routing'
component: 't3n\GraphQL\Http\HttpOptionsComponent'
middlewares:
'graphQLOptions':
position: 'before routing'
middleware: 't3n\GraphQL\Http\HttpOptionsMiddleware'
log:
graphQLRequestLogger:
logger: Neos\Flow\Log\Logger
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
"bin-dir": "bin"
},
"require": {
"neos/flow": "~6.0",
"neos/flow": "~7.0",
"t3n/graphql-tools": "~1.0.2",
"php": ">=7.2",
"ext-json": "*"
},
"require-dev": {
"t3n/coding-standard": "~1.0.0"
"t3n/coding-standard": "~1.1.0"
},
"autoload": {
"psr-4": {
Expand Down
6 changes: 3 additions & 3 deletions composer.json.ci
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
"bin-dir": "bin"
},
"require": {
"neos/flow": "~6.0",
"neos/buildessentials": "~6.0",
"neos/flow": "~7.0",
"neos/buildessentials": "~7.0",
"t3n/graphql": "@dev",
"t3n/coding-standard": "~1.1.0"
},
"require-dev": {
"squizlabs/php_codesniffer": "~3.5",
"phpunit/phpunit": "~8.5",
"phpunit/phpunit": "~9.3",
"mikey179/vfsstream": "~1.6"
},
"repositories": {
Expand Down

0 comments on commit ea0fde5

Please sign in to comment.