File tree Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Original file line number Diff line number Diff line change @@ -2,13 +2,16 @@ const hash = require('object-hash');
2
2
3
3
const toSafeObject = obj => JSON . parse ( JSON . stringify ( obj || { } ) ) ;
4
4
5
- function cache ( func , options ) {
5
+ function cache ( func , options = { } ) {
6
6
return ( root , args , context ) => {
7
7
if ( ! context . resolverCache ) {
8
8
throw new Error ( 'Missing resolverCache property on the Graphql context.' ) ;
9
9
}
10
+
11
+ const key = options . key
12
+ ? options . key ( root , args , context )
13
+ : `${ hash ( func ) } :${ hash ( toSafeObject ( root ) ) } :${ hash ( toSafeObject ( args ) ) } ` ;
10
14
11
- const key = `${ hash ( func ) } :${ hash ( toSafeObject ( root ) ) } :${ hash ( toSafeObject ( args ) ) } ` ;
12
15
const executeAndCache = ( ) =>
13
16
Promise . resolve ( func ( root , args , context ) ) . then ( ( value ) => {
14
17
context . resolverCache . set ( key , value , options ) ;
You can’t perform that action at this time.
0 commit comments