public function JsonQueryMapQueryProvider::getQuery in GraphQL 8.3
Returns a query string given the query parameters.
Can be used to load a query string from arbitrary query parameters e.g. when using persisted queries (loading queries by their hash or version and id).
Parameters
string $id: The query id.
\GraphQL\Server\OperationParams $operation: The operation parameters.
Return value
string|null The query string or NULL if it couldn't be determined.
Overrides QueryProviderInterface::getQuery
File
- src/
GraphQL/ QueryProvider/ JsonQueryMapQueryProvider.php, line 42
Class
Namespace
Drupal\graphql\GraphQL\QueryProviderCode
public function getQuery($id, OperationParams $operation) {
list($version, $id) = explode(':', $id);
// Check that the id is properly formatted.
if (empty($version) || empty($id)) {
return NULL;
}
if (!(($cache = $this->cacheBackend
->get('graphql_query_map_json_versions')) && ($versions = $cache->data) !== NULL)) {
$this->cacheBackend
->set('graphql_query_map_json_versions', $versions = $this
->discoverQueryMaps());
}
if (isset($versions) && isset($versions[$version]) && file_exists($versions[$version])) {
$contents = json_decode(file_get_contents($versions[$version]), TRUE);
if ($query = array_search($id, $contents)) {
return $query;
}
}
return NULL;
}