File tree Expand file tree Collapse file tree 1 file changed +33
-1
lines changed Expand file tree Collapse file tree 1 file changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -16,7 +16,39 @@ $ npm install graphql-resolver-cache --save
16
16
17
17
# Configuration
18
18
19
- TODO
19
+ Add a cache to your Graphql middleware:
20
+
21
+ ```
22
+ import express from 'express';
23
+ import bodyParser from 'body-parser';
24
+ import { graphqlExpress } from 'apollo-server-express';
25
+ import { LruCache } from 'graphql-resolver-cache';
26
+
27
+ const myGraphQLSchema = // ... define or import your schema here!
28
+ const PORT = 3000;
29
+
30
+ const app = express();
31
+ const resolverCache = new LruCache();
32
+
33
+ // bodyParser is needed just for POST.
34
+ app.use('/graphql', bodyParser.json(), graphqlExpress({
35
+ schema: myGraphQLSchema,
36
+ context: { resolverCache }
37
+ }));
38
+
39
+ app.listen(PORT);
40
+ ```
41
+
42
+ Wrap your resolver in a cache function:
43
+
44
+ ```
45
+ import { withCache } from 'graphql-resolver-cache';
46
+ export default {
47
+ User: {
48
+ getFriends: withCache((root, args, context) => { /* logic */ }),
49
+ },
50
+ };
51
+ ```
20
52
21
53
[ npm-url ] : https://npmjs.org/package/graphql-resolver-cache
22
54
[ npm-image ] : http://img.shields.io/npm/v/graphql-resolver-cache.svg?style=flat-square
You can’t perform that action at this time.
0 commit comments