diff --git a/app/etc/graphql/di.xml b/app/etc/graphql/di.xml new file mode 100644 index 000000000000..aba60d00080f --- /dev/null +++ b/app/etc/graphql/di.xml @@ -0,0 +1,10 @@ + + + + + diff --git a/lib/internal/Magento/Framework/GraphQl/Query/ErrorHandler.php b/lib/internal/Magento/Framework/GraphQl/Query/ErrorHandler.php new file mode 100644 index 000000000000..2661034116f9 --- /dev/null +++ b/lib/internal/Magento/Framework/GraphQl/Query/ErrorHandler.php @@ -0,0 +1,48 @@ +logger = $logger; + } + + /** + * @inheritDoc + */ + public function handle(array $errors, callable $formatter): array + { + return array_map( + function (ClientAware $error) use ($formatter) { + $this->logger->error($error); + + return $formatter($error); + }, + $errors + ); + } +} diff --git a/lib/internal/Magento/Framework/GraphQl/Query/ErrorHandlerInterface.php b/lib/internal/Magento/Framework/GraphQl/Query/ErrorHandlerInterface.php new file mode 100644 index 000000000000..b89207fe3bdb --- /dev/null +++ b/lib/internal/Magento/Framework/GraphQl/Query/ErrorHandlerInterface.php @@ -0,0 +1,32 @@ +exceptionFormatter = $exceptionFormatter; $this->queryComplexityLimiter = $queryComplexityLimiter; + $this->errorHandler = $errorHandler; } /** @@ -67,6 +77,8 @@ public function process( $contextValue, $variableValues, $operationName + )->setErrorsHandler( + [$this->errorHandler, 'handle'] )->toArray( $this->exceptionFormatter->shouldShowDetail() ? \GraphQL\Error\Debug::INCLUDE_DEBUG_MESSAGE : false