Skip to content

Commit a44593c

Browse files
authored
Allow to set custom cache key through options
1 parent 3e579e0 commit a44593c

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/cache.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ function cache(func, options) {
77
if (!context.resolverCache) {
88
throw new Error('Missing resolverCache property on the Graphql context.');
99
}
10+
11+
const key = options.key
12+
? options.key(root, args, context)
13+
: `${hash(func)}:${hash(toSafeObject(root))}:${hash(toSafeObject(args))}`;
1014

11-
const key = `${hash(func)}:${hash(toSafeObject(root))}:${hash(toSafeObject(args))}`;
1215
const executeAndCache = () =>
1316
Promise.resolve(func(root, args, context)).then((value) => {
1417
context.resolverCache.set(key, value, options);

0 commit comments

Comments
 (0)