Skip to content

Commit ae8c202

Browse files
Dylan Aubreyhwillson
Dylan Aubrey
andauthored
docs: add GraphQLBox client and server to docs (#1311)
* docs: add GraphQLBox client and server to docs * docs: update examples Co-authored-by: hwillson <hugh@octonary.com>
1 parent c3e8955 commit ae8c202

File tree

2 files changed

+122
-0
lines changed

2 files changed

+122
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
name: GraphQLBox client
3+
description: An extensible GraphQL client with modules for react, caching, request parsing, web workers, websockets and more...
4+
url: https://github.com/badbatch/graphql-box
5+
github: badbatch/graphql-box
6+
npm: "@graphql-box/client"
7+
---
8+
9+
The example below installs and initializes the GraphQLBox client with a persisted cache and debugging enabled.
10+
11+
```bash
12+
npm install @graphql-box/core @graphql-box/client @graphql-box/request-parser @graphql-box/cache-manager @graphql-box/debug-manager @graphql-box/fetch-manager @graphql-box/helpers @cachemap/core @cachemap/reaper @cachemap/indexed-db @cachemap/constants @cachemap/types
13+
```
14+
15+
```javascript
16+
import Cachemap from "@cachemap/core";
17+
import indexedDB from "@cachemap/indexed-db";
18+
import reaper from "@cachemap/reaper";
19+
import CacheManager from "@graphql-box/cache-manager";
20+
import Client from "@graphql-box/client";
21+
import DebugManager from "@graphql-box/debug-manager";
22+
import FetchManager from "@graphql-box/fetch-manager";
23+
import RequestParser from "@graphql-box/request-parser";
24+
import introspection from "./introspection-query";
25+
26+
const requestManager = new FetchManager({
27+
apiUrl: "/api/graphql",
28+
batchRequests: true,
29+
logUrl: "/log/graphql",
30+
});
31+
32+
const client = new Client({
33+
cacheManager: new CacheManager({
34+
cache: new Cachemap({
35+
name: "client-cache",
36+
reaper: reaper({ interval: 300000 }),
37+
store: indexedDB(/* configure */),
38+
}),
39+
cascadeCacheControl: true,
40+
typeCacheDirectives: {
41+
// Add any type specific cache control directives in the format:
42+
// TypeName: "public, max-age=3",
43+
},
44+
}),
45+
debugManager: new DebugManager({
46+
environment: "client",
47+
log: (message, data, logLevel) => {
48+
requestManager.log(message, data, logLevel);
49+
},
50+
name: "CLIENT",
51+
performance: self.performance,
52+
}),
53+
requestManager,
54+
requestParser: new RequestParser({ introspection }),
55+
});
56+
57+
// Meanwhile... somewhere else in your code
58+
59+
const { data, errors } = await client.request(queryOrMutation);
60+
```
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
name: GraphQLBox server
3+
description: An extensible GraphQL server with modules for caching, request parsing, debugging, subscriptions and more...
4+
url: https://github.com/badbatch/graphql-box
5+
github: badbatch/graphql-box
6+
npm: "@graphql-box/server"
7+
---
8+
9+
The example below installs and initializes the GraphQLBox server with a persisted cache and debugging enabled.
10+
11+
```bash
12+
npm install @graphql-box/core @graphql-box/server @graphql-box/client @graphql-box/request-parser @graphql-box/cache-manager @graphql-box/debug-manager @graphql-box/execute @graphql-box/helpers @cachemap/core @cachemap/reaper @cachemap/redis @cachemap/constants @cachemap/types
13+
```
14+
15+
```javascript
16+
import Cachemap from "@cachemap/core";
17+
import redis from "@cachemap/redis";
18+
import reaper from "@cachemap/reaper";
19+
import CacheManager from "@graphql-box/cache-manager";
20+
import Client from "@graphql-box/client";
21+
import DebugManager from "@graphql-box/debug-manager";
22+
import Execute from "@graphql-box/execute";
23+
import RequestParser from "@graphql-box/request-parser";
24+
import Server from "@graphql-box/server";
25+
import { makeExecutableSchema } from "@graphql-tools/schema";
26+
import { performance } from "perf_hooks";
27+
import { schemaResolvers, schemaTypeDefs } from "./schema";
28+
import logger from './logger';
29+
30+
const schema = makeExecutableSchema({ typeDefs: schemaTypeDefs, resolvers: schemaResolvers });
31+
32+
const server = new Server({
33+
client: new Client({
34+
cacheManager: new CacheManager({
35+
cache: new Cachemap({
36+
name: "server-cache",
37+
reaper: reaper({ interval: 300000 }),
38+
store: redis(/* configure */),
39+
}),
40+
cascadeCacheControl: true,
41+
typeCacheDirectives: {
42+
// Add any type specific cache control directives in the format:
43+
// TypeName: "public, max-age=3",
44+
},
45+
}),
46+
debugManager: new DebugManager({
47+
environment: "server",
48+
log: (...args) => {
49+
logger.log(...args);
50+
},
51+
name: "SERVER",
52+
performance,
53+
}),
54+
requestManager: new Execute({ schema }),
55+
requestParser: new RequestParser({ schema }),
56+
}),
57+
});
58+
59+
// Meanwhile... somewhere else in your code
60+
61+
app.use("api/graphql", graphqlServer.request());
62+
```

0 commit comments

Comments
 (0)