Skip to content

Commit 36b569b

Browse files
committed
Docs: Add basic installation instructions
1 parent 7beec12 commit 36b569b

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

README.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,39 @@ $ npm install graphql-resolver-cache --save
1616

1717
# Configuration
1818

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+
```
2052

2153
[npm-url]: https://npmjs.org/package/graphql-resolver-cache
2254
[npm-image]: http://img.shields.io/npm/v/graphql-resolver-cache.svg?style=flat-square

0 commit comments

Comments
 (0)