Skip to content

Commit

Permalink
Merge pull request #11 from daniellienert/task/support-flow-6
Browse files Browse the repository at this point in the history
Feature: Flow 6.0 compatibility
  • Loading branch information
bwaidelich authored Jan 6, 2020
2 parents adefd13 + 7f6b5cd commit 058cb29
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 19 deletions.
2 changes: 2 additions & 0 deletions Classes/Controller/StandardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use GraphQL\GraphQL;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Mvc\Controller\ActionController;
use Neos\Flow\Mvc\Exception\NoSuchArgumentException;
use Wwwision\GraphQL\GraphQLContext;
use Wwwision\GraphQL\SchemaService;
use Wwwision\GraphQL\TypeResolver;
Expand Down Expand Up @@ -54,6 +55,7 @@ public function indexAction($endpoint)
* @param string $operationName The operation to execute (if multiple, see GraphQL::execute())
* @return void
* @Flow\SkipCsrfProtection
* @throws NoSuchArgumentException
*/
public function queryAction($endpoint, $query, $variables = null, $operationName = null)
{
Expand Down
14 changes: 7 additions & 7 deletions Classes/GraphQLContext.php
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
<?php
namespace Wwwision\GraphQL;

use Neos\Flow\Http\Request as HttpRequest;
use Psr\Http\Message\ServerRequestInterface;

/**
* A custom context that will be accessible to all resolvers
*/
final class GraphQLContext
{
/**
* @var HttpRequest
* @var ServerRequestInterface
*/
private $httpRequest;

/**
* @param HttpRequest $httpRequest
* @param ServerRequestInterface $httpRequest
*/
public function __construct(HttpRequest $httpRequest)
public function __construct(ServerRequestInterface $httpRequest)
{
$this->httpRequest = $httpRequest;
}

/**
* @return HttpRequest
* @return ServerRequestInterface
*/
public function getHttpRequest()
public function getHttpRequest(): ServerRequestInterface
{
return $this->httpRequest;
}

}
}
6 changes: 4 additions & 2 deletions Classes/Http/HttpOptionsComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ public function handle(ComponentContext $componentContext)
if ($httpRequest->getMethod() !== 'OPTIONS') {
return;
}
$endpoint = ltrim($httpRequest->getUri()->getPath(), '\/');
// no matching graphQL endpoint configured => skip
if (!isset($this->endpoints[$httpRequest->getRelativePath()])) {
if (!isset($this->endpoints[$endpoint])) {
return;
}
$httpResponse = $componentContext->getHttpResponse();
$httpResponse->setHeader('Allow', 'GET, POST');
$httpResponse = $httpResponse->withHeader('Allow', 'GET, POST');
$componentContext->replaceHttpResponse($httpResponse);
$componentContext->setParameter(ComponentChain::class, 'cancel', true);
}
}
4 changes: 2 additions & 2 deletions Classes/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Neos\Flow\Core\Bootstrap;
use Neos\Flow\Monitor\FileMonitor;
use Neos\Flow\Package\Package as BasePackage;
use Neos\Flow\Package\PackageManagerInterface;
use Neos\Flow\Package\PackageManager;
use Neos\Utility\Files;
use Neos\Utility\Unicode\Functions;

Expand Down Expand Up @@ -41,7 +41,7 @@ public function boot(Bootstrap $bootstrap)
$graphQlFileMonitor = FileMonitor::createFileMonitorAtBoot(self::FILE_MONITOR_IDENTIFIER, $bootstrap);
$configurationManager = $bootstrap->getEarlyInstance(ConfigurationManager::class);
$endpointsConfiguration = $configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, 'Wwwision.GraphQL.endpoints');
$packageManager = $bootstrap->getEarlyInstance(PackageManagerInterface::class);
$packageManager = $bootstrap->getEarlyInstance(PackageManager::class);

foreach($endpointsConfiguration as $endpointConfiguration) {
if (!isset($endpointConfiguration['schema'])) {
Expand Down
13 changes: 6 additions & 7 deletions Classes/View/GraphQlView.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
use GraphQL\Error\Error;
use GraphQL\Executor\ExecutionResult;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Http\Response as HttpResponse;
use Neos\Flow\Log\SystemLoggerInterface;
use Neos\Flow\Exception as FlowException;
use Neos\Flow\Http\Helper\ResponseInformationHelper;
use Neos\Flow\Log\ThrowableStorageInterface;
use Neos\Flow\Mvc\ActionResponse;
use Neos\Flow\Mvc\View\AbstractView;
use Neos\Flow\Exception as FlowException;
use Psr\Log\LoggerInterface;

class GraphQlView extends AbstractView
Expand Down Expand Up @@ -40,9 +40,8 @@ public function render()
throw new FlowException(sprintf('The GraphQlView expects a variable "result" of type "%s", "%s" given!', ExecutionResult::class, is_object($result) ? get_class($result) : gettype($result)), 1469545198);
}

/** @var HttpResponse $response */
$response = $this->controllerContext->getResponse();
$response->setHeader('Content-Type', 'application/json');
$response->setContentType('application/json');

return json_encode($this->formatResult($result));
}
Expand All @@ -67,7 +66,7 @@ private function formatResult(ExecutionResult $executionResult)
];
$exception = $error->getPrevious();
if ($exception instanceof FlowException) {
$errorResult['message'] = HttpResponse::getStatusMessageByCode($exception->getStatusCode());
$errorResult['message'] = ResponseInformationHelper::getStatusMessageByCode($exception->getStatusCode());
$errorResult['_exceptionCode'] = $exception->getCode();
$errorResult['_statusCode'] = $exception->getStatusCode();
$errorResult['_referenceCode'] = $exception->getReferenceCode();
Expand All @@ -84,4 +83,4 @@ private function formatResult(ExecutionResult $executionResult)
}
return $convertedResult;
}
}
}
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": "^4.0 || ^5.0",
"neos/flow": "^6.0",
"webonyx/graphql-php": "^0.13.0"
},
"autoload": {
Expand Down

0 comments on commit 058cb29

Please sign in to comment.