grafserv 0.0.1-0.2 → 0.0.1-0.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/CHANGELOG.md +220 -0
  2. package/README.md +248 -3
  3. package/dist/accept.d.ts +8 -0
  4. package/dist/accept.d.ts.map +1 -0
  5. package/dist/accept.js +419 -0
  6. package/dist/accept.js.map +1 -0
  7. package/dist/core/base.d.ts +38 -0
  8. package/dist/core/base.d.ts.map +1 -0
  9. package/dist/core/base.js +440 -0
  10. package/dist/core/base.js.map +1 -0
  11. package/dist/index.d.ts +2 -2
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +3 -3
  14. package/dist/index.js.map +1 -1
  15. package/dist/interfaces.d.ts +176 -23
  16. package/dist/interfaces.d.ts.map +1 -1
  17. package/dist/interfaces.js +2 -0
  18. package/dist/interfaces.js.map +1 -1
  19. package/dist/mapIterator.d.ts +2 -0
  20. package/dist/mapIterator.d.ts.map +1 -0
  21. package/dist/mapIterator.js +65 -0
  22. package/dist/mapIterator.js.map +1 -0
  23. package/dist/middleware/graphiql.d.ts +3 -3
  24. package/dist/middleware/graphiql.d.ts.map +1 -1
  25. package/dist/middleware/graphiql.js +14 -4
  26. package/dist/middleware/graphiql.js.map +1 -1
  27. package/dist/middleware/graphql.d.ts +8 -3
  28. package/dist/middleware/graphql.d.ts.map +1 -1
  29. package/dist/middleware/graphql.js +325 -23
  30. package/dist/middleware/graphql.js.map +1 -1
  31. package/dist/options.d.ts +23 -0
  32. package/dist/options.d.ts.map +1 -0
  33. package/dist/options.js +114 -0
  34. package/dist/options.js.map +1 -0
  35. package/dist/servers/express/v4/index.d.ts +24 -0
  36. package/dist/servers/express/v4/index.d.ts.map +1 -0
  37. package/dist/servers/express/v4/index.js +62 -0
  38. package/dist/servers/express/v4/index.js.map +1 -0
  39. package/dist/servers/fastify/v4/index.d.ts +21 -0
  40. package/dist/servers/fastify/v4/index.d.ts.map +1 -0
  41. package/dist/servers/fastify/v4/index.js +198 -0
  42. package/dist/servers/fastify/v4/index.js.map +1 -0
  43. package/dist/servers/koa/v2/index.d.ts +25 -0
  44. package/dist/servers/koa/v2/index.d.ts.map +1 -0
  45. package/dist/servers/koa/v2/index.js +137 -0
  46. package/dist/servers/koa/v2/index.js.map +1 -0
  47. package/dist/servers/node/index.d.ts +32 -0
  48. package/dist/servers/node/index.d.ts.map +1 -0
  49. package/dist/servers/node/index.js +269 -0
  50. package/dist/servers/node/index.js.map +1 -0
  51. package/dist/utils.d.ts +19 -0
  52. package/dist/utils.d.ts.map +1 -0
  53. package/dist/utils.js +145 -0
  54. package/dist/utils.js.map +1 -0
  55. package/package.json +42 -8
  56. package/dist/middleware/index.d.ts +0 -12
  57. package/dist/middleware/index.d.ts.map +0 -1
  58. package/dist/middleware/index.js +0 -431
  59. package/dist/middleware/index.js.map +0 -1
  60. package/dist/middleware/interfaces.d.ts +0 -40
  61. package/dist/middleware/interfaces.d.ts.map +0 -1
  62. package/dist/middleware/interfaces.js +0 -3
  63. package/dist/middleware/interfaces.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,225 @@
1
1
  # grafserv
2
2
 
