diff --git a/src/Entity/Server.php b/src/Entity/Server.php index 78511c4da..0f1213d7f 100644 --- a/src/Entity/Server.php +++ b/src/Entity/Server.php @@ -237,6 +237,7 @@ public function configuration() { /** @var \Drupal\graphql\Plugin\SchemaPluginInterface $plugin */ $plugin = $manager->createInstance($schema); + $plugin->setServerId($this->name); if ($plugin instanceof ConfigurableInterface && $config = $this->get('schema_configuration')) { $plugin->setConfiguration($config[$schema] ?? []); } diff --git a/src/GraphQL/Execution/Executor.php b/src/GraphQL/Execution/Executor.php index ec8a54101..64f3073ff 100644 --- a/src/GraphQL/Execution/Executor.php +++ b/src/GraphQL/Execution/Executor.php @@ -351,6 +351,7 @@ protected function cachePrefix() { ksort($extensions); $hash = hash('sha256', serialize([ + 'server' => $this->context->getServer()->name, 'query' => DocumentSerializer::serializeDocument($this->document), 'variables' => $variables, 'extensions' => $extensions, diff --git a/src/Plugin/GraphQL/Schema/SdlSchemaPluginBase.php b/src/Plugin/GraphQL/Schema/SdlSchemaPluginBase.php index fecf60e46..76e32ca7c 100644 --- a/src/Plugin/GraphQL/Schema/SdlSchemaPluginBase.php +++ b/src/Plugin/GraphQL/Schema/SdlSchemaPluginBase.php @@ -44,6 +44,13 @@ abstract class SdlSchemaPluginBase extends PluginBase implements SchemaPluginInt */ protected $inDevelopment; + /** + * The ID of the server using this plugin. + * + * @var string + */ + protected $serverId; + /** * The schema extension plugin manager. * @@ -111,6 +118,13 @@ public function __construct( $this->moduleHandler = $moduleHandler; } + /** + * {@inheritdoc} + */ + public function setServerId(string $serverId): void { + $this->serverId = $serverId; + } + /** * {@inheritdoc} * @@ -179,7 +193,7 @@ protected function getExtensions() { */ protected function getSchemaDocument(array $extensions = []) { // Only use caching of the parsed document if we aren't in development mode. - $cid = "schema:{$this->getPluginId()}"; + $cid = "server:{$this->serverId}:schema:{$this->getPluginId()}"; if (empty($this->inDevelopment) && $cache = $this->astCache->get($cid)) { return $cache->data; } @@ -209,7 +223,7 @@ protected function getSchemaDocument(array $extensions = []) { */ private function getFullSchemaDocument(Schema $schema, array $extensions): ?DocumentNode { // Only use caching of the parsed document if we aren't in development mode. - $cid = "full:{$this->getPluginId()}"; + $cid = "server:{$this->serverId}:full:{$this->getPluginId()}"; if (empty($this->inDevelopment) && $cache = $this->astCache->get($cid)) { return $cache->data; } diff --git a/src/Plugin/SchemaPluginInterface.php b/src/Plugin/SchemaPluginInterface.php index ab8dbc33a..e1e6e5f03 100644 --- a/src/Plugin/SchemaPluginInterface.php +++ b/src/Plugin/SchemaPluginInterface.php @@ -14,6 +14,14 @@ */ interface SchemaPluginInterface extends PluginInspectionInterface, DerivativeInspectionInterface { + /** + * Set the serverID, required for cache id generation. + * + * @param string $serverId + * The machine name of the server using this plugin. + */ + public function setServerId(string $serverId): void; + /** * Retrieves the schema. *