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