grafserv 0.0.0 → 0.0.1-0.10

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 (56) hide show
  1. package/CHANGELOG.md +103 -0
  2. package/README.md +248 -1
  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 +35 -0
  8. package/dist/core/base.d.ts.map +1 -0
  9. package/dist/core/base.js +381 -0
  10. package/dist/core/base.js.map +1 -0
  11. package/dist/index.d.ts +3 -0
  12. package/dist/index.d.ts.map +1 -0
  13. package/dist/index.js +6 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/interfaces.d.ts +177 -0
  16. package/dist/interfaces.d.ts.map +1 -0
  17. package/dist/interfaces.js +6 -0
  18. package/dist/interfaces.js.map +1 -0
  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 +4 -0
  24. package/dist/middleware/graphiql.d.ts.map +1 -0
  25. package/dist/middleware/graphiql.js +31 -0
  26. package/dist/middleware/graphiql.js.map +1 -0
  27. package/dist/middleware/graphql.d.ts +9 -0
  28. package/dist/middleware/graphql.d.ts.map +1 -0
  29. package/dist/middleware/graphql.js +415 -0
  30. package/dist/middleware/graphql.js.map +1 -0
  31. package/dist/options.d.ts +14 -0
  32. package/dist/options.d.ts.map +1 -0
  33. package/dist/options.js +23 -0
  34. package/dist/options.js.map +1 -0
  35. package/dist/servers/express/v4/index.d.ts +20 -0
  36. package/dist/servers/express/v4/index.d.ts.map +1 -0
  37. package/dist/servers/express/v4/index.js +43 -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 +179 -0
  42. package/dist/servers/fastify/v4/index.js.map +1 -0
  43. package/dist/servers/koa/v2/index.d.ts +21 -0
  44. package/dist/servers/koa/v2/index.d.ts.map +1 -0
  45. package/dist/servers/koa/v2/index.js +110 -0
  46. package/dist/servers/koa/v2/index.js.map +1 -0
  47. package/dist/servers/node/index.d.ts +22 -0
  48. package/dist/servers/node/index.d.ts.map +1 -0
  49. package/dist/servers/node/index.js +173 -0
  50. package/dist/servers/node/index.js.map +1 -0
  51. package/dist/utils.d.ts +16 -0
  52. package/dist/utils.d.ts.map +1 -0
  53. package/dist/utils.js +121 -0
  54. package/dist/utils.js.map +1 -0
  55. package/package.json +76 -5
  56. package/index.js +0 -1
