You are here

public function QueryRouteEnhancer::enhance in GraphQL 8.3

Same name and namespace in other branches
  1. 8.4 src/Routing/QueryRouteEnhancer.php \Drupal\graphql\Routing\QueryRouteEnhancer::enhance()

File

src/Routing/QueryRouteEnhancer.php, line 18

Class

QueryRouteEnhancer

Namespace

Drupal\graphql\Routing

Code

public function enhance(array $defaults, Request $request) {
  $route = $defaults[RouteObjectInterface::ROUTE_OBJECT];
  if (!$route
    ->hasDefault('_graphql')) {
    return $defaults;
  }
  $helper = new Helper();
  $method = $request
    ->getMethod();
  $body = $this
    ->extractBody($request);
  $query = $this
    ->extractQuery($request);
  $operations = $helper
    ->parseRequestParams($method, $body, $query);

  // By default we assume a 'single' request. This is going to fail in the
  // graphql processor due to a missing query string but at least provides
  // the right format for the client to act upon.
  return $defaults + [
    '_controller' => $defaults['_graphql']['single'],
    'operations' => $operations,
  ];
}