You are here

trait HttpRequestTrait in GraphQL 8.3

Same name and namespace in other branches
  1. 8.4 tests/src/Traits/HttpRequestTrait.php \Drupal\Tests\graphql\Traits\HttpRequestTrait

Test trait for the GraphQL HTTP interface.

Hierarchy

1 file declares its use of HttpRequestTrait
GraphQLTestBase.php in tests/src/Kernel/GraphQLTestBase.php

File

tests/src/Traits/HttpRequestTrait.php, line 10

Namespace

Drupal\Tests\graphql\Traits
View source
trait HttpRequestTrait {

  /**
   * Issue a simple query over http.
   *
   * @param string $query
   *   The query string.
   * @param array $variables
   *   Query variables.
   *
   * @return \Symfony\Component\HttpFoundation\Response
   *   The http response object.
   */
  protected function query($query, array $variables = []) {
    return $this->container
      ->get('http_kernel')
      ->handle(Request::create('/graphql', 'GET', [
      'query' => $query,
      'variables' => $variables,
    ]));
  }

  /**
   * Issue a persisted query over http.
   *
   * @param $id
   *   The query id.
   * @param array $variables
   *   Query variables.
   *
   * @return \Symfony\Component\HttpFoundation\Response
   *   The http response object.
   */
  protected function persistedQuery($id, array $variables = []) {
    return $this->container
      ->get('http_kernel')
      ->handle(Request::create('/graphql', 'GET', [
      'queryId' => $id,
      'variables' => $variables,
    ]));
  }

  /**
   * Simulate batched queries over http.
   *
   * @param string[] $queries
   *   A set of queries to be executed in one go.
   *
   * @return \Symfony\Component\HttpFoundation\Response
   *   The http response object.
   */
  protected function batchedQueries($queries) {
    return $this->container
      ->get('http_kernel')
      ->handle(Request::create('/graphql', 'POST', [], [], [], [], json_encode($queries)));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
HttpRequestTrait::batchedQueries protected function Simulate batched queries over http.
HttpRequestTrait::persistedQuery protected function Issue a persisted query over http.
HttpRequestTrait::query protected function Issue a simple query over http.