You are here

protected function HttpRequestTrait::query in GraphQL 8.4

Same name and namespace in other branches
  1. 8.3 tests/src/Traits/HttpRequestTrait.php \Drupal\Tests\graphql\Traits\HttpRequestTrait::query()

Issue a simple query over http.

Parameters

string $query: The query string.

\Drupal\graphql\Entity\Server|null $server: The server instance.

array $variables: Query variables.

array|null $extensions: The query extensions.

bool $persisted: Flag if the query is actually the identifier of a persisted query.

Return value

\Symfony\Component\HttpFoundation\Response The http response object.

10 calls to HttpRequestTrait::query()
DisabledResultCacheTest::testDisabledCache in tests/src/Kernel/Framework/DisabledResultCacheTest.php
Test if disabling the result cache has the desired effect.
PersistedQueriesTest::testPersistedQueries in tests/src/Kernel/Framework/PersistedQueriesTest.php
Test a simple query result.
ResultCacheTest::testCacheableResult in tests/src/Kernel/Framework/ResultCacheTest.php
Check basic result caching.
ResultCacheTest::testContext in tests/src/Kernel/Framework/ResultCacheTest.php
Test if changing test context's trigger re-evaluations.
ResultCacheTest::testLeakingCacheMetadata in tests/src/Kernel/Framework/ResultCacheTest.php
Test behavior in case of leaking cache metadata.

... See full list

File

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

Class

HttpRequestTrait
Test trait for the GraphQL HTTP interface.

Namespace

Drupal\Tests\graphql\Traits

Code

protected function query($query, $server = NULL, array $variables = [], array $extensions = NULL, $persisted = FALSE) {
  $server = $server ?: $this->server;
  if (!$server instanceof Server) {
    throw new \LogicException('Invalid server.');
  }
  $endpoint = $this->server
    ->get('endpoint');
  $extensions = !empty($extensions) ? [
    'extensions' => $extensions,
  ] : [];

  // If the persisted flag is true, then instead of sending the full query to
  // the server we only send the query id.
  $query_key = $persisted ? 'queryId' : 'query';
  $request = Request::create($endpoint, 'GET', [
    $query_key => $query,
    'variables' => $variables,
  ] + $extensions);
  return $this->container
    ->get('http_kernel')
    ->handle($request);
}