Skip to content

Commit

Permalink
Merge pull request #15 from sitegeist/neos7
Browse files Browse the repository at this point in the history
Neos 7 Compatibility
  • Loading branch information
bwaidelich authored Jul 5, 2021
2 parents ab08458 + 05566c2 commit d8c4f7e
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 48 deletions.
41 changes: 0 additions & 41 deletions Classes/Http/HttpOptionsComponent.php

This file was deleted.

46 changes: 46 additions & 0 deletions Classes/Http/HttpOptionsMiddleware.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
namespace Wwwision\GraphQL\Http;

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;
use Psr\Http\Message\ResponseFactoryInterface;

/**
* A simple HTTP Component that captures OPTIONS requests and responds with a general "Allow: GET, POST" header if a matching graphQL endpoint is configured
*/
class HttpOptionsMiddleware implements MiddlewareInterface
{
/**
* @Flow\InjectConfiguration(path="endpoints")
* @var array
*/
protected $endpoints;

/**
* @Flow\Inject
* @var ResponseFactoryInterface
*/
protected $responseFactory;

/**
* @param ServerRequestInterface $request
* @param RequestHandlerInterface $next
* @return ResponseInterface
*/
public function process(ServerRequestInterface $request, RequestHandlerInterface $next): ResponseInterface
{
// no OPTIONS request => 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');
}
}
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: 'Wwwision\GraphQL\Http\HttpOptionsComponent'
middlewares:
redirect:
position: 'before routing'
middleware: 'Wwwision\GraphQL\Http\HttpOptionsMidleware'

Wwwision:
GraphQL:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit d8c4f7e

Please sign in to comment.