trait QueryFileTrait in GraphQL 8.4
Same name and namespace in other branches
- 8.3 tests/src/Traits/QueryFileTrait.php \Drupal\Tests\graphql\Traits\QueryFileTrait
Trait for retrieving GraphQL queries from files.
Hierarchy
- trait \Drupal\Tests\graphql\Traits\QueryFileTrait
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\TraitsView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
QueryFileTrait:: |
protected | function | Get the path to the directory containing test query files. | |
QueryFileTrait:: |
public | function | Retrieve the GraphQL query stored in a file as string. |