public function RequestController::handleRequest in GraphQL 8
Same name and namespace in other branches
- 8.4 src/Controller/RequestController.php \Drupal\graphql\Controller\RequestController::handleRequest()
- 8.2 src/Controller/RequestController.php \Drupal\graphql\Controller\RequestController::handleRequest()
- 8.3 src/Controller/RequestController.php \Drupal\graphql\Controller\RequestController::handleRequest()
Handles GraphQL requests.
Parameters
\Symfony\Component\HttpFoundation\Request: The request object.
Return value
\Symfony\Component\HttpFoundation\JsonResponse The JSON formatted response.
Throws
\Symfony\Component\HttpKernel\Exception\NotFoundHttpException
1 string reference to 'RequestController::handleRequest'
File
- src/
Controller/ RequestController.php, line 81
Class
- RequestController
- Handles GraphQL requests.
Namespace
Drupal\graphql\ControllerCode
public function handleRequest(Request $request) {
$body = (array) json_decode($request
->getContent()) + [
'query' => NULL,
'variables' => NULL,
'operation' => NULL,
];
$query = $request->query
->has('query') ? $request->query
->get('query') : $body['query'];
$variables = $request->query
->has('variables') ? $request->query
->get('variables') : $body['variables'];
$operation = $request->query
->has('operation') ? $request->query
->get('operation') : $body['operation'];
if (empty($query)) {
throw new NotFoundHttpException();
}
$schema = $this->schemaLoader
->loadSchema($this->languageManager
->getCurrentLanguage());
$variables = $variables ? (array) json_decode($variables) : NULL;
$result = $this->graphql
->execute($schema, $query, NULL, $variables, $operation);
$response = new JsonResponse($result);
return $response
->setPrivate();
}