From 42956875d4bbbb9e47d60aae0cef93cbf0d7c82c Mon Sep 17 00:00:00 2001 From: Johannes Steu Date: Mon, 15 Jul 2019 11:16:32 +0200 Subject: [PATCH 1/2] SchemaService can now be asked for endpoint configuration --- Classes/Service/SchemaService.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Classes/Service/SchemaService.php b/Classes/Service/SchemaService.php index 8042c13..db7de48 100644 --- a/Classes/Service/SchemaService.php +++ b/Classes/Service/SchemaService.php @@ -74,6 +74,14 @@ public function getSchemaForEndpoint(string $endpoint): Schema return $schema; } + /** + * @return mixed[] + */ + public function getEndpointConfiguration(string $endpoint): ?array + { + return $this->endpoints[$endpoint] ?? null; + } + protected function getSchemaFromEnvelope(string $envelopeClassName): Schema { $envelope = $this->objectManager->get($envelopeClassName); From 365aa790072bebd40982e0f107eabfd642773bd8 Mon Sep 17 00:00:00 2001 From: Johannes Steu Date: Mon, 15 Jul 2019 12:54:41 +0200 Subject: [PATCH 2/2] Add new Request Logger To enable the request logger set the `logRequests` for your endpoint to true --- Classes/Controller/GraphQLController.php | 18 ++++++++++++++++-- Classes/Log/RequestLoggerInterface.php | 11 +++++++++++ Configuration/Objects.yaml | 8 ++++++++ Configuration/Settings.yaml | 12 ++++++++++++ Readme.md | 15 +++++++++++++++ 5 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 Classes/Log/RequestLoggerInterface.php diff --git a/Classes/Controller/GraphQLController.php b/Classes/Controller/GraphQLController.php index e78cb11..1402849 100644 --- a/Classes/Controller/GraphQLController.php +++ b/Classes/Controller/GraphQLController.php @@ -9,6 +9,7 @@ use Neos\Flow\Mvc\Controller\ActionController; use t3n\GraphQL\Context; use t3n\GraphQL\Exception\InvalidContextException; +use t3n\GraphQL\Log\RequestLoggerInterface; use t3n\GraphQL\Service\DefaultFieldResolver; use t3n\GraphQL\Service\SchemaService; use t3n\GraphQL\Service\ValidationRuleService; @@ -43,6 +44,13 @@ class GraphQLController extends ActionController */ protected $endpointConfigurations; + /** + * @Flow\Inject + * + * @var RequestLoggerInterface + */ + protected $requestLogger; + /** * phpcs:disable SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableParameterTypeHintSpecification * @@ -62,8 +70,10 @@ public function queryAction(string $endpoint, string $query, ?array $variables = $schema = $this->schemaService->getSchemaForEndpoint($endpoint); $validationRules = $this->validationRuleService->getValidationRulesForEndpoint($endpoint); - if (isset($this->endpointConfigurations[$endpoint]['context'])) { - $contextClassname = $this->endpointConfigurations[$endpoint]['context']; + $endpointConfiguration = $this->endpointConfigurations[$endpoint] ?? []; + + if (isset($endpointConfiguration['context'])) { + $contextClassname = $endpointConfiguration['context']; } else { $contextClassname = $this->contextClassName; } @@ -73,6 +83,10 @@ public function queryAction(string $endpoint, string $query, ?array $variables = throw new InvalidContextException('The configured Context must extend \t3n\GraphQL\Context', 1545945332); } + if (isset($endpointConfiguration['logRequests']) && $endpointConfiguration['logRequests'] === true) { + $this->requestLogger->info('Incoming graphql request', ['endpoint' => $endpoint, 'query' => json_encode($query), 'variables' => empty($variables) ? 'none' : $variables]); + } + GraphQL::setDefaultFieldResolver([DefaultFieldResolver::class, 'resolve']); $result = GraphQL::executeQuery( diff --git a/Classes/Log/RequestLoggerInterface.php b/Classes/Log/RequestLoggerInterface.php new file mode 100644 index 0000000..e333aa5 --- /dev/null +++ b/Classes/Log/RequestLoggerInterface.php @@ -0,0 +1,11 @@ +