Commit 732ae5ba authored by Steffen Schlaer's avatar Steffen Schlaer Committed by Steffen Schlaer
Browse files

Issue #3323571 by IT-Cru: Broken GraphQL request detection in...

Issue #3323571 by IT-Cru: Broken GraphQL request detection in consumer_base_url_is_graphql_request()
parent 950149e9
Loading
Loading
Loading
Loading
+16 −10
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Render\BubbleableMetadata;
use Drupal\Core\Routing\RouteObjectInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Symfony\Component\HttpFoundation\Request;

/**
 * Implements hook_entity_base_field_info().
@@ -87,10 +88,13 @@ function consumer_base_url_tokens_alter(array &$replacements, array $context, Bu
/**
 * Helper function to detect GraphQL requests.
 *
 * @param \Symfony\Component\HttpFoundation\Request|null $request
 *   The HttpRequest object representing the current request.
 *
 * @return bool
 *   Return TRUE if request is a GraphQL query.
 */
function consumer_base_url_is_graphql_request():bool {
function consumer_base_url_is_graphql_request(Request $request = NULL): bool {
  static $drupal_static_fast;
  if (!isset($drupal_static_fast)) {
    $drupal_static_fast['is_graphql_request'] = &drupal_static(__FUNCTION__);
@@ -98,17 +102,19 @@ function consumer_base_url_is_graphql_request():bool {

  $is_graphql_request = &$drupal_static_fast['is_graphql_request'];
  if (!isset($is_graphql_request)) {
    $graphql_routes = [
      'graphql.query.default:default',
      'graphql.explorer.default:default',
      'graphql.voyager.default:default',
    ];
    $is_graphql_request = FALSE;

    if (is_null($request)) {
      $request = \Drupal::request();
    $route_name = $request->attributes->get(RouteObjectInterface::ROUTE_NAME);
    $is_apollo = $request->query->get('extensions');
    if (in_array($route_name, $graphql_routes) || $is_apollo) {
    }

    if ($request
      && (
        $request->attributes->has('_graphql_subrequest')
        || $request->attributes->has('_graphql')
      )
    ) {

      $is_graphql_request = TRUE;
    }
  }
+1 −4
Original line number Diff line number Diff line
@@ -70,10 +70,7 @@ class ConsumerPathProcessor implements OutboundPathProcessorInterface {
      }

      // Do not change Base URL in GraphQL 4.x and 3.x requests.
      if ($request
        && ($request->attributes->has('_graphql_subrequest')
          || $request->attributes->has('_graphql'))
      ) {
      if (consumer_base_url_is_graphql_request($request)) {
        return $path;
      }