Skip to content
Open
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
18 changes: 16 additions & 2 deletions src/Controller/GraphController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use function in_array;

class GraphController
Expand All @@ -19,19 +20,22 @@ class GraphController
private Parser $requestParser;
private bool $shouldHandleCORS;
private bool $useApolloBatchingMethod;
private bool $debugMode;

public function __construct(
BatchParser $batchParser,
Executor $requestExecutor,
Parser $requestParser,
bool $shouldHandleCORS,
string $graphQLBatchingMethod
string $graphQLBatchingMethod,
bool $debugMode = false
) {
$this->batchParser = $batchParser;
$this->requestExecutor = $requestExecutor;
$this->requestParser = $requestParser;
$this->shouldHandleCORS = $shouldHandleCORS;
$this->useApolloBatchingMethod = 'apollo' === $graphQLBatchingMethod;
$this->debugMode = $debugMode;
}

/**
Expand Down Expand Up @@ -61,7 +65,17 @@ private function createResponse(Request $request, ?string $schemaName, bool $bat
if (!in_array($request->getMethod(), ['POST', 'GET'])) {
return new JsonResponse('', 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($e->getMessage(), 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 @@ -88,6 +88,7 @@ services:
- '@Overblog\GraphQLBundle\Request\Parser'
- "%overblog_graphql.handle_cors%"
- "%overblog_graphql.batching_method%"
- "%kernel.debug%"

Overblog\GraphQLBundle\Definition\ConfigProcessor:
arguments:
Expand Down