package/CHANGELOG.md ADDED
@@ -0,0 +1,103 @@
1
+ # grafserv
2
+
3
+ ## 0.0.1-0.10
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+ [[`208166269`](https://github.com/benjie/postgraphile-private/commit/208166269177d6e278b056e1c77d26a2d8f59f49)]:
9
+ - grafast@0.0.1-0.8
10
+
11
+ ## 0.0.1-0.9
12
+
13
+ ### Patch Changes
14
+
15
+ - Updated dependencies [[`a40fa6966`](undefined),
16
+ [`8f04af08d`](https://github.com/benjie/postgraphile-private/commit/8f04af08da68baf7b2b4d508eac0d2a57064da7b)]:
17
+ - ruru@2.0.0-0.6
18
+ - grafast@0.0.1-0.7
19
+
20
+ ## 0.0.1-0.8
21
+
22
+ ### Patch Changes
23
+
24
+ - [`c4213e91d`](undefined) - Add pgl.getResolvedPreset() API; fix Ruru
25
+ respecting graphqlPath setting; replace 'instance' with 'pgl'/'serv' as
26
+ appropriate; forbid subscriptions on GET
27
+
28
+ ## 0.0.1-0.7
29
+
30
+ ### Patch Changes
31
+
32
+ - [`9b296ba54`](undefined) - More secure, more compatible, and lots of fixes
33
+ across the monorepo
34
+
35
+ - Updated dependencies [[`9b296ba54`](undefined)]:
36
+ - grafast@0.0.1-0.6
37
+ - ruru@2.0.0-0.5
38
+ - graphile-config@0.0.1-0.2
39
+
40
+ ## 0.0.1-0.6
41
+
42
+ ### Patch Changes
43
+
44
+ - Updated dependencies [[`cd37fd02a`](undefined)]:
45
+ - grafast@0.0.1-0.5
46
+
47
+ ## 0.0.1-0.5
48
+
49
+ ### Patch Changes
50
+
51
+ - [`768f32681`](undefined) - Fix peerDependencies ranges
52
+
53
+ - Updated dependencies [[`768f32681`](undefined)]:
54
+ - grafast@0.0.1-0.4
55
+ - ruru@2.0.0-0.4
56
+
57
+ ## 0.0.1-0.4
58
+
59
+ ### Patch Changes
60
+
61
+ - Updated dependencies [[`0983df3f6`](undefined)]:
62
+ - ruru@2.0.0-0.3
63
+
64
+ ## 0.0.1-0.3
65
+
66
+ ### Patch Changes
67
+
68
+ - [`d11c1911c`](undefined) - Fix dependencies
69
+
70
+ - Updated dependencies [[`d11c1911c`](undefined)]:
71
+ - grafast@0.0.1-0.3
72
+ - ruru@2.0.0-0.2
73
+ - graphile-config@0.0.1-0.1
74
+
75
+ ## 0.0.1-0.2
76
+
77
+ ### Patch Changes
78
+
79
+ - Updated dependencies [[`6576bd37b`](undefined), [`25037fc15`](undefined)]:
80
+ - ruru@2.0.0-0.1
81
+ - grafast@0.0.1-0.2
82
+
83
+ ## 0.0.1-0.1
84
+
85
+ ### Patch Changes
86
+
87
+ - Updated dependencies [[`55f15cf35`](undefined)]:
88
+ - grafast@0.0.1-0.1
89
+
90
+ ## 0.0.1-0.0
91
+
92
+ ### Patch Changes
93
+
94
+ - [#125](https://github.com/benjie/postgraphile-private/pull/125)
95
+ [`91f2256b3`](https://github.com/benjie/postgraphile-private/commit/91f2256b3fd699bec19fc86f1ca79df057e58639)
96
+ Thanks [@benjie](https://github.com/benjie)! - Initial changesets release
97
+
98
+ - Updated dependencies
99
+ [[`91f2256b3`](https://github.com/benjie/postgraphile-private/commit/91f2256b3fd699bec19fc86f1ca79df057e58639)]:
100
+ - ruru@2.0.0-0.0
101
+ - @graphile/lru@5.0.0-0.1
102
+ - grafast@0.0.1-0.0
103
+ - graphile-config@0.0.1-0.0
package/README.md CHANGED
@@ -1 +1,248 @@
1
- Coming 2023 :D
1
+ # grafserv
2
+
3
+ <span class="badge-patreon"><a href="https://patreon.com/benjie" title="Support Graphile development on Patreon"><img src="https://img.shields.io/badge/sponsor-via%20Patreon-orange.svg" alt="Patreon sponsor button" /></a></span>
4
+ [![Discord chat room](https://img.shields.io/discord/489127045289476126.svg)](http://discord.gg/graphile)
5
+ [![Package on npm](https://img.shields.io/npm/v/grafserv.svg?style=flat)](https://www.npmjs.com/package/grafserv)
6
+ ![MIT license](https://img.shields.io/npm/l/grafserv.svg)
7
+ [![Follow](https://img.shields.io/badge/twitter-@GraphileHQ-blue.svg)](https://twitter.com/GraphileHQ)
8
+
9
+ _**A highly performant GraphQL server for Node.js, powered by
10
+ [Gra*fast*](https://grafast.org).**_
11
+
12
+ **Documentation**: https://grafast.org/grafserv/
13
+
14
+ <!-- SPONSORS_BEGIN -->
15
+
16
+ ## Crowd-funded open-source software
17
+
18
+ To help us develop this software sustainably under the MIT license, we ask all
19
+ individuals and businesses that use it to help support its ongoing maintenance
20
+ and development via sponsorship.
21
+
22
+ ### [Click here to find out more about sponsors and sponsorship.](https://www.graphile.org/sponsor/)
23
+
24
+ And please give some love to our featured sponsors 🤩:
25
+
26
+ <table><tr>
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
+ <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
+ <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>
31
+ </tr><tr>
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
+ <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
+ <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
+ <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
+ </tr></table>
39
+
40
+ <em>\* Sponsors the entire Graphile suite</em>
41
+
42
+ <!-- SPONSORS_END -->
43
+
44
+ ## Usage
45
+
46
+ Grafserv supports many different servers, and because each server is different
47
+ each has their own entrypoint, e.g. `grafserv/node` for the Node.js HTTP server
48
+ or `grafserv/express/v4` for Express v4. Generally you import the `grafserv`
49
+ function from the relevant entrypoint for your server of choice and then create
50
+ an instance:
51
+
52
+ ```js
53
+ const serv = grafserv({ schema, preset });
54
+ ```
55
+
56
+ `grafserv` is passed the GraphQL schema to use (if it's available, otherwise
57
+ passing either null or a promise is also acceptable) and a `graphql-config`
58
+ preset - i.e. your configuration.
59
+
60
+ Calling `grafserv` will return an instance; this instance will have a number of
61
+ helpers on it, including helpers specific to integrating it with your framework
62
+ of choice. For servers that operate on a middleware basis this is typically
63
+ `serv.addTo(app)` (which allows registering multiple route handlers), though
64
+ different servers may have different APIs, such as `serv.createHandler()` for
65
+ Node and `serv.createGraphQLHandler()` for Lambda and Next.js.
66
+
67
+ Note: There is little value in Grafserv reimplementing every non-GraphQL concern
68
+ your server may have, so instead it leans on the ecosystem of your chosen server
69
+ to handle things like compression, rate limits, sessions, cookies, etc. For
70
+ example, to compress your responses you'd need to use a module like
71
+ [`compression`](https://expressjs.com/en/resources/middleware/compression.html)
72
+ for Express, [`koa-compress`](https://www.npmjs.com/package/koa-compress) for
73
+ Koa, or [`@fastify/compress`](https://www.npmjs.com/package/@fastify/compress)
74
+ for Fastify.
75
+
76
+ ### serv.release()
77
+
78
+ Releases any resources created by the instance; no further requests should be
79
+ handled (though currently active requests will be allowed to complete).
80
+
81
+ // TODO: consider terminating subscriptions or other long-lived things.
82
+
83
+ ### serv.onRelease(cb)
84
+
85
+ Adds `cb` to the list of callbacks to be called when the server is released;
86
+ useful for releasing resources you created only for the server. Callbacks will
87
+ be called in reverse order that they were added.
88
+
89
+ ### serv.setSchema(newSchema)
90
+
91
+ Replaces the schema to use for future requests (currently active requests are
92
+ unaffected) - this is primarily used for "watch" mode.
93
+
94
+ ### serv.setPreset(newPreset)
95
+
96
+ Replaces the config to use for future requests (currently active requests are
97
+ unaffected) - this is primarily used for "watch" mode. Note that certain
98
+ configuration changes might not be reflected by certain servers until a restart.
99
+
100
+ ### serv.getSchema()
101
+
102
+ Returns either the GraphQL schema that is currently in use, or a promise to the
103
+ same.
104
+
105
+ ### serv.getPreset()
106
+
107
+ Returns the resolved `graphile-config` preset that is currently in use.
108
+
109
+ ## Servers
110
+
111
+ ### Node HTTP server
112
+
113
+ ```js
114
+ import { createServer } from "node:http";
115
+ import { grafserv } from "grafserv/node";
116
+ import preset from "./graphile.config.mjs";
117
+ import schema from "./schema.mjs";
118
+
119
+ // Create a Grafserv instance
120
+ const serv = grafserv({ schema, preset });
121
+
122
+ // Mount the request handler into a new HTTP server
123
+ const server = createServer(serv.createHandler());
124
+
125
+ // Start the Node server
126
+ server.listen(preset.server.port ?? 5678);
127
+ ```
128
+
129
+ ### Express V4
130
+
131
+ ```js
132
+ import express from "express";
133
+ import { grafserv } from "grafserv/express/v4";
134
+ import preset from "./graphile.config.mjs";
135
+ import schema from "./schema.mjs";
136
+
137
+ // Create an express app
138
+ const app = express();
139
+ // (Add any Express middleware you want here.)
140
+
141
+ // Create a Grafserv instance
142
+ const serv = grafserv({ schema, preset });
143
+
144
+ // Add the Grafserv instance's route handlers to the Express app
145
+ serv.addTo(app);
146
+
147
+ // Start the Express server
148
+ app.listen(preset.server.port ?? 5678);
149
+ ```
150
+
151
+ ### Koa V2
152
+
153
+ ```js
154
+ import Koa from "koa";
155
+ import { grafserv } from "grafserv/koa/v2";
156
+ import preset from "./graphile.config.mjs";
157
+ import schema from "./schema.mjs";
158
+
159
+ // Create a Koa app
160
+ const app = new Koa();
161
+ // (Add any Koa middleware you want here.)
162
+
163
+ // Create a Grafserv instance
164
+ const serv = grafserv({ schema, preset });
165
+
166
+ // Add the Grafserv instance's route handlers to the Koa app
167
+ serv.addTo(app);
168
+
169
+ // Start the Koa server
170
+ app.listen(preset.server.port ?? 5678);
171
+ ```
172
+
173
+ ### Fastify V4
174
+
175
+ ```js
176
+ import Fastify from "fastify";
177
+ import { grafserv } from "grafserv/fastify/v4";
178
+ import preset from "./graphile.config.mjs";
179
+ import schema from "./schema.mjs";
180
+
181
+ // Create a Koa app
182
+ const app = Fastify({
183
+ logger: true,
184
+ });
185
+ // (Add any Fastify middleware you want here.)
186
+
187
+ // Create a Grafserv instance
188
+ const serv = grafserv({ schema, preset });
189
+
190
+ // Add the Grafserv instance's route handlers to the Fastify app
191
+ serv.addTo(app);
192
+
193
+ // Start the Fastify server
194
+ app.listen({ port: preset.server.port ?? 5678 }, (err, address) => {
195
+ if (err) throw err;
196
+ console.log(`Server is now listening on ${address}`);
197
+ });
198
+ ```
199
+
200
+ ### Next.js API route
201
+
202
+ Grafserv handles a number of API routes, so you should define one for each of
203
+ the things you care about. It's critical that you ensure that the paths line up
204
+ with those used in the Graphile config, otherwise the assets will not correctly
205
+ be served/referenced, this may cause issues when communicating between [Ruru][]
206
+ and GraphQL.
207
+
208
+ ```js
209
+ // utils/grafserv.mjs
210
+ import { grafserv } from "grafserv/next/v13";
211
+ import preset from "./graphile.config.mjs";
212
+ import schema from "./schema.mjs";
213
+
214
+ // Create a shared Grafserv instance
215
+ export const serv = grafserv({ schema, preset });
216
+ ```
217
+
218
+ ```js
219
+ // pages/api/graphql.mjs
220
+ import { serv } from "../../utils/grafserv.mjs";
221
+
222
+ // Create and export the `/graphql` route handler
223
+ const handler = serv.createGraphQLHandler();
224
+ export default handler;
225
+ ```
226
+
227
+ ```js
228
+ // pages/api/ruru.mjs
229
+ import { serv } from "../../utils/grafserv.mjs";
230
+
231
+ // Create and export the `/ruru` route handler
232
+ const handler = serv.createRuruHandler();
233
+ export default handler;
234
+ ```
235
+
236
+ ### Lambda
237
+
238
+ ```js
239
+ import { grafserv } from "grafserv/lambda";
240
+ import preset from "./graphile.config.mjs";
241
+ import schema from "./schema.mjs";
242
+
243
+ // Create a Grafserv instance
244
+ const serv = grafserv({ schema, preset });
245
+
246
+ // Export a lambda handler for GraphQL
247
+ export const handler = serv.createGraphQLHandler();
248
+ ```
@@ -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"}