agrosner
06/19/2024, 7:31 PMCacheKeyGenerator
to formulate caching keys for complex entities that have multiple forms of identity.
• id
- can be an entity with a fully formed id based on @key
field of the entity itself
type SomeEntity @key(fields: "id") {
id: ID!
}
• if no id, then use another secondaryId
field in combination with the complex entity, call it foo
type SomeEntity @key(fields: "secondaryId foo { id }") {
secondaryId: Int
foo: Foo
}
• if foo
not found, then use secondaryId
only if found.
• if none found, fallback on TypePolicyCacheKeyGenerator
now the main issue is that there is no way to enforce developers follow this format and query for those fields if available to ensure its properly cached.
if we query for something that may have an id
or second option with combination key, but only for the title and secondaryId, but not the nested id that we need:
theEntity {
title
secondaryId
}
then our entity that gets normalized forgoes uniqueness on the foo
level, leading to overwriting and sharing of the same entity, even if unintentionally.agrosner
06/19/2024, 7:33 PMwasyl
06/19/2024, 8:19 PMthe main issue is that there is no way to enforce developers follow this format and query for those fields if available to ensure its properly cached.the latter we're doing with graphql-eslint and its
require-selections
rule I think, + you can write your own if you have custom things you want to enforce
https://the-guild.dev/graphql/eslint/docs
https://github.com/dimaMachina/graphql-eslint/blob/master/packages/plugin/src/rules/require-selections.tswasyl
06/19/2024, 8:23 PMrequire-id-when-available
rule (you can configure required fields) but I don't see it in the sources for some reason. Maybe the name has changedagrosner
06/19/2024, 9:19 PMagrosner
06/19/2024, 9:21 PMagrosner
06/19/2024, 9:25 PM