drupal-graphql / drupal-graphql/graphql

4.x $metadata caching not respecting max-age

Open
#1,167 4 comments 0 reactions 0 assignees View on GitHub
4.x
Dominant language
PHP
Stars
287
Forks
198
PR merge metrics
No merged PRs in 30d

Description

I'm trying to cache most of a schema, while certain fields should never be cached. I understand that Drupal may prevent the max-age specification from applying to anonymous users, but this behavior is also happening via a logged in user. The debug code for my DataProducer's resolver looks like this:

```
/**
* Determines the geo-detected country code
*
* @param \Drupal\Core\Cache\RefinableCacheableDependencyInterface $metadata
* @throws \Exception
*/
public function resolve(RefinableCacheableDependencyInterface $metadata) {

//same behavior with or without any cache tags
$metadata->addCacheTags(["geocountry"]);
//cache contexts automatically has one entry (user.permissions)
$metadata->mergeCacheMaxAge(0);
$metadata_of_the_metadata = [
"tags"=>$metadata->getCacheTags(),
"contexts"=>$metadata->getCacheContexts(),
"age"=>$metadata->getCacheMaxAge(),
"example_to_change_between_calls"=>"Test2"
];

return print_r($metadata_of_the_metadata,true);

}
```

The response I get back does not change when I change the value of `example_to_change_between_calls`

```
{
"data": {
"detectedCountryCode": "Array
(
[tags] => Array
(
[0] => geocountry
)

[contexts] => Array
(
[0] => user.permissions
)

[age] => 0
[example_to_change_between_calls] => Test1
)
"
}
}
```

If I were to comment out the addCacheTags() function, the result would update on the next query, but that result would still cache for future queries, so it seems some kind of cache verification is taking place, but it doesn't appear to be related to max age at all - I need a way to completely disable caching on this and other fields, preferably without having two separate schemas/endpoints.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.