3
+ ## 0.0.1-0.21
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+ [[`397e8bb40`](https://github.com/benjie/postgraphile-private/commit/397e8bb40fe3783995172356a39ab7cb33e3bd36)]:
9
+ - grafast@0.0.1-0.19
10
+
11
+ ## 0.0.1-0.20
12
+
13
+ ### Patch Changes
14
+
15
+ - Updated dependencies
16
+ [[`4c2b7d1ca`](https://github.com/benjie/postgraphile-private/commit/4c2b7d1ca1afbda1e47da22c346cc3b03d01b7f0),
17
+ [`c8a56cdc8`](https://github.com/benjie/postgraphile-private/commit/c8a56cdc83390e5735beb9b90f004e7975cab28c)]:
18
+ - grafast@0.0.1-0.18
19
+
20
+ ## 0.0.1-0.19
21
+
22
+ ### Patch Changes
23
+
24
+ - Updated dependencies [[`f48860d4f`](undefined)]:
25
+ - grafast@0.0.1-0.17
26
+
27
+ ## 0.0.1-0.18
28
+
29
+ ### Patch Changes
30
+
31
+ - Updated dependencies
32
+ [[`df89aba52`](https://github.com/benjie/postgraphile-private/commit/df89aba524270e52f82987fcc4ab5d78ce180fc5)]:
33
+ - grafast@0.0.1-0.16
34
+
35
+ ## 0.0.1-0.17
36
+
37
+ ### Patch Changes
38
+
39
+ - [#210](https://github.com/benjie/postgraphile-private/pull/210)
40
+ [`b523118fe`](https://github.com/benjie/postgraphile-private/commit/b523118fe6217c027363fea91252a3a1764e17df)
41
+ Thanks [@benjie](https://github.com/benjie)! - Replace BaseGraphQLContext with
42
+ Grafast.Context throughout.
43
+
44
+ - [#210](https://github.com/benjie/postgraphile-private/pull/210)
45
+ [`461c03b72`](https://github.com/benjie/postgraphile-private/commit/461c03b72477821ec26cbf703011542e453d083c)
46
+ Thanks [@benjie](https://github.com/benjie)! - Make servers releasable where
47
+ possible.
48
+
49
+ - Updated dependencies
50
+ [[`b523118fe`](https://github.com/benjie/postgraphile-private/commit/b523118fe6217c027363fea91252a3a1764e17df)]:
51
+ - grafast@0.0.1-0.15
52
+
53
+ ## 0.0.1-0.16
54
+
55
+ ### Patch Changes
56
+
57
+ - [#207](https://github.com/benjie/postgraphile-private/pull/207)
58
+ [`c850dd4ec`](https://github.com/benjie/postgraphile-private/commit/c850dd4ec0e42e37122f5bca55a079b53bfd895e)
59
+ Thanks [@benjie](https://github.com/benjie)! - Rename 'preset.server' to
60
+ 'preset.grafserv'.
61
+
62
+ - [#207](https://github.com/benjie/postgraphile-private/pull/207)
63
+ [`afa0ea5f6`](https://github.com/benjie/postgraphile-private/commit/afa0ea5f6c508d9a0ba5946ab153b13ddbd274a0)
64
+ Thanks [@benjie](https://github.com/benjie)! - Fix bug in subscriptions where
65
+ termination of underlying stream wouldn't terminate the subscription.
66
+
67
+ - [#206](https://github.com/benjie/postgraphile-private/pull/206)
68
+ [`851b78ef2`](https://github.com/benjie/postgraphile-private/commit/851b78ef20d430164507ec9b3f41a5a0b8a18ed7)
69
+ Thanks [@benjie](https://github.com/benjie)! - Grafserv now masks untrusted
70
+ errors by default; trusted errors are constructed via GraphQL's GraphQLError
71
+ or Grafast's SafeError.
72
+ - Updated dependencies
73
+ [[`d76043453`](https://github.com/benjie/postgraphile-private/commit/d7604345362c58bf7eb43ef1ac1795a2ac22ae79),
74
+ [`afa0ea5f6`](https://github.com/benjie/postgraphile-private/commit/afa0ea5f6c508d9a0ba5946ab153b13ddbd274a0),
75
+ [`851b78ef2`](https://github.com/benjie/postgraphile-private/commit/851b78ef20d430164507ec9b3f41a5a0b8a18ed7),
76
+ [`384b3594f`](https://github.com/benjie/postgraphile-private/commit/384b3594f543d113650c1b6b02b276360dd2d15f)]:
77
+ - grafast@0.0.1-0.14
78
+
79
+ ## 0.0.1-0.15
80
+
81
+ ### Patch Changes
82
+
83
+ - Updated dependencies [[`e5b664b6f`](undefined)]:
84
+ - grafast@0.0.1-0.13
85
+
86
+ ## 0.0.1-0.14
87
+
88
+ ### Patch Changes
89
+
90
+ - [#200](https://github.com/benjie/postgraphile-private/pull/200)
91
+ [`1e5671cdb`](https://github.com/benjie/postgraphile-private/commit/1e5671cdbbf9f4600b74c43eaa7e33b7bfd75fb9)
92
+ Thanks [@benjie](https://github.com/benjie)! - Add support for websocket
93
+ GraphQL subscriptions (via graphql-ws) to grafserv and PostGraphile (currently
94
+ supporting Node, Express, Koa and Fastify)
95
+
96
+ - [#200](https://github.com/benjie/postgraphile-private/pull/200)
97
+ [`5b634a78e`](https://github.com/benjie/postgraphile-private/commit/5b634a78e51816071447aceb1edfb813d77d563b)
98
+ Thanks [@benjie](https://github.com/benjie)! - Standardize on `serv.addTo`
99
+ interface, even for Node
100
+
101
+ - Updated dependencies
102
+ [[`4f5d5bec7`](https://github.com/benjie/postgraphile-private/commit/4f5d5bec72f949b17b39cd07acc848ce7a8bfa36),
103
+ [`e11698473`](https://github.com/benjie/postgraphile-private/commit/e1169847303790570bfafa07eb25d8fce53a0391),
104
+ [`25f5a6cbf`](https://github.com/benjie/postgraphile-private/commit/25f5a6cbff6cd5a94ebc4f411f7fa89c209fc383)]:
105
+ - grafast@0.0.1-0.12
106
+ - ruru@2.0.0-0.10
107
+
108
+ ## 0.0.1-0.13
109
+
110
+ ### Patch Changes
111
+
112
+ - [`0ab95d0b1`](undefined) - Update sponsors.
113
+
114
+ - [#195](https://github.com/benjie/postgraphile-private/pull/195)
115
+ [`752ec9c51`](https://github.com/benjie/postgraphile-private/commit/752ec9c516add7c4617b426e97eccd1d4e5b7833)
116
+ Thanks [@benjie](https://github.com/benjie)! - Fix handling of HTTP errors and
117
+ allow for 204 status code responses. Add CORS hack to enable graphql-http
118
+ auditing.
119
+ - Updated dependencies [[`0ab95d0b1`](undefined),
120
+ [`4783bdd7c`](https://github.com/benjie/postgraphile-private/commit/4783bdd7cc28ac8b497fdd4d6f1024d80cb432ef),
121
+ [`652cf1073`](https://github.com/benjie/postgraphile-private/commit/652cf107316ea5832f69c6a55574632187f5c876)]:
122
+ - grafast@0.0.1-0.11
123
+ - graphile-config@0.0.1-0.5
124
+ - ruru@2.0.0-0.9
125
+
126
+ ## 0.0.1-0.12
127
+
128
+ ### Patch Changes
129
+
130
+ - Updated dependencies
131
+ [[`842f6ccbb`](https://github.com/benjie/postgraphile-private/commit/842f6ccbb3c9bd0c101c4f4df31c5ed1aea9b2ab)]:
132
+ - graphile-config@0.0.1-0.4
133
+ - grafast@0.0.1-0.10
134
+ - ruru@2.0.0-0.8
135
+
136
+ ## 0.0.1-0.11
137
+
138
+ ### Patch Changes
139
+
140
+ - [#176](https://github.com/benjie/postgraphile-private/pull/176)
141
+ [`11d6be65e`](https://github.com/benjie/postgraphile-private/commit/11d6be65e0da489f8ab3e3a8b8db145f8b2147ad)
142
+ Thanks [@benjie](https://github.com/benjie)! - Fix issue with plugin
143
+ versioning. Add more TSDoc comments. New getTerminalWidth() helper.
144
+ - Updated dependencies
145
+ [[`19e2961de`](https://github.com/benjie/postgraphile-private/commit/19e2961de67dc0b9601799bba256e4c4a23cc0cb),
146
+ [`11d6be65e`](https://github.com/benjie/postgraphile-private/commit/11d6be65e0da489f8ab3e3a8b8db145f8b2147ad)]:
147
+ - graphile-config@0.0.1-0.3
148
+ - grafast@0.0.1-0.9
149
+ - ruru@2.0.0-0.7
150
+
151
+ ## 0.0.1-0.10
152
+
153
+ ### Patch Changes
154
+
155
+ - Updated dependencies
156
+ [[`208166269`](https://github.com/benjie/postgraphile-private/commit/208166269177d6e278b056e1c77d26a2d8f59f49)]:
157
+ - grafast@0.0.1-0.8
158
+
159
+ ## 0.0.1-0.9
160
+
161
+ ### Patch Changes
162
+
163
+ - Updated dependencies [[`a40fa6966`](undefined),
164
+ [`8f04af08d`](https://github.com/benjie/postgraphile-private/commit/8f04af08da68baf7b2b4d508eac0d2a57064da7b)]:
165
+ - ruru@2.0.0-0.6
166
+ - grafast@0.0.1-0.7
167
+
168
+ ## 0.0.1-0.8
169
+
170
+ ### Patch Changes
171
+
172
+ - [`c4213e91d`](undefined) - Add pgl.getResolvedPreset() API; fix Ruru
173
+ respecting graphqlPath setting; replace 'instance' with 'pgl'/'serv' as
174
+ appropriate; forbid subscriptions on GET
175
+
176
+ ## 0.0.1-0.7
177
+
178
+ ### Patch Changes
179
+
180
+ - [`9b296ba54`](undefined) - More secure, more compatible, and lots of fixes
181
+ across the monorepo
182
+
183
+ - Updated dependencies [[`9b296ba54`](undefined)]:
184
+ - grafast@0.0.1-0.6
185
+ - ruru@2.0.0-0.5
186
+ - graphile-config@0.0.1-0.2
187
+
188
+ ## 0.0.1-0.6
189
+
190
+ ### Patch Changes
191
+
192
+ - Updated dependencies [[`cd37fd02a`](undefined)]:
193
+ - grafast@0.0.1-0.5
194
+
195
+ ## 0.0.1-0.5
196
+
197
+ ### Patch Changes
198
+
199
+ - [`768f32681`](undefined) - Fix peerDependencies ranges
200
+
201
+ - Updated dependencies [[`768f32681`](undefined)]:
202
+ - grafast@0.0.1-0.4
203
+ - ruru@2.0.0-0.4
204
+
205
+ ## 0.0.1-0.4
206
+
207
+ ### Patch Changes
208
+
209
+ - Updated dependencies [[`0983df3f6`](undefined)]:
210
+ - ruru@2.0.0-0.3
211
+
212
+ ## 0.0.1-0.3
213
+
214
+ ### Patch Changes
215
+
216
+ - [`d11c1911c`](undefined) - Fix dependencies
217
+
218
+ - Updated dependencies [[`d11c1911c`](undefined)]:
219
+ - grafast@0.0.1-0.3
220
+ - ruru@2.0.0-0.2
221
+ - graphile-config@0.0.1-0.1
222
+
3
223
  ## 0.0.1-0.2
4
224
 
5
225
  ### Patch Changes
package/README.md CHANGED
@@ -26,17 +26,262 @@ And please give some love to our featured sponsors 🤩:
26
26
  <table><tr>
27
27
  <td align="center"><a href="https://surge.io/"><img src="https://graphile.org/images/sponsors/surge.png" width="90" height="90" alt="Surge" /><br />Surge</a> *</td>
28
28
  <td align="center"><a href="https://www.netflix.com/"><img src="https://graphile.org/images/sponsors/Netflix.png" width="90" height="90" alt="Netflix" /><br />Netflix</a> *</td>
29
- <td align="center"><a href="https://qwick.com/"><img src="https://graphile.org/images/sponsors/qwick.png" width="90" height="90" alt="Qwick" /><br />Qwick</a> *</td>
30
29
  <td align="center"><a href="https://www.the-guild.dev/"><img src="https://graphile.org/images/sponsors/theguild.png" width="90" height="90" alt="The Guild" /><br />The Guild</a> *</td>
30
+ <td align="center"><a href="https://qwick.com/"><img src="https://graphile.org/images/sponsors/qwick.png" width="90" height="90" alt="Qwick" /><br />Qwick</a> *</td>
31
31
  </tr><tr>
32
32
  <td align="center"><a href="http://chads.website"><img src="https://graphile.org/images/sponsors/chadf.png" width="90" height="90" alt="Chad Furman" /><br />Chad Furman</a> *</td>
33
- <td align="center"><a href="https://www.fanatics.com/"><img src="https://graphile.org/images/sponsors/fanatics.png" width="90" height="90" alt="Fanatics" /><br />Fanatics</a> *</td>
34
33
  <td align="center"><a href="https://dovetailapp.com/"><img src="https://graphile.org/images/sponsors/dovetail.png" width="90" height="90" alt="Dovetail" /><br />Dovetail</a> *</td>
35
34
  <td align="center"><a href="https://www.enzuzo.com/"><img src="https://graphile.org/images/sponsors/enzuzo.png" width="90" height="90" alt="Enzuzo" /><br />Enzuzo</a> *</td>
36
- </tr><tr>
37
35
  <td align="center"><a href="https://stellate.co/"><img src="https://graphile.org/images/sponsors/Stellate.png" width="90" height="90" alt="Stellate" /><br />Stellate</a> *</td>
38
36
  </tr></table>
39
37
 
40
38
  <em>\* Sponsors the entire Graphile suite</em>
41
39
 
42
40
  <!-- SPONSORS_END -->
41
+
42
+ ## Usage
43
+
44
+ Grafserv supports many different servers, and because each server is different
45
+ each has their own entrypoint, e.g. `grafserv/node` for the Node.js HTTP server
46
+ or `grafserv/express/v4` for Express v4. Generally you import the `grafserv`
47
+ function from the relevant entrypoint for your server of choice and then create
48
+ an instance:
49
+
50
+ ```js
51
+ const serv = grafserv({ schema, preset });
52
+ ```
53
+
54
+ `grafserv` is passed the GraphQL schema to use (if it's available, otherwise
55
+ passing either null or a promise is also acceptable) and a `graphql-config`
56
+ preset - i.e. your configuration.
57
+
58
+ Calling `grafserv` will return an instance; this instance will have a number of
59
+ helpers on it, including helpers specific to integrating it with your framework
60
+ of choice. For servers that operate on a middleware basis this is typically
61
+ `serv.addTo(app)` (which allows registering multiple route handlers), though
62
+ different servers may have different APIs, such as `serv.createGraphQLHandler()`
63
+ for Lambda and Next.js.
64
+
65
+ Note: There is little value in Grafserv reimplementing every non-GraphQL concern
66
+ your server may have, so instead it leans on the ecosystem of your chosen server
67
+ to handle things like compression, rate limits, sessions, cookies, etc. For
68
+ example, to compress your responses you'd need to use a module like
69
+ [`compression`](https://expressjs.com/en/resources/middleware/compression.html)
70
+ for Express, [`koa-compress`](https://www.npmjs.com/package/koa-compress) for
71
+ Koa, or [`@fastify/compress`](https://www.npmjs.com/package/@fastify/compress)
72
+ for Fastify.
73
+
74
+ ### serv.release()
75
+
76
+ Releases any resources created by the instance; no further requests should be
77
+ handled (though currently active requests will be allowed to complete).
78
+
79
+ // TODO: consider terminating subscriptions or other long-lived things.
80
+
81
+ ### serv.onRelease(cb)
82
+
83
+ Adds `cb` to the list of callbacks to be called when the server is released;
84
+ useful for releasing resources you created only for the server. Callbacks will
85
+ be called in reverse order that they were added.
86
+
87
+ ### serv.setSchema(newSchema)
88
+
89
+ Replaces the schema to use for future requests (currently active requests are
90
+ unaffected) - this is primarily used for "watch" mode.
91
+
92
+ ### serv.setPreset(newPreset)
93
+
94
+ Replaces the config to use for future requests (currently active requests are
95
+ unaffected) - this is primarily used for "watch" mode. Note that certain
96
+ configuration changes might not be reflected by certain servers until a restart.
97
+
98
+ ### serv.getSchema()
99
+
100
+ Returns either the GraphQL schema that is currently in use, or a promise to the
101
+ same.
102
+
103
+ ### serv.getPreset()
104
+
105
+ Returns the resolved `graphile-config` preset that is currently in use.
106
+
107
+ ## Servers
108
+
109
+ ### Node HTTP server
110
+
111
+ ```js
112
+ import { createServer } from "node:http";
113
+ import { grafserv } from "grafserv/node";
114
+ import preset from "./graphile.config.mjs";
115
+ import schema from "./schema.mjs";
116
+
117
+ // Create a Node HTTP server
118
+ const server = createServer();
119
+ server.on("error", (e) => {
120
+ console.error(e);
121
+ });
122
+
123
+ // Create a Grafserv instance
124
+ const serv = grafserv({ schema, preset });
125
+
126
+ // Mount the request handler into a new HTTP server, and register websockets if
127
+ // desired
128
+ serv.addTo(server).catch((e) => {
129
+ console.error(e);
130
+ process.exit(1);
131
+ });
132
+
133
+ // Start the Node server
134
+ server.listen(preset.grafserv.port ?? 5678);
135
+ ```
136
+
137
+ ### Express V4
138
+
139
+ ```js
140
+ import { createServer } from "node:http";
141
+ import express from "express";
142
+ import { grafserv } from "grafserv/express/v4";
143
+ import preset from "./graphile.config.mjs";
144
+ import schema from "./schema.mjs";
145
+
146
+ // Create an express app
147
+ const app = express();
148
+ // (Add any Express middleware you want here.)
149
+
150
+ // Create a Node HTTP server, mounting Express into it
151
+ const server = createServer(app);
152
+ server.on("error", (e) => {
153
+ console.error(e);
154
+ });
155
+
156
+ // Create a Grafserv instance
157
+ const serv = grafserv({ schema, preset });
158
+
159
+ // Add the Grafserv instance's route handlers to the Express app, and register
160
+ // websockets if desired
161
+ serv.addTo(app, server).catch((e) => {
162
+ console.error(e);
163
+ process.exit(1);
164
+ });
165
+
166
+ // Start the Express server
167
+ server.listen(preset.grafserv.port ?? 5678);
168
+ ```
169
+
170
+ ### Koa V2
171
+
172
+ ```js
173
+ import { createServer } from "node:http";
174
+ import Koa from "koa";
175
+ import { grafserv } from "grafserv/koa/v2";
176
+ import preset from "./graphile.config.mjs";
177
+ import schema from "./schema.mjs";
178
+
179
+ // Create a Koa app
180
+ const app = new Koa();
181
+ // (Add any Koa middleware you want here.)
182
+
183
+ // Create a Node HTTP server, mounting Koa into it
184
+ const server = createServer(app);
185
+ server.on("error", (e) => {
186
+ console.error(e);
187
+ });
188
+
189
+ // Create a Grafserv instance
190
+ const serv = grafserv({ schema, preset });
191
+
192
+ // Add the Grafserv instance's route handlers to the Koa app, and register
193
+ // websockets if desired
194
+ serv.addTo(app, server).catch((e) => {
195
+ console.error(e);
196
+ process.exit(1);
197
+ });
198
+
199
+ // Start the Koa server
200
+ server.listen(preset.grafserv.port ?? 5678);
201
+ ```
202
+
203
+ ### Fastify V4
204
+
205
+ ```js
206
+ import Fastify from "fastify";
207
+ // import websocket from '@fastify/websocket'
208
+ import { grafserv } from "grafserv/fastify/v4";
209
+ import preset from "./graphile.config.mjs";
210
+ import schema from "./schema.mjs";
211
+
212
+ // Create a Fastify app
213
+ const app = Fastify({
214
+ logger: true,
215
+ });
216
+ // (Add any Fastify middleware you want here.)
217
+ // await app.register(websocket);
218
+
219
+ // Create a Grafserv instance
220
+ const serv = grafserv({ schema, preset });
221
+
222
+ // Add the Grafserv instance's route handlers to the Fastify app
223
+ serv.addTo(app).catch((e) => {
224
+ console.error(e);
225
+ process.exit(1);
226
+ });
227
+
228
+ // Start the Fastify server
229
+ app.listen({ port: preset.grafserv.port ?? 5678 }, (err, address) => {
230
+ if (err) throw err;
231
+ console.log(`Server is now listening on ${address}`);
232
+ });
233
+ ```
234
+
235
+ ### Next.js API route
236
+
237
+ **TODO: actually implement this!**
238
+
239
+ Grafserv handles a number of API routes, so you should define one for each of
240
+ the things you care about. It's critical that you ensure that the paths line up
241
+ with those used in the Graphile config, otherwise the assets will not correctly
242
+ be served/referenced, this may cause issues when communicating between [Ruru][]
243
+ and GraphQL.
244
+
245
+ ```js
246
+ // utils/grafserv.mjs
247
+ import { grafserv } from "grafserv/next/v13";
248
+ import preset from "./graphile.config.mjs";
249
+ import schema from "./schema.mjs";
250
+
251
+ // Create a shared Grafserv instance
252
+ export const serv = grafserv({ schema, preset });
253
+ ```
254
+
255
+ ```js
256
+ // pages/api/graphql.mjs
257
+ import { serv } from "../../utils/grafserv.mjs";
258
+
259
+ // Create and export the `/graphql` route handler
260
+ const handler = serv.createGraphQLHandler();
261
+ export default handler;
262
+ ```
263
+
264
+ ```js
265
+ // pages/api/ruru.mjs
266
+ import { serv } from "../../utils/grafserv.mjs";
267
+
268
+ // Create and export the `/ruru` route handler
269
+ const handler = serv.createRuruHandler();
270
+ export default handler;
271
+ ```
272
+
273
+ ### Lambda
274
+
275
+ **TODO: actually implement this!**
276
+
277
+ ```js
278
+ import { grafserv } from "grafserv/lambda";
279
+ import preset from "./graphile.config.mjs";
280
+ import schema from "./schema.mjs";
281
+
282
+ // Create a Grafserv instance
283
+ const serv = grafserv({ schema, preset });
284
+
285
+ // Export a lambda handler for GraphQL
286
+ export const handler = serv.createGraphQLHandler();
287
+ ```
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Returns a function that returns the (first, if multiple equal matches) type
3
+ * from mediaTypes that best matches the accept query specified by the given
4
+ * `acceptHeader`. If no Accept header is present then the first mediaType will
5
+ * be returned. If no match is possible, `null` will be returned.
6
+ */
7
+ export declare function makeAcceptMatcher(mediaTypes: string[]): (acceptHeader: string | undefined) => string | null;
8
+ //# sourceMappingURL=accept.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accept.d.ts","sourceRoot":"","sources":["../src/accept.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,EAAE,kBAwBpC,MAAM,GAAG,SAAS,KAC/B,MAAM,GAAG,IAAI,CAmCjB"}