You are here

trait QueryFileTrait in GraphQL 8.3

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

Trait for retrieving GraphQL queries from files.

Hierarchy

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

File

tests/src/Traits/QueryFileTrait.php, line 8

Namespace

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

  /**
   * Get the path to the directory containing test query files.
   *
   * @return string
   *   The path to the collection of test query files.
   */
  protected function getQueriesDirectory() {
    return drupal_get_path('module', explode('\\', get_class($this))[2]) . '/tests/queries';
  }

  /**
   * Retrieve the GraphQL query stored in a file as string.
   *
   * @param string $queryFile
   *   The query file name.
   *
   * @return string
   *   The graphql query string.
   */
  public function getQueryFromFile($queryFile) {
    return file_get_contents($this
      ->getQueriesDirectory() . '/' . $queryFile);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
QueryFileTrait::getQueriesDirectory protected function Get the path to the directory containing test query files.
QueryFileTrait::getQueryFromFile public function Retrieve the GraphQL query stored in a file as string.