In magento 2.4.5 the env.php automatically inject the 'cache' => ['graphql' => ['id_salt' => 'xxxx']] Can anyone help to solve the issue or to disable this setting .
2 Answers
Open the following file: vendor/magento/module-graph-ql-cache/Model/CacheId/CacheIdCalculator.php
The following method generate this:
/**
* Gets the existing salt from the environment config or creates one if it hasn't been set yet
*
* @return string
* @throws Exception
*/
private function getSalt(): string
{
$salt = $this->deploymentConfig->get(self::SALT_CONFIG_PATH);
if ($salt) {
return $salt;
}
$salt = $this->random->getRandomString(ConfigOptionsListConstants::STORE_KEY_RANDOM_STRING_SIZE);
$config = new ConfigData(ConfigFilePool::APP_ENV);
$config->set(self::SALT_CONFIG_PATH, $salt);
$this->envWriter->saveConfig([$config->getFileKey() => $config->getData()], false, null, [], true);
return $salt;
}
So overwrite this class and remove $salt = $this->getSalt(); from public function getCacheId(): ?string method.
If you don't have a cache entry in your env.php array, Magento will break when the GraphQL module decides to add a salt entry within the cache key. The moment ['cache']
exists, Magento also expects ['cache']['frontend']
to exist too. See this GitHub issue for more info: https://github.com/magento/magento2/issues/35861
Removing the whole cache entry where the GraphQL was generated and stored will fix things, but then the issue will come back when Magento decides to generate the salt again. For a longer term fix, add an empty value for ['cache']['frontend']
either next to the generated GraphQL salt, or next to it, not important which:
'cache' => [
'frontend' => [],
],
or
'cache' => [
'frontend' => [],
'graphql' => [
'id_salt' => 'ABC123'
]
],
It's fair to assume that you're here because you didn't already have a value against ['cache']['frontend']
but if you did, you've hit a separate issue.