grafserv 0.0.1-alpha.13 → 0.0.1-alpha.15
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 +26 -0
- package/README.md +1 -247
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# grafserv
|
|
2
2
|
|
|
3
|
+
## 0.0.1-alpha.15
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#422](https://github.com/benjie/postgraphile-private/pull/422)
|
|
8
|
+
[`9f87a26b1`](https://github.com/benjie/postgraphile-private/commit/9f87a26b10e5539aa88cfd9909e265513e941fd5)
|
|
9
|
+
Thanks [@benjie](https://github.com/benjie)! - Comments enabled in released
|
|
10
|
+
packages
|
|
11
|
+
|
|
12
|
+
- Updated dependencies
|
|
13
|
+
[[`ea003ca3a`](https://github.com/benjie/postgraphile-private/commit/ea003ca3a8f68fb87dca603582e47981ed033996),
|
|
14
|
+
[`57d88b5fa`](https://github.com/benjie/postgraphile-private/commit/57d88b5fa3ed296210c1fcb223452213fd57985b),
|
|
15
|
+
[`a22830b2f`](https://github.com/benjie/postgraphile-private/commit/a22830b2f293b50a244ac18e1601d7579b450c7d),
|
|
16
|
+
[`9f87a26b1`](https://github.com/benjie/postgraphile-private/commit/9f87a26b10e5539aa88cfd9909e265513e941fd5)]:
|
|
17
|
+
- grafast@0.0.1-alpha.15
|
|
18
|
+
- graphile-config@0.0.1-alpha.7
|
|
19
|
+
- ruru@2.0.0-alpha.11
|
|
20
|
+
|
|
21
|
+
## 0.0.1-alpha.14
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- Updated dependencies
|
|
26
|
+
[[`d99d666fb`](https://github.com/benjie/postgraphile-private/commit/d99d666fb234eb02dd196610995fa480c596242a)]:
|
|
27
|
+
- grafast@0.0.1-alpha.14
|
|
28
|
+
|
|
3
29
|
## 0.0.1-alpha.13
|
|
4
30
|
|
|
5
31
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -31,255 +31,9 @@ And please give some love to our featured sponsors 🤩:
|
|
|
31
31
|
</tr><tr>
|
|
32
32
|
<td align="center"><a href=""><img src="https://graphile.org/images/sponsors/chadf.png" width="90" height="90" alt="Chad Furman" /><br />Chad Furman</a> *</td>
|
|
33
33
|
<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>
|
|
34
|
+
<td align="center"><a href="https://www.accenture.com/"><img src="https://graphile.org/images/sponsors/accenture.svg" width="90" height="90" alt="Accenture" /><br />Accenture</a> *</td>
|
|
34
35
|
</tr></table>
|
|
35
36
|
|
|
36
37
|
<em>\* Sponsors the entire Graphile suite</em>
|
|
37
38
|
|
|
38
39
|
<!-- SPONSORS_END -->
|
|
39
|
-
|
|
40
|
-
## Usage
|
|
41
|
-
|
|
42
|
-
Grafserv supports many different servers, and because each server is different
|
|
43
|
-
each has their own entrypoint, e.g. `grafserv/node` for the Node.js HTTP server
|
|
44
|
-
or `grafserv/express/v4` for Express v4. Generally you import the `grafserv`
|
|
45
|
-
function from the relevant entrypoint for your server of choice and then create
|
|
46
|
-
an instance:
|
|
47
|
-
|
|
48
|
-
```js
|
|
49
|
-
const serv = grafserv({ schema, preset });
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
`grafserv` is passed the GraphQL schema to use (if it's available, otherwise
|
|
53
|
-
passing either null or a promise is also acceptable) and a `graphql-config`
|
|
54
|
-
preset - i.e. your configuration.
|
|
55
|
-
|
|
56
|
-
Calling `grafserv` will return an instance; this instance will have a number of
|
|
57
|
-
helpers on it, including helpers specific to integrating it with your framework
|
|
58
|
-
of choice. For servers that operate on a middleware basis this is typically
|
|
59
|
-
`serv.addTo(app)` (which allows registering multiple route handlers), though
|
|
60
|
-
different servers may have different APIs, such as `serv.createGraphQLHandler()`
|
|
61
|
-
for Lambda and Next.js.
|
|
62
|
-
|
|
63
|
-
Note: There is little value in Grafserv reimplementing every non-GraphQL concern
|
|
64
|
-
your server may have, so instead it leans on the ecosystem of your chosen server
|
|
65
|
-
to handle things like compression, rate limits, sessions, cookies, etc. For
|
|
66
|
-
example, to compress your responses you'd need to use a module like
|
|
67
|
-
[`compression`](https://expressjs.com/en/resources/middleware/compression.html)
|
|
68
|
-
for Express, [`koa-compress`](https://www.npmjs.com/package/koa-compress) for
|
|
69
|
-
Koa, or [`@fastify/compress`](https://www.npmjs.com/package/@fastify/compress)
|
|
70
|
-
for Fastify.
|
|
71
|
-
|
|
72
|
-
### serv.release()
|
|
73
|
-
|
|
74
|
-
Releases any resources created by the instance; no further requests should be
|
|
75
|
-
handled (though currently active requests will be allowed to complete).
|
|
76
|
-
|
|
77
|
-
// TODO: consider terminating subscriptions or other long-lived things.
|
|
78
|
-
|
|
79
|
-
### serv.onRelease(cb)
|
|
80
|
-
|
|
81
|
-
Adds `cb` to the list of callbacks to be called when the server is released;
|
|
82
|
-
useful for releasing resources you created only for the server. Callbacks will
|
|
83
|
-
be called in reverse order that they were added.
|
|
84
|
-
|
|
85
|
-
### serv.setSchema(newSchema)
|
|
86
|
-
|
|
87
|
-
Replaces the schema to use for future requests (currently active requests are
|
|
88
|
-
unaffected) - this is primarily used for "watch" mode.
|
|
89
|
-
|
|
90
|
-
### serv.setPreset(newPreset)
|
|
91
|
-
|
|
92
|
-
Replaces the config to use for future requests (currently active requests are
|
|
93
|
-
unaffected) - this is primarily used for "watch" mode. Note that certain
|
|
94
|
-
configuration changes might not be reflected by certain servers until a restart.
|
|
95
|
-
|
|
96
|
-
### serv.getSchema()
|
|
97
|
-
|
|
98
|
-
Returns either the GraphQL schema that is currently in use, or a promise to the
|
|
99
|
-
same.
|
|
100
|
-
|
|
101
|
-
### serv.getPreset()
|
|
102
|
-
|
|
103
|
-
Returns the resolved `graphile-config` preset that is currently in use.
|
|
104
|
-
|
|
105
|
-
## Servers
|
|
106
|
-
|
|
107
|
-
### Node HTTP server
|
|
108
|
-
|
|
109
|
-
```js
|
|
110
|
-
import { createServer } from "node:http";
|
|
111
|
-
import { grafserv } from "grafserv/node";
|
|
112
|
-
import preset from "./graphile.config.mjs";
|
|
113
|
-
import schema from "./schema.mjs";
|
|
114
|
-
|
|
115
|
-
// Create a Node HTTP server
|
|
116
|
-
const server = createServer();
|
|
117
|
-
server.on("error", (e) => {
|
|
118
|
-
console.error(e);
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
// Create a Grafserv instance
|
|
122
|
-
const serv = grafserv({ schema, preset });
|
|
123
|
-
|
|
124
|
-
// Mount the request handler into a new HTTP server, and register websockets if
|
|
125
|
-
// desired
|
|
126
|
-
serv.addTo(server).catch((e) => {
|
|
127
|
-
console.error(e);
|
|
128
|
-
process.exit(1);
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
// Start the Node server
|
|
132
|
-
server.listen(preset.grafserv?.port ?? 5678);
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
### Express V4
|
|
136
|
-
|
|
137
|
-
```js
|
|
138
|
-
import { createServer } from "node:http";
|
|
139
|
-
import express from "express";
|
|
140
|
-
import { grafserv } from "grafserv/express/v4";
|
|
141
|
-
import preset from "./graphile.config.mjs";
|
|
142
|
-
import schema from "./schema.mjs";
|
|
143
|
-
|
|
144
|
-
// Create an express app
|
|
145
|
-
const app = express();
|
|
146
|
-
// (Add any Express middleware you want here.)
|
|
147
|
-
|
|
148
|
-
// Create a Node HTTP server, mounting Express into it
|
|
149
|
-
const server = createServer(app);
|
|
150
|
-
server.on("error", (e) => {
|
|
151
|
-
console.error(e);
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
// Create a Grafserv instance
|
|
155
|
-
const serv = grafserv({ schema, preset });
|
|
156
|
-
|
|
157
|
-
// Add the Grafserv instance's route handlers to the Express app, and register
|
|
158
|
-
// websockets if desired
|
|
159
|
-
serv.addTo(app, server).catch((e) => {
|
|
160
|
-
console.error(e);
|
|
161
|
-
process.exit(1);
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
// Start the Express server
|
|
165
|
-
server.listen(preset.grafserv?.port ?? 5678);
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
### Koa V2
|
|
169
|
-
|
|
170
|
-
```js
|
|
171
|
-
import { createServer } from "node:http";
|
|
172
|
-
import Koa from "koa";
|
|
173
|
-
import { grafserv } from "grafserv/koa/v2";
|
|
174
|
-
import preset from "./graphile.config.mjs";
|
|
175
|
-
import schema from "./schema.mjs";
|
|
176
|
-
|
|
177
|
-
// Create a Koa app
|
|
178
|
-
const app = new Koa();
|
|
179
|
-
// (Add any Koa middleware you want here.)
|
|
180
|
-
|
|
181
|
-
// Create a Node HTTP server, mounting Koa into it
|
|
182
|
-
const server = createServer(app);
|
|
183
|
-
server.on("error", (e) => {
|
|
184
|
-
console.error(e);
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
// Create a Grafserv instance
|
|
188
|
-
const serv = grafserv({ schema, preset });
|
|
189
|
-
|
|
190
|
-
// Add the Grafserv instance's route handlers to the Koa app, and register
|
|
191
|
-
// websockets if desired
|
|
192
|
-
serv.addTo(app, server).catch((e) => {
|
|
193
|
-
console.error(e);
|
|
194
|
-
process.exit(1);
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
// Start the Koa server
|
|
198
|
-
server.listen(preset.grafserv?.port ?? 5678);
|
|
199
|
-
```
|
|
200
|
-
|
|
201
|
-
### Fastify V4
|
|
202
|
-
|
|
203
|
-
```js
|
|
204
|
-
import Fastify from "fastify";
|
|
205
|
-
// import websocket from '@fastify/websocket'
|
|
206
|
-
import { grafserv } from "grafserv/fastify/v4";
|
|
207
|
-
import preset from "./graphile.config.mjs";
|
|
208
|
-
import schema from "./schema.mjs";
|
|
209
|
-
|
|
210
|
-
// Create a Fastify app
|
|
211
|
-
const app = Fastify({
|
|
212
|
-
logger: true,
|
|
213
|
-
});
|
|
214
|
-
// (Add any Fastify middleware you want here.)
|
|
215
|
-
// await app.register(websocket);
|
|
216
|
-
|
|
217
|
-
// Create a Grafserv instance
|
|
218
|
-
const serv = grafserv({ schema, preset });
|
|
219
|
-
|
|
220
|
-
// Add the Grafserv instance's route handlers to the Fastify app
|
|
221
|
-
serv.addTo(app).catch((e) => {
|
|
222
|
-
console.error(e);
|
|
223
|
-
process.exit(1);
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
// Start the Fastify server
|
|
227
|
-
app.listen({ port: preset.grafserv?.port ?? 5678 }, (err, address) => {
|
|
228
|
-
if (err) throw err;
|
|
229
|
-
console.log(`Server is now listening on ${address}`);
|
|
230
|
-
});
|
|
231
|
-
```
|
|
232
|
-
|
|
233
|
-
### Next.js API route
|
|
234
|
-
|
|
235
|
-
**TODO: actually implement this!**
|
|
236
|
-
|
|
237
|
-
Grafserv handles a number of API routes, so you should define one for each of
|
|
238
|
-
the things you care about. It's critical that you ensure that the paths line up
|
|
239
|
-
with those used in the Graphile config, otherwise the assets will not correctly
|
|
240
|
-
be served/referenced, this may cause issues when communicating between [Ruru][]
|
|
241
|
-
and GraphQL.
|
|
242
|
-
|
|
243
|
-
```js
|
|
244
|
-
// utils/grafserv.mjs
|
|
245
|
-
import { grafserv } from "grafserv/next/v13";
|
|
246
|
-
import preset from "./graphile.config.mjs";
|
|
247
|
-
import schema from "./schema.mjs";
|
|
248
|
-
|
|
249
|
-
// Create a shared Grafserv instance
|
|
250
|
-
export const serv = grafserv({ schema, preset });
|
|
251
|
-
```
|
|
252
|
-
|
|
253
|
-
```js
|
|
254
|
-
// pages/api/graphql.mjs
|
|
255
|
-
import { serv } from "../../utils/grafserv.mjs";
|
|
256
|
-
|
|
257
|
-
// Create and export the `/graphql` route handler
|
|
258
|
-
const handler = serv.createGraphQLHandler();
|
|
259
|
-
export default handler;
|
|
260
|
-
```
|
|
261
|
-
|
|
262
|
-
```js
|
|
263
|
-
// pages/api/ruru.mjs
|
|
264
|
-
import { serv } from "../../utils/grafserv.mjs";
|
|
265
|
-
|
|
266
|
-
// Create and export the `/ruru` route handler
|
|
267
|
-
const handler = serv.createRuruHandler();
|
|
268
|
-
export default handler;
|
|
269
|
-
```
|
|
270
|
-
|
|
271
|
-
### Lambda
|
|
272
|
-
|
|
273
|
-
**TODO: actually implement this!**
|
|
274
|
-
|
|
275
|
-
```js
|
|
276
|
-
import { grafserv } from "grafserv/lambda";
|
|
277
|
-
import preset from "./graphile.config.mjs";
|
|
278
|
-
import schema from "./schema.mjs";
|
|
279
|
-
|
|
280
|
-
// Create a Grafserv instance
|
|
281
|
-
const serv = grafserv({ schema, preset });
|
|
282
|
-
|
|
283
|
-
// Export a lambda handler for GraphQL
|
|
284
|
-
export const handler = serv.createGraphQLHandler();
|
|
285
|
-
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "grafserv",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.15",
|
|
4
4
|
"description": "A highly optimized server for GraphQL, powered by Grafast",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -68,17 +68,17 @@
|
|
|
68
68
|
"@graphile/lru": "^5.0.0-alpha.2",
|
|
69
69
|
"debug": "^4.1.1",
|
|
70
70
|
"eventemitter3": "^4.0.7",
|
|
71
|
-
"graphile-config": "^0.0.1-alpha.
|
|
71
|
+
"graphile-config": "^0.0.1-alpha.7",
|
|
72
72
|
"graphql-ws": "^5.11.3",
|
|
73
|
-
"ruru": "^2.0.0-alpha.
|
|
73
|
+
"ruru": "^2.0.0-alpha.11",
|
|
74
74
|
"tslib": "^2.5.0"
|
|
75
75
|
},
|
|
76
76
|
"engines": {
|
|
77
77
|
"node": ">=16.10"
|
|
78
78
|
},
|
|
79
79
|
"peerDependencies": {
|
|
80
|
-
"grafast": "^0.0.1-alpha.
|
|
81
|
-
"graphile-config": "^0.0.1-alpha.
|
|
80
|
+
"grafast": "^0.0.1-alpha.15",
|
|
81
|
+
"graphile-config": "^0.0.1-alpha.7",
|
|
82
82
|
"graphql": "^16.1.0-experimental-stream-defer.6",
|
|
83
83
|
"ws": "^8.12.1"
|
|
84
84
|
},
|
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
"@whatwg-node/fetch": "^0.8.1",
|
|
95
95
|
"express": "^4.18.2",
|
|
96
96
|
"fastify": "^4.12.0",
|
|
97
|
-
"grafast": "^0.0.1-alpha.
|
|
97
|
+
"grafast": "^0.0.1-alpha.15",
|
|
98
98
|
"graphql-http": "^1.16.0",
|
|
99
99
|
"jest": "^28.1.3",
|
|
100
100
|
"jest-serializer-graphql-schema": "^5.0.0-alpha.2",
|