Skip to content

Commit 18396ff

Browse files
Document updates in README
1 parent 64977fb commit 18396ff

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

README.md

+42-1
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,55 @@ const graphQLOptions = {
2626
playgroundEndpoint: '/___graphql', // ?String
2727
forwardUnmatchedRequestsToOrigin: false, // Boolean
2828
debug: false, // Boolean
29+
cors: true, // Boolean or Object to further configure
30+
kvCache: false // Boolean
2931
}
3032
```
3133

34+
### Endpoints
35+
3236
Make requests to your GraphQL server at the `baseEndpoint` (e.g. `graphql-on-workers.signalnerve.com/`) and, if configured, try GraphQL queries at the `playgroundEndpoint` (e.g. `graphql-on-workers.signalnerve.com/___graphql`).
3337

38+
### Origin forwarding
39+
3440
If you run your GraphQL server on a domain already registered with Cloudflare, you may want to pass any unmatched requests from inside your Workers script to your origin: in that case, set `forwardUnmatchedRequestToOrigin` to true (if you're running a GraphQL server on a [Workers.dev](https://workers.dev) subdomain, the default of `false` is fine).
3541

36-
Finally, while configuring your server, you may want to set the `debug` flag to `true`, to allow script errors to be returned in your browser. This can be useful for debugging any errors while setting up your GraphQL server.
42+
### Debugging
43+
44+
While configuring your server, you may want to set the `debug` flag to `true`, to return script errors in your browser. This can be useful for debugging any errors while setting up your GraphQL server, but should be disabled on a production server.
45+
46+
### CORS
47+
48+
By default, the `cors` option allows cross-origin requests to the server from any origin. You may wish to configure it to whitelist specific origins, methods, or headers. To do this, change the `cors` option to an object:
49+
50+
```js
51+
const graphQLOptions = {
52+
// ... other options ...
53+
54+
cors: {
55+
allowCredentials: 'true',
56+
allowHeaders: 'Content-type',
57+
allowOrigin: '*',
58+
allowMethods: 'GET, POST, PUT',
59+
}
60+
}
61+
```
62+
63+
Note that by default, any field that you _don't_ pass here (e.g. `allowMethods`) will fallback to the default value. See `utils/setCors.js` for the default values for these fields.
64+
65+
### REST caching
66+
67+
Version 1.1.0 of this project includes support for caching external requests made via instances of [`RESTDataSource`](https://www.apollographql.com/docs/apollo-server/features/data-sources/), using KV. To use caching in your project, [create a new KV namespace](https://workers.cloudflare.com/docs/reference/storage/writing-data), and in `wrangler.toml`, configure your namespace, calling it `WORKERS_GRAPHQL_CACHE`:
68+
69+
```toml
70+
# wrangler.toml
71+
72+
[[kv-namespaces]]
73+
binding = "WORKERS_GRAPHQL_CACHE"
74+
id = "$myId"
75+
```
76+
77+
With a configured KV namespace set up, you can opt-in to KV caching by changing the `kvCache` config value in `graphQLOptions` (in `index.js`) to `true`.
3778

3879
## License
3980

0 commit comments

Comments
 (0)