grafserv 0.0.1-0.2 → 0.0.1-0.20
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.
- package/CHANGELOG.md +212 -0
- package/README.md +248 -3
- package/dist/accept.d.ts +8 -0
- package/dist/accept.d.ts.map +1 -0
- package/dist/accept.js +419 -0
- package/dist/accept.js.map +1 -0
- package/dist/core/base.d.ts +38 -0
- package/dist/core/base.d.ts.map +1 -0
- package/dist/core/base.js +440 -0
- package/dist/core/base.js.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/interfaces.d.ts +176 -23
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/interfaces.js +2 -0
- package/dist/interfaces.js.map +1 -1
- package/dist/mapIterator.d.ts +2 -0
- package/dist/mapIterator.d.ts.map +1 -0
- package/dist/mapIterator.js +65 -0
- package/dist/mapIterator.js.map +1 -0
- package/dist/middleware/graphiql.d.ts +3 -3
- package/dist/middleware/graphiql.d.ts.map +1 -1
- package/dist/middleware/graphiql.js +14 -4
- package/dist/middleware/graphiql.js.map +1 -1
- package/dist/middleware/graphql.d.ts +8 -3
- package/dist/middleware/graphql.d.ts.map +1 -1
- package/dist/middleware/graphql.js +325 -23
- package/dist/middleware/graphql.js.map +1 -1
- package/dist/options.d.ts +23 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/options.js +114 -0
- package/dist/options.js.map +1 -0
- package/dist/servers/express/v4/index.d.ts +24 -0
- package/dist/servers/express/v4/index.d.ts.map +1 -0
- package/dist/servers/express/v4/index.js +62 -0
- package/dist/servers/express/v4/index.js.map +1 -0
- package/dist/servers/fastify/v4/index.d.ts +21 -0
- package/dist/servers/fastify/v4/index.d.ts.map +1 -0
- package/dist/servers/fastify/v4/index.js +198 -0
- package/dist/servers/fastify/v4/index.js.map +1 -0
- package/dist/servers/koa/v2/index.d.ts +25 -0
- package/dist/servers/koa/v2/index.d.ts.map +1 -0
- package/dist/servers/koa/v2/index.js +137 -0
- package/dist/servers/koa/v2/index.js.map +1 -0
- package/dist/servers/node/index.d.ts +32 -0
- package/dist/servers/node/index.d.ts.map +1 -0
- package/dist/servers/node/index.js +269 -0
- package/dist/servers/node/index.js.map +1 -0
- package/dist/utils.d.ts +19 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +145 -0
- package/dist/utils.js.map +1 -0
- package/package.json +42 -8
- package/dist/middleware/index.d.ts +0 -12
- package/dist/middleware/index.d.ts.map +0 -1
- package/dist/middleware/index.js +0 -431
- package/dist/middleware/index.js.map +0 -1
- package/dist/middleware/interfaces.d.ts +0 -40
- package/dist/middleware/interfaces.d.ts.map +0 -1
- package/dist/middleware/interfaces.js +0 -3
- package/dist/middleware/interfaces.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,217 @@
|
|
|
1
1
|
# grafserv
|
|
2
2
|
|
|
3
|
+
## 0.0.1-0.20
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies
|
|
8
|
+
[[`4c2b7d1ca`](https://github.com/benjie/postgraphile-private/commit/4c2b7d1ca1afbda1e47da22c346cc3b03d01b7f0),
|
|
9
|
+
[`c8a56cdc8`](https://github.com/benjie/postgraphile-private/commit/c8a56cdc83390e5735beb9b90f004e7975cab28c)]:
|
|
10
|
+
- grafast@0.0.1-0.18
|
|
11
|
+
|
|
12
|
+
## 0.0.1-0.19
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- Updated dependencies [[`f48860d4f`](undefined)]:
|
|
17
|
+
- grafast@0.0.1-0.17
|
|
18
|
+
|
|
19
|
+
## 0.0.1-0.18
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- Updated dependencies
|
|
24
|
+
[[`df89aba52`](https://github.com/benjie/postgraphile-private/commit/df89aba524270e52f82987fcc4ab5d78ce180fc5)]:
|
|
25
|
+
- grafast@0.0.1-0.16
|
|
26
|
+
|
|
27
|
+
## 0.0.1-0.17
|
|
28
|
+
|
|
29
|
+
### Patch Changes
|
|
30
|
+
|
|
31
|
+
- [#210](https://github.com/benjie/postgraphile-private/pull/210)
|
|
32
|
+
[`b523118fe`](https://github.com/benjie/postgraphile-private/commit/b523118fe6217c027363fea91252a3a1764e17df)
|
|
33
|
+
Thanks [@benjie](https://github.com/benjie)! - Replace BaseGraphQLContext with
|
|
34
|
+
Grafast.Context throughout.
|
|
35
|
+
|
|
36
|
+
- [#210](https://github.com/benjie/postgraphile-private/pull/210)
|
|
37
|
+
[`461c03b72`](https://github.com/benjie/postgraphile-private/commit/461c03b72477821ec26cbf703011542e453d083c)
|
|
38
|
+
Thanks [@benjie](https://github.com/benjie)! - Make servers releasable where
|
|
39
|
+
possible.
|
|
40
|
+
|
|
41
|
+
- Updated dependencies
|
|
42
|
+
[[`b523118fe`](https://github.com/benjie/postgraphile-private/commit/b523118fe6217c027363fea91252a3a1764e17df)]:
|
|
43
|
+
- grafast@0.0.1-0.15
|
|
44
|
+
|
|
45
|
+
## 0.0.1-0.16
|
|
46
|
+
|
|
47
|
+
### Patch Changes
|
|
48
|
+
|
|
49
|
+
- [#207](https://github.com/benjie/postgraphile-private/pull/207)
|
|
50
|
+
[`c850dd4ec`](https://github.com/benjie/postgraphile-private/commit/c850dd4ec0e42e37122f5bca55a079b53bfd895e)
|
|
51
|
+
Thanks [@benjie](https://github.com/benjie)! - Rename 'preset.server' to
|
|
52
|
+
'preset.grafserv'.
|
|
53
|
+
|
|
54
|
+
- [#207](https://github.com/benjie/postgraphile-private/pull/207)
|
|
55
|
+
[`afa0ea5f6`](https://github.com/benjie/postgraphile-private/commit/afa0ea5f6c508d9a0ba5946ab153b13ddbd274a0)
|
|
56
|
+
Thanks [@benjie](https://github.com/benjie)! - Fix bug in subscriptions where
|
|
57
|
+
termination of underlying stream wouldn't terminate the subscription.
|
|
58
|
+
|
|
59
|
+
- [#206](https://github.com/benjie/postgraphile-private/pull/206)
|
|
60
|
+
[`851b78ef2`](https://github.com/benjie/postgraphile-private/commit/851b78ef20d430164507ec9b3f41a5a0b8a18ed7)
|
|
61
|
+
Thanks [@benjie](https://github.com/benjie)! - Grafserv now masks untrusted
|
|
62
|
+
errors by default; trusted errors are constructed via GraphQL's GraphQLError
|
|
63
|
+
or Grafast's SafeError.
|
|
64
|
+
- Updated dependencies
|
|
65
|
+
[[`d76043453`](https://github.com/benjie/postgraphile-private/commit/d7604345362c58bf7eb43ef1ac1795a2ac22ae79),
|
|
66
|
+
[`afa0ea5f6`](https://github.com/benjie/postgraphile-private/commit/afa0ea5f6c508d9a0ba5946ab153b13ddbd274a0),
|
|
67
|
+
[`851b78ef2`](https://github.com/benjie/postgraphile-private/commit/851b78ef20d430164507ec9b3f41a5a0b8a18ed7),
|
|
68
|
+
[`384b3594f`](https://github.com/benjie/postgraphile-private/commit/384b3594f543d113650c1b6b02b276360dd2d15f)]:
|
|
69
|
+
- grafast@0.0.1-0.14
|
|
70
|
+
|
|
71
|
+
## 0.0.1-0.15
|
|
72
|
+
|
|
73
|
+
### Patch Changes
|
|
74
|
+
|
|
75
|
+
- Updated dependencies [[`e5b664b6f`](undefined)]:
|
|
76
|
+
- grafast@0.0.1-0.13
|
|
77
|
+
|
|
78
|
+
## 0.0.1-0.14
|
|
79
|
+
|
|
80
|
+
### Patch Changes
|
|
81
|
+
|
|
82
|
+
- [#200](https://github.com/benjie/postgraphile-private/pull/200)
|
|
83
|
+
[`1e5671cdb`](https://github.com/benjie/postgraphile-private/commit/1e5671cdbbf9f4600b74c43eaa7e33b7bfd75fb9)
|
|
84
|
+
Thanks [@benjie](https://github.com/benjie)! - Add support for websocket
|
|
85
|
+
GraphQL subscriptions (via graphql-ws) to grafserv and PostGraphile (currently
|
|
86
|
+
supporting Node, Express, Koa and Fastify)
|
|
87
|
+
|
|
88
|
+
- [#200](https://github.com/benjie/postgraphile-private/pull/200)
|
|
89
|
+
[`5b634a78e`](https://github.com/benjie/postgraphile-private/commit/5b634a78e51816071447aceb1edfb813d77d563b)
|
|
90
|
+
Thanks [@benjie](https://github.com/benjie)! - Standardize on `serv.addTo`
|
|
91
|
+
interface, even for Node
|
|
92
|
+
|
|
93
|
+
- Updated dependencies
|
|
94
|
+
[[`4f5d5bec7`](https://github.com/benjie/postgraphile-private/commit/4f5d5bec72f949b17b39cd07acc848ce7a8bfa36),
|
|
95
|
+
[`e11698473`](https://github.com/benjie/postgraphile-private/commit/e1169847303790570bfafa07eb25d8fce53a0391),
|
|
96
|
+
[`25f5a6cbf`](https://github.com/benjie/postgraphile-private/commit/25f5a6cbff6cd5a94ebc4f411f7fa89c209fc383)]:
|
|
97
|
+
- grafast@0.0.1-0.12
|
|
98
|
+
- ruru@2.0.0-0.10
|
|
99
|
+
|
|
100
|
+
## 0.0.1-0.13
|
|
101
|
+
|
|
102
|
+
### Patch Changes
|
|
103
|
+
|
|
104
|
+
- [`0ab95d0b1`](undefined) - Update sponsors.
|
|
105
|
+
|
|
106
|
+
- [#195](https://github.com/benjie/postgraphile-private/pull/195)
|
|
107
|
+
[`752ec9c51`](https://github.com/benjie/postgraphile-private/commit/752ec9c516add7c4617b426e97eccd1d4e5b7833)
|
|
108
|
+
Thanks [@benjie](https://github.com/benjie)! - Fix handling of HTTP errors and
|
|
109
|
+
allow for 204 status code responses. Add CORS hack to enable graphql-http
|
|
110
|
+
auditing.
|
|
111
|
+
- Updated dependencies [[`0ab95d0b1`](undefined),
|
|
112
|
+
[`4783bdd7c`](https://github.com/benjie/postgraphile-private/commit/4783bdd7cc28ac8b497fdd4d6f1024d80cb432ef),
|
|
113
|
+
[`652cf1073`](https://github.com/benjie/postgraphile-private/commit/652cf107316ea5832f69c6a55574632187f5c876)]:
|
|
114
|
+
- grafast@0.0.1-0.11
|
|
115
|
+
- graphile-config@0.0.1-0.5
|
|
116
|
+
- ruru@2.0.0-0.9
|
|
117
|
+
|
|
118
|
+
## 0.0.1-0.12
|
|
119
|
+
|
|
120
|
+
### Patch Changes
|
|
121
|
+
|
|
122
|
+
- Updated dependencies
|
|
123
|
+
[[`842f6ccbb`](https://github.com/benjie/postgraphile-private/commit/842f6ccbb3c9bd0c101c4f4df31c5ed1aea9b2ab)]:
|
|
124
|
+
- graphile-config@0.0.1-0.4
|
|
125
|
+
- grafast@0.0.1-0.10
|
|
126
|
+
- ruru@2.0.0-0.8
|
|
127
|
+
|
|
128
|
+
## 0.0.1-0.11
|
|
129
|
+
|
|
130
|
+
### Patch Changes
|
|
131
|
+
|
|
132
|
+
- [#176](https://github.com/benjie/postgraphile-private/pull/176)
|
|
133
|
+
[`11d6be65e`](https://github.com/benjie/postgraphile-private/commit/11d6be65e0da489f8ab3e3a8b8db145f8b2147ad)
|
|
134
|
+
Thanks [@benjie](https://github.com/benjie)! - Fix issue with plugin
|
|
135
|
+
versioning. Add more TSDoc comments. New getTerminalWidth() helper.
|
|
136
|
+
- Updated dependencies
|
|
137
|
+
[[`19e2961de`](https://github.com/benjie/postgraphile-private/commit/19e2961de67dc0b9601799bba256e4c4a23cc0cb),
|
|
138
|
+
[`11d6be65e`](https://github.com/benjie/postgraphile-private/commit/11d6be65e0da489f8ab3e3a8b8db145f8b2147ad)]:
|
|
139
|
+
- graphile-config@0.0.1-0.3
|
|
140
|
+
- grafast@0.0.1-0.9
|
|
141
|
+
- ruru@2.0.0-0.7
|
|
142
|
+
|
|
143
|
+
## 0.0.1-0.10
|
|
144
|
+
|
|
145
|
+
### Patch Changes
|
|
146
|
+
|
|
147
|
+
- Updated dependencies
|
|
148
|
+
[[`208166269`](https://github.com/benjie/postgraphile-private/commit/208166269177d6e278b056e1c77d26a2d8f59f49)]:
|
|
149
|
+
- grafast@0.0.1-0.8
|
|
150
|
+
|
|
151
|
+
## 0.0.1-0.9
|
|
152
|
+
|
|
153
|
+
### Patch Changes
|
|
154
|
+
|
|
155
|
+
- Updated dependencies [[`a40fa6966`](undefined),
|
|
156
|
+
[`8f04af08d`](https://github.com/benjie/postgraphile-private/commit/8f04af08da68baf7b2b4d508eac0d2a57064da7b)]:
|
|
157
|
+
- ruru@2.0.0-0.6
|
|
158
|
+
- grafast@0.0.1-0.7
|
|
159
|
+
|
|
160
|
+
## 0.0.1-0.8
|
|
161
|
+
|
|
162
|
+
### Patch Changes
|
|
163
|
+
|
|
164
|
+
- [`c4213e91d`](undefined) - Add pgl.getResolvedPreset() API; fix Ruru
|
|
165
|
+
respecting graphqlPath setting; replace 'instance' with 'pgl'/'serv' as
|
|
166
|
+
appropriate; forbid subscriptions on GET
|
|
167
|
+
|
|
168
|
+
## 0.0.1-0.7
|
|
169
|
+
|
|
170
|
+
### Patch Changes
|
|
171
|
+
|
|
172
|
+
- [`9b296ba54`](undefined) - More secure, more compatible, and lots of fixes
|
|
173
|
+
across the monorepo
|
|
174
|
+
|
|
175
|
+
- Updated dependencies [[`9b296ba54`](undefined)]:
|
|
176
|
+
- grafast@0.0.1-0.6
|
|
177
|
+
- ruru@2.0.0-0.5
|
|
178
|
+
- graphile-config@0.0.1-0.2
|
|
179
|
+
|
|
180
|
+
## 0.0.1-0.6
|
|
181
|
+
|
|
182
|
+
### Patch Changes
|
|
183
|
+
|
|
184
|
+
- Updated dependencies [[`cd37fd02a`](undefined)]:
|
|
185
|
+
- grafast@0.0.1-0.5
|
|
186
|
+
|
|
187
|
+
## 0.0.1-0.5
|
|
188
|
+
|
|
189
|
+
### Patch Changes
|
|
190
|
+
|
|
191
|
+
- [`768f32681`](undefined) - Fix peerDependencies ranges
|
|
192
|
+
|
|
193
|
+
- Updated dependencies [[`768f32681`](undefined)]:
|
|
194
|
+
- grafast@0.0.1-0.4
|
|
195
|
+
- ruru@2.0.0-0.4
|
|
196
|
+
|
|
197
|
+
## 0.0.1-0.4
|
|
198
|
+
|
|
199
|
+
### Patch Changes
|
|
200
|
+
|
|
201
|
+
- Updated dependencies [[`0983df3f6`](undefined)]:
|
|
202
|
+
- ruru@2.0.0-0.3
|
|
203
|
+
|
|
204
|
+
## 0.0.1-0.3
|
|
205
|
+
|
|
206
|
+
### Patch Changes
|
|
207
|
+
|
|
208
|
+
- [`d11c1911c`](undefined) - Fix dependencies
|
|
209
|
+
|
|
210
|
+
- Updated dependencies [[`d11c1911c`](undefined)]:
|
|
211
|
+
- grafast@0.0.1-0.3
|
|
212
|
+
- ruru@2.0.0-0.2
|
|
213
|
+
- graphile-config@0.0.1-0.1
|
|
214
|
+
|
|
3
215
|
## 0.0.1-0.2
|
|
4
216
|
|
|
5
217
|
### 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
|
+
```
|
package/dist/accept.d.ts
ADDED
|
@@ -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"}
|