You are here

QueryFileTrait.php in GraphQL 8.4

Same filename and directory in other branches
  1. 8.3 tests/src/Traits/QueryFileTrait.php

File

tests/src/Traits/QueryFileTrait.php
View source
<?php

namespace Drupal\Tests\graphql\Traits;


/**
 * Trait for retrieving GraphQL queries from files.
 */
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);
  }

}

Traits

Namesort descending Description
QueryFileTrait Trait for retrieving GraphQL queries from files.