drupal-graphql / drupal-graphql/graphql
Persisted query provider 'JsonQueryMapQueryProvider' not working.
- Dominant language
- PHP
- Stars
- 287
- Forks
- 198
- PR merge metrics
- No merged PRs in 30d
Description
I have been investigating persisted queries and it seems that if you are using JsonQueryMapQueryProvider it is broken. [JsonQueryMapQueryProvider.php#L56](https://github.com/drupal-graphql/graphql/blob/65a6555daaf1a7e3df3e2c2ed5b1d76a13f804d3/src/GraphQL/QueryProvider/JsonQueryMapQueryProvider.php#L56)
```
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;
}
}
```
uses an `array_aearch()` to locate the id in the json array and then returns the result, which is not a query, and also being an `array_search()` if the index returned is 0 then it jumps to the returning NULL.
I played a little and changed it to the following which got it working.
```
if (isset($versions) && isset($versions[$version]) && file_exists($versions[$version])) {
$contents = json_decode(file_get_contents($versions[$version]), TRUE);
if (isset($contents[$id])) {
return $contents[$id];
}
}
```
Which this works however I am not sure why this is being done like this, as we are just setting up a json array with the query in it, and once deployed you can't change the query as the sha1 will change.
I am wondering if a GQL query provider would work better, Instead of a JSON file with the query, use a text file with extension of `.gql` which is a plain text version of the query which is a lot easier to read and edit. As for using a sha1 to reference the query just using the filename (excluding the extension) which will mean the query can be changed without needing to change the frontend references to this query.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.