You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
cors:true, // Boolean or Object to further configure
30
+
kvCache:false// Boolean
29
31
}
30
32
```
31
33
34
+
### Endpoints
35
+
32
36
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`).
33
37
38
+
### Origin forwarding
39
+
34
40
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).
35
41
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
+
constgraphQLOptions= {
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`.
0 commit comments