Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make bad request exception generic unless in debug mode (0.13) #1128

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
},
"config": {
"bin-dir": "bin",
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"phpstan/extension-installer": true
}
},
"require": {
"php": ">=7.2",
Expand Down
22 changes: 20 additions & 2 deletions src/Controller/GraphController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;

class GraphController
{
Expand Down Expand Up @@ -36,18 +37,25 @@ class GraphController
*/
private $useApolloBatchingMethod;

/**
* @var bool
*/
private $debugMode;

public function __construct(
GraphQLRequest\ParserInterface $batchParser,
GraphQLRequest\Executor $requestExecutor,
GraphQLRequest\ParserInterface $requestParser,
$shouldHandleCORS,
$graphQLBatchingMethod
$graphQLBatchingMethod,
$debugMode = true
) {
$this->batchParser = $batchParser;
$this->requestExecutor = $requestExecutor;
$this->requestParser = $requestParser;
$this->shouldHandleCORS = $shouldHandleCORS;
$this->useApolloBatchingMethod = 'apollo' === $graphQLBatchingMethod;
$this->debugMode = $debugMode;
}

/**
Expand Down Expand Up @@ -87,7 +95,17 @@ private function createResponse(Request $request, string $schemaName = null, boo
if (!\in_array($request->getMethod(), ['POST', 'GET'])) {
return new Response('', 405);
}
$payload = $this->processQuery($request, $schemaName, $batched);

try {
$payload = $this->processQuery($request, $schemaName, $batched);
} catch(BadRequestHttpException $e) {
if ($this->debugMode) {
throw $e;
} else {
return new JsonResponse('', 400);
}
}

$response = new JsonResponse($payload, 200);
}
$this->addCORSHeadersIfNeeded($response, $request);
Expand Down
1 change: 1 addition & 0 deletions src/Resources/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ services:
- '@Overblog\GraphQLBundle\Request\Parser'
- "%overblog_graphql.handle_cors%"
- "%overblog_graphql.batching_method%"
- "%kernel.debug%"

Overblog\GraphQLBundle\Definition\ConfigProcessor: ~

Expand Down