Query dynamic cache key computation (#12814)

In this PR:
- add query hashKey to ObjectMetadataItems query graphql cache to avoid
caching outdated queries
- improve performance by removing ResolveField at FieldLevel and adding
this at resolver level
This commit is contained in:
Charles Bochet
2025-06-24 14:04:00 +02:00
committed by GitHub
parent 48347095d2
commit 4ac208cf1c
6 changed files with 44 additions and 57 deletions

View File

@ -1,3 +1,5 @@
import { createHash } from 'crypto';
import { isDefined } from 'class-validator';
import { Plugin } from 'graphql-yoga';
@ -20,8 +22,11 @@ export function useCachedMetadata(config: CacheMetadataPluginConfig): Plugin {
const localeCacheKey = isDefined(serverContext.req.headers['x-locale'])
? `:${locale}`
: '';
const queryHash = createHash('sha256')
.update(serverContext.req.body.query)
.digest('hex');
return `graphql:operations:${operationName}:${workspaceId}:${workspaceMetadataVersion}${localeCacheKey}`;
return `graphql:operations:${operationName}:${workspaceId}:${workspaceMetadataVersion}${localeCacheKey}:${queryHash}`;
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any