Skip to content

Commit 59eafd6

Browse files
authored
Fixing schema cache metadata. (#394)
1 parent 1b93ddd commit 59eafd6

21 files changed

Lines changed: 54 additions & 34 deletions

File tree

modules/graphql_content/src/Plugin/Deriver/DisplayedFieldDeriver.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Drupal\graphql_content\Plugin\Deriver;
44

55
use Drupal\Component\Plugin\Derivative\DeriverBase;
6+
use Drupal\Core\Cache\CacheableMetadata;
67
use Drupal\Core\Entity\ContentEntityTypeInterface;
78
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
89
use Drupal\Core\Entity\EntityFieldManagerInterface;
@@ -145,17 +146,22 @@ public function getDerivativeDefinitions($basePluginDefinition) {
145146
continue;
146147
}
147148

149+
$metadata = CacheableMetadata::createFromObject($display);
150+
if (isset($storageDefinition)) {
151+
$metadata->addCacheableDependency($storageDefinition);
152+
}
153+
148154
$this->derivatives[$typeId . '-' . $bundle . '-' . $field] = [
149155
'name' => StringHelper::propCase($field),
150156
'types' => [StringHelper::camelCase([$typeId, $bundle])],
151157
'entity_type' => $typeId,
152158
'bundle' => $bundle,
153159
'field' => $field,
154160
'virtual' => !isset($storageDefinition),
155-
'multi' => isset($storageDefinition) ? $storageDefinition->getCardinality() != 1 : FALSE,
156-
'cache_tags' => $display->getCacheTags(),
157-
'cache_contexts' => $display->getCacheContexts(),
158-
'cache_max_age' => $display->getCacheMaxAge(),
161+
'multi' => isset($storageDefinition) ? $storageDefinition->getCardinality() !== 1 : FALSE,
162+
'schema_cache_tags' => $metadata->getCacheTags(),
163+
'schema_cache_contexts' => $metadata->getCacheContexts(),
164+
'schema_cache_max_age' => $metadata->getCacheMaxAge(),
159165
] + $basePluginDefinition;
160166
}
161167
}

modules/graphql_content_mutation/src/Plugin/GraphQL/Mutations/CreateEntity.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* type = "EntityCrudOutput",
2020
* secure = true,
2121
* nullable = false,
22-
* cache_tags = {"entity_types", "entity_bundles"},
22+
* schema_cache_tags = {"entity_types", "entity_bundles"},
2323
* deriver = "Drupal\graphql_content_mutation\Plugin\Deriver\CreateEntityDeriver"
2424
* )
2525
*/

modules/graphql_content_mutation/src/Plugin/GraphQL/Mutations/DeleteEntity.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* "id" = "String"
2424
* },
2525
* nullable = false,
26-
* cache_tags = {"entity_types"},
26+
* schema_cache_tags = {"entity_types"},
2727
* deriver = "Drupal\graphql_content_mutation\Plugin\Deriver\DeleteEntityDeriver"
2828
* )
2929
*/

modules/graphql_content_mutation/src/Plugin/GraphQL/Mutations/UpdateEntity.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* type = "EntityCrudOutput",
2222
* secure = true,
2323
* nullable = false,
24-
* cache_tags = {"entity_types", "entity_bundles"},
24+
* schema_cache_tags = {"entity_types", "entity_bundles"},
2525
* deriver = "Drupal\graphql_content_mutation\Plugin\Deriver\UpdateEntityDeriver"
2626
* )
2727
*/

modules/graphql_core/src/Plugin/Deriver/Fields/EntityFieldDeriver.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ protected function getDerivativesFromPropertyDefinitions($entityTypeId, FieldSto
3030
'name' => EntityField::getId($fieldName),
3131
'multi' => $definition->isMultiple(),
3232
'field' => $fieldName,
33+
'schema_cache_tags' => array_merge($definition->getCacheTags(), ['entity_field_info']),
34+
'schema_cache_contexts' => $definition->getCacheContexts(),
35+
'schema_cache_max_age' => $definition->getCacheMaxAge(),
3336
];
3437

3538
$properties = $definition->getPropertyDefinitions();

modules/graphql_core/src/Plugin/Deriver/Fields/EntityFieldItemDeriver.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ protected function getDerivativesFromPropertyDefinitions($entityTypeId, FieldSto
1616
$fieldName = $definition->getName();
1717
$dataType = EntityFieldType::getId($entityTypeId, $fieldName);
1818

19-
$definitions = $definition->getPropertyDefinitions();
20-
21-
foreach ($definitions as $property => $definition) {
22-
if ($definition->getDataType() == 'map') {
19+
$propertyDefinitions = $definition->getPropertyDefinitions();
20+
foreach ($propertyDefinitions as $property => $propertyDefinition) {
21+
if ($propertyDefinition->getDataType() == 'map') {
2322
// TODO Is it possible to get the keys of a map (eg. the options array for link field) here?
2423
continue;
2524
}
@@ -28,8 +27,11 @@ protected function getDerivativesFromPropertyDefinitions($entityTypeId, FieldSto
2827
'name' => StringHelper::propCase($property),
2928
'property' => $property,
3029
'multi' => FALSE,
31-
'type' => $this->typeMapper->typedDataToGraphQLFieldType($definition),
30+
'type' => $this->typeMapper->typedDataToGraphQLFieldType($propertyDefinition),
3231
'types' => [$dataType],
32+
'schema_cache_tags' => array_merge($definition->getCacheTags(), ['entity_field_info']),
33+
'schema_cache_contexts' => $definition->getCacheContexts(),
34+
'schema_cache_max_age' => $definition->getCacheMaxAge(),
3335
] + $basePluginDefinition;
3436
}
3537
}

modules/graphql_core/src/Plugin/GraphQL/Interfaces/Entity/EntityType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* @GraphQLInterface(
1111
* id = "entity_type",
1212
* weight = -1,
13-
* cache_tags = {"entity_types"},
13+
* schema_cache_tags = {"entity_types"},
1414
* interfaces = {"Entity"},
1515
* deriver = "Drupal\graphql_core\Plugin\Deriver\Interfaces\EntityTypeDeriver"
1616
* )

modules/graphql_core/src/Plugin/GraphQL/Types/Entity/EntityBundle.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* @GraphQLType(
1313
* id = "entity_bundle",
1414
* weight = -1,
15-
* cache_tags = {"entity_types", "entity_bundles"},
15+
* schema_cache_tags = {"entity_types", "entity_bundles"},
1616
* deriver = "Drupal\graphql_core\Plugin\Deriver\Types\EntityBundleDeriver"
1717
* )
1818
*/

modules/graphql_entity_reference/src/Plugin/GraphQL/Fields/EntityReferenceField.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* id = "entity_reference",
1515
* secure = true,
1616
* field_formatter = "graphql_entity_reference",
17-
* cache_tags = {"entity_field_info"},
17+
* schema_cache_tags = {"entity_field_info"},
1818
* deriver = "Drupal\graphql_entity_reference\Plugin\Deriver\EntityReferenceFields"
1919
* )
2020
*/

modules/graphql_file/src/Plugin/GraphQL/Fields/FileField.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* secure = true,
1515
* field_formatter = "graphql_file",
1616
* type = "File",
17-
* cache_tags = {"entity_field_info"},
17+
* schema_cache_tags = {"entity_field_info"},
1818
* deriver = "Drupal\graphql_content\Plugin\Deriver\FieldFormatterDeriver"
1919
* )
2020
*/

0 commit comments

Comments
 (0)