@softistx/alxia-graphql 0.0.0-stage → 0.19.0

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 (49) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +445 -2
  3. package/dist/bounded-stream.d.ts +37 -0
  4. package/dist/bounded-stream.d.ts.map +1 -0
  5. package/dist/endpoint.d.ts +17 -0
  6. package/dist/endpoint.d.ts.map +1 -0
  7. package/dist/executor.d.ts +49 -0
  8. package/dist/executor.d.ts.map +1 -0
  9. package/dist/explorer.d.ts +24 -0
  10. package/dist/explorer.d.ts.map +1 -0
  11. package/dist/graphql.d.ts +63 -0
  12. package/dist/graphql.d.ts.map +1 -0
  13. package/dist/handler.d.ts +11 -0
  14. package/dist/handler.d.ts.map +1 -0
  15. package/dist/index.d.ts +8 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +621 -0
  18. package/dist/index.js.map +21 -0
  19. package/dist/once-per-request.d.ts +28 -0
  20. package/dist/once-per-request.d.ts.map +1 -0
  21. package/dist/operation.d.ts +3 -0
  22. package/dist/operation.d.ts.map +1 -0
  23. package/dist/options.d.ts +38 -0
  24. package/dist/options.d.ts.map +1 -0
  25. package/dist/removed.d.ts +14 -0
  26. package/dist/removed.d.ts.map +1 -0
  27. package/dist/sandbox.d.ts +15 -0
  28. package/dist/sandbox.d.ts.map +1 -0
  29. package/dist/testing/client.d.ts +95 -0
  30. package/dist/testing/client.d.ts.map +1 -0
  31. package/dist/testing/index.d.ts +2 -0
  32. package/dist/testing/index.d.ts.map +1 -0
  33. package/dist/testing/index.js +73 -0
  34. package/dist/testing/index.js.map +10 -0
  35. package/dist/ws.d.ts +30 -0
  36. package/dist/ws.d.ts.map +1 -0
  37. package/docs/README.md +31 -0
  38. package/docs/guide/context.md +351 -0
  39. package/docs/guide/endpoint.md +293 -0
  40. package/docs/guide/executor.md +75 -0
  41. package/docs/guide/ide.md +160 -0
  42. package/docs/guide/plugins.md +316 -0
  43. package/docs/guide/production.md +374 -0
  44. package/docs/guide/testing.md +171 -0
  45. package/docs/guide/websockets.md +329 -0
  46. package/docs/migrating-to-graxia.md +408 -0
  47. package/docs/roadmap.md +122 -0
  48. package/docs/troubleshooting.md +963 -0
  49. package/package.json +69 -5
@@ -0,0 +1,408 @@
1
+ # Migrating to graxia
2
+
3
+ `@softistx/alxia-graphql` used to mount GraphQL Yoga. It now runs on
4
+ [graxia](https://github.com/softistx/graxia) (`@softistx/graxia`): the same
5
+ `graphql(app, options)` call and the same typed context, on a different
6
+ engine. This is a **breaking** release (a `0.x` minor, so `^0.16` does not take it). Plan it as a migration, not a bump: the
7
+ checklist at the end is the order to follow.
8
+
9
+ ## Why
10
+
11
+ graxia is built for graphql 17 and for a host that owns `Bun.serve`: it ships
12
+ the limits, the caches, the refusal codes, the CSRF check, server-sent events
13
+ and WebSocket itself, so the endpoint no longer depends on Yoga, on the Envelop
14
+ core or on `graphql-ws`. Plugins, errors and the context's shape are graxia's.
15
+
16
+ ## graphql 17 first
17
+
18
+ graphql 16 is no longer supported: move to `graphql@^17.1.0` (and any tool that
19
+ pins 16: codegen, a validation-rule package) before anything else.
20
+
21
+ ```sh
22
+ bun add graphql@^17.1.0
23
+ ```
24
+
25
+ ## Peers
26
+
27
+ | Before | After |
28
+ | --- | --- |
29
+ | `graphql-yoga` | `@softistx/graxia` `^0.15.0` (0.10 sets the HTTP status from errors again) |
30
+ | `graphql-ws` (for `ws`) | nothing: graxia speaks `graphql-transport-ws` |
31
+ | bundled GraphiQL of Yoga | `@softistx/graxia-graphiql` `^0.3.0` (required) |
32
+ | Envelop plugins | not a peer: install `@softistx/graxia-envelop` yourself to use Envelop plugins |
33
+
34
+ `@softistx/graxia-graphiql` peers on exactly one core minor, so install the one that matches:
35
+
36
+ | `@softistx/graxia` | `@softistx/graxia-graphiql` |
37
+ | --- | --- |
38
+ | 0.15 | 0.3.0 |
39
+
40
+ Before the move to the `@softistx` scope, the packages were `@graxia/core` and `@graxia/graphiql`:
41
+ core 0.10 to 0.14 paired with graphiql 0.2.4 to 0.2.8 (one graphiql patch per core minor).
42
+
43
+ ```sh
44
+ bun remove graphql-yoga graphql-ws
45
+ bun add @softistx/graxia @softistx/graxia-graphiql graphql
46
+ ```
47
+
48
+ ## Schema and context
49
+
50
+ `createSchema` comes from `@softistx/graxia` and is **curried**: the type argument
51
+ goes on the first call, the schema on the second.
52
+
53
+ ```ts
54
+ // file: src/schema.ts
55
+ import { alxia } from '@softistx/alxia';
56
+ import type { GraphQLContext } from '@softistx/alxia-graphql';
57
+ import { createSchema } from '@softistx/graxia';
58
+
59
+ const base = alxia().decorate({ greeting: 'hello' });
60
+
61
+ // Before: createSchema<GraphQLContext<typeof base>>({ typeDefs, resolvers })
62
+ export const schema = createSchema<GraphQLContext<typeof base>>()({
63
+ typeDefs: /* GraphQL */ `type Query { hello: String! }`,
64
+ resolvers: { Query: { hello: (_, __, { greeting }) => greeting } },
65
+ });
66
+ ```
67
+
68
+ `resolvers` takes one map or an array of maps, as Yoga's `resolvers: [a, b]`
69
+ did: graxia merges them per type and field, and each map stays checked, so no
70
+ cast is needed. A field defined twice **throws** a `GraxiaConfigError` naming
71
+ `Type.field` at schema build: the order of the maps never decides a conflict
72
+ (Yoga's tools let the last one win). `freshPerMutation` takes the same array
73
+ and returns an array, each map wrapped on its own.
74
+
75
+ `createSchema` also adds the `@cost` and `@listSize` directives (for the
76
+ operation cost) and, unless `incremental: false`, `@defer` and `@stream` to the
77
+ schema (a directive the SDL already declares is kept). A `schema.graphql`
78
+ printed from the Yoga schema, or a snapshot of it, no longer matches: print it
79
+ again from the new schema and commit the result.
80
+
81
+ A schema that graphql's own `graphql()` or `execute()` also runs (a second
82
+ endpoint, a script, a spec that skips graxia) needs `incremental: false`.
83
+ On a schema that declares `@defer` and `@stream`, graphql's `graphql()` and
84
+ `execute()` throw "The provided schema unexpectedly contains experimental
85
+ directives (@defer or @stream)…", so every spec that runs that schema fails
86
+ at once. With `incremental: false` that schema serves no `@defer` or
87
+ `@stream`. See graxia's [schema guide](https://github.com/softistx/graxia/blob/develop/packages/core/docs/guide/schema.md).
88
+
89
+ ```ts
90
+ // file: src/schema-maps.ts
91
+ import { createSchema } from '@softistx/graxia';
92
+
93
+ export const schema = createSchema()({
94
+ typeDefs: /* GraphQL */ `type Query { a: String b: String }`,
95
+ resolvers: [{ Query: { a: () => 'A' } }, { Query: { b: () => 'B' } }],
96
+ });
97
+ ```
98
+
99
+ What a resolver reads changes:
100
+
101
+ - `GraphQLContext` is graxia's `CoreContext` (`signal`, the request's abort
102
+ signal), the app's context, the WebSocket's `connectionParams`, and the
103
+ `context` option's values. Yoga's `request`, `params` and the headers it
104
+ spread into the context are gone: read what the app needs from a middleware
105
+ and the app's context.
106
+ - The `context` option now receives graxia's `{ request, serverContext, signal }`,
107
+ and the app's own values live in `serverContext`. Annotate it, since an
108
+ unannotated argument does not infer:
109
+
110
+ ```ts
111
+ // file: src/schema-context.ts
112
+ import { alxia } from '@softistx/alxia';
113
+ import type { ServerContext } from '@softistx/alxia-graphql';
114
+ import { graphql } from '@softistx/alxia-graphql';
115
+ import { createSchema } from '@softistx/graxia';
116
+
117
+ const base = alxia().decorate({ name: 'ada' });
118
+ const schema = createSchema()({
119
+ typeDefs: /* GraphQL */ `type Query { hello: String! }`,
120
+ resolvers: { Query: { hello: () => 'world' } },
121
+ });
122
+
123
+ export const app = base.plugin((app) =>
124
+ graphql(app, {
125
+ schema,
126
+ // Before: context: ({ name }) => ({ shout: name.toUpperCase() })
127
+ context: ({ serverContext }: { serverContext: ServerContext<(typeof base)['~context']> }) => ({
128
+ shout: serverContext.name.toUpperCase(),
129
+ }),
130
+ }),
131
+ );
132
+ ```
133
+
134
+ See [The typed context](guide/context.md).
135
+
136
+ ## Plugins
137
+
138
+ Yoga plugins no longer run. Write a graxia plugin with `definePlugin`
139
+ (`onContext`, `onParse`, `onValidate` with `addRule`, `onExecute`,
140
+ `onResultChunk`…), and wrap an Envelop plugin with `fromEnvelop`:
141
+
142
+ ```ts
143
+ // file: src/plugins.ts
144
+ import { fromEnvelop } from '@softistx/graxia-envelop';
145
+ import { useDepthLimit } from '@envelop/depth-limit';
146
+
147
+ // Before: plugins: [useDepthLimit({ maxDepth: 8 })]
148
+ export const plugins = [fromEnvelop([useDepthLimit({ maxDepth: 8 })])];
149
+ ```
150
+
151
+ **Janus.** `useJanus()` was a Yoga plugin. Use `@softistx/janus-graphql`
152
+ `^0.37.0` (or later) and its `/graxia` entry, `janusGraxia(options)`, in `plugins`.
153
+ `fromEnvelop` refuses the old plugin at boot, since it relies on Yoga's
154
+ `onResponse` hook; wrapping it is not a way around. If the app renames error
155
+ codes with `mapCode`, pass the same `mapCode` to `janusGraxia` and
156
+ `janusGraxiaMaskError`: from 0.37.0 `janusGraxia` maps the codes of every
157
+ result (janus denials, already-coded errors, each subscription event and
158
+ `@defer` payload), and `janusGraxiaMaskError` those of the errors graxia masks.
159
+ See janus-graphql's
160
+ [graxia guide](https://github.com/softistx/nxgt-janus/blob/develop/packages/janus-graphql/docs/guide/graxia.md).
161
+
162
+ ```diff
163
+ -import { useJanus } from '@softistx/janus-graphql';
164
+ +import { janusGraxia } from '@softistx/janus-graphql/graxia';
165
+ -plugins: [useJanus(options)],
166
+ +plugins: [janusGraxia(options)],
167
+ ```
168
+
169
+ Many Yoga plugins have a graxia option now: depth, aliases and cost limits
170
+ (`limits`), persisted operations (`trustedDocuments`), response masking
171
+ (`maskErrors`), CORS stays in `@softistx/alxia-cors`. See
172
+ [Plugins and options](guide/plugins.md).
173
+
174
+ ## Traps in graxia plugins
175
+
176
+ - **Refuse with `respond`, never `throw`.** In `onRequest` and `onParams`,
177
+ `respond(new Response(null, { status: 401 }))` answers; a `throw` is an
178
+ unexpected failure and answers 500. `onResponse` has no `respond`: it
179
+ replaces the response with `setResponse`.
180
+ - **`respond` stops the plugins after it.** Once a plugin answers with
181
+ `respond`, the later plugins' hooks of that stage do not run. Put the plugins
182
+ that only add headers or record something before the ones that may refuse.
183
+ - **Per-operation checks go in `onParams`.** `onRequest` runs for every
184
+ request that reaches the endpoint, the GraphiQL page's `GET` included, so a
185
+ check there blocks the IDE too.
186
+ - **An after-hook's `result` can be `undefined`.** The function an `onExecute`
187
+ hook returns receives `{ result, setResult }` with `result` typed
188
+ `ExecutionOutput | undefined`: test it before reading it.
189
+ - **`exactOptionalPropertyTypes` and `ResponseInit`.** `headers: undefined` is
190
+ refused, so build the init conditionally:
191
+
192
+ ```ts
193
+ // file: src/refuse.ts
194
+ export const refuse = (headers?: Headers): Response =>
195
+ new Response(null, { status: 401, ...(headers ? { headers } : {}) });
196
+ ```
197
+
198
+ - **`setResult` in the after-hook of `onValidate` is refused.** An Envelop
199
+ plugin (through `@softistx/graxia-envelop`) that calls `setResult` there gets a
200
+ `GraxiaConfigError`, by design. Call `setResult` in `onValidate` itself, or
201
+ add validation rules (`addValidationRule`, or `setValidationFn` to wrap the rules) instead of rewriting the
202
+ result afterwards. See `@softistx/graxia-envelop`'s
203
+ [troubleshooting](https://github.com/softistx/graxia/blob/develop/packages/envelop/docs/troubleshooting.md)
204
+ ("calls setResult in the after-hook of onValidate…") and the hook table of
205
+ its [Envelop guide](https://github.com/softistx/graxia/blob/develop/packages/envelop/docs/guide/envelop.md).
206
+ - **Variable-coercion errors carry `extensions.code: 'BAD_USER_INPUT'`**
207
+ from graxia. Errors graphql raises before any field runs (a bad
208
+ variable, an unknown operation name) are stamped with it when they have no
209
+ code of their own. App code or specs that reshape those errors into a code of
210
+ their own, or assert the old absence of a code, must accept `BAD_USER_INPUT`.
211
+ - **graxia's operation limits are on by default.** `limits` caps `depth` (12),
212
+ `aliases` (30), `directives` (50), `rootFields` (20) and `cost` (5 000). An
213
+ app that already has its own depth, alias, root-field or cost rules (or specs
214
+ that probe their thresholds) turns graxia's off, or aligns the two:
215
+
216
+ ```ts
217
+ // file: src/limits.ts
218
+ import type { OperationLimits } from '@softistx/graxia';
219
+
220
+ // Turn off what the app's own rules already enforce…
221
+ export const off: OperationLimits = {
222
+ depth: false,
223
+ aliases: false,
224
+ rootFields: false,
225
+ directives: false,
226
+ cost: false,
227
+ };
228
+
229
+ // …or keep graxia's and align the numbers.
230
+ export const aligned: OperationLimits = { depth: 8, cost: { max: 2_000 } };
231
+ // Pass one of them as `createGraxia({ …, limits: off })`.
232
+ ```
233
+
234
+ - **A hard-coded `status: 400` on validation refusals is redundant under
235
+ `application/graphql-response+json`.** graxia honours
236
+ `extensions.http.status`, and a validation failure already answers 400 for a
237
+ client that accepts `application/graphql-response+json`; for plain
238
+ `application/json` the unchanged default is 200. Keep an explicit status only
239
+ to force a code for plain JSON clients, and set it as
240
+ `extensions: { http: { status: 400 } }` on the error rather than in a layer
241
+ around the server.
242
+
243
+ ## Options
244
+
245
+ | Option | Now |
246
+ | --- | --- |
247
+ | `maxTokens`, `maxNesting` | `limits: { tokens, nesting }`; the old names still work, marked `@deprecated`, and are removed in the next minor. A bad value is no longer rejected at declaration. |
248
+ | `parseCache` | `caches: { parse: { maxBytes, max, ttlMs } }` or `caches: false`; the old name still maps (`maxBytes`, `max`, `ttl`). |
249
+ | `maskedErrors` | `maskErrors` (the old name still maps, deprecated). Masking is on by default. |
250
+ | `bodyLimit` | still `bodyLimit`, graxia's `limits.bodyBytes`; `0` or a fraction is a `GraxiaConfigError`, also when it comes from an earlier `bodyLimit()` of the app. |
251
+ | `batching` | `batching: true` is 10 operations, or `{ limit }`. |
252
+ | `graphqlEndpoint` | `path`, as before. |
253
+ | `logging`, `requestId`, `cors` | removed, they throw a `TypeError` naming the fix: `onUnexpected` and `@softistx/alxia-logger`, graxia's own `x-request-id`, `@softistx/alxia-cors`. |
254
+ | `sameOrigin()`, `renderSandbox` | removed with no shim: `csrf: { sameOrigin: true }` and `ide: 'apollo-sandbox'`. |
255
+ | `fieldRateLimit`, `limitFromStore` | unchanged names, now graxia plugins. |
256
+
257
+ ## CSRF and client headers
258
+
259
+ graxia's CSRF check is **on by default**. A `GET`, or a `POST` that is not
260
+ `application/json`, is answered `403 CSRF_HEADER_REQUIRED` unless it carries one
261
+ of `x-graphql-csrf`, `graphql-require-preflight`, `apollo-require-preflight` or
262
+ `x-apollo-operation-name`. A JSON `POST` passes. Apollo Client and urql send
263
+ `x-apollo-operation-name` or can be given a header; a hand-written `GET` client
264
+ needs `x-graphql-csrf: 1`. `csrf: { sameOrigin: true }` adds a check of the
265
+ `Origin`; `csrf: false` turns it all off.
266
+
267
+ ## WebSocket
268
+
269
+ `ws: true` (or `{ path?, keepAlive? }`) is unchanged, and graxia serves
270
+ `graphql-transport-ws` itself: remove `graphql-ws` from the server's
271
+ dependencies (clients keep theirs). Subscriptions are also served over
272
+ server-sent events by default, with a keep-alive every 12 seconds. A client
273
+ that offers no subprotocol now gets an HTTP 400 at the upgrade. See
274
+ [GraphQL over WebSocket](guide/websockets.md). Two more differences:
275
+
276
+ - `ws: { keepAlive: 0 }` now throws a `TypeError`: write `keepAlive: false` for
277
+ no pings ([troubleshooting](troubleshooting.md#typeerror-graphqlapp--ws--keepalive-0---keepalive-is-the-milliseconds-between-pings-a-positive-number-up-to-2147483647-or-false-for-none)).
278
+ - A binary frame is refused: the socket closes with `4400`, so send text
279
+ frames ([troubleshooting](troubleshooting.md#a-websocket-closes-with-4400-after-the-first-message)).
280
+ - A subscription sent as a plain JSON `POST` (no `Accept: text/event-stream`)
281
+ is refused with a `SUBSCRIPTION_NOT_SUPPORTED` error whose message names the
282
+ transports that are on. Clients must send `Accept: text/event-stream` or use
283
+ the WebSocket.
284
+
285
+ ### `connectionParams` and client-header checks
286
+
287
+ The payload of `connection_init` is read in the `context` option as
288
+ `init.connectionParams` (`@softistx/graxia` 0.14 types it: no cast; `undefined` over
289
+ HTTP and SSE, and for a socket opened without a payload):
290
+
291
+ ```ts
292
+ // file: src/schema-connection-params.ts
293
+ import { alxia } from '@softistx/alxia';
294
+ import { graphql } from '@softistx/alxia-graphql';
295
+ import { createSchema } from '@softistx/graxia';
296
+
297
+ const schema = createSchema()({
298
+ typeDefs: /* GraphQL */ `type Query { hello: String! }`,
299
+ resolvers: { Query: { hello: () => 'world' } },
300
+ });
301
+
302
+ export const app = alxia().plugin((app) =>
303
+ graphql(app, {
304
+ schema,
305
+ context: ({ connectionParams, request }) => ({
306
+ token:
307
+ typeof connectionParams?.['token'] === 'string'
308
+ ? connectionParams['token']
309
+ : (request.headers.get('authorization') ?? undefined),
310
+ }),
311
+ }),
312
+ );
313
+ ```
314
+
315
+ The trap: a plugin's `onParams` hook also runs for every WebSocket operation,
316
+ and a browser's upgrade request carries no custom header, so a client-header
317
+ check there refuses every socket operation. Skip the socket operations with
318
+ `if (connectionParams) return`, which `onParams` receives only for an operation
319
+ over a WebSocket. Never test the `Upgrade` header: over HTTP it can be forged.
320
+ See graxia's [WebSocket guide](https://github.com/softistx/graxia/blob/develop/packages/core/docs/guide/websocket.md#header-checks-in-onparams)
321
+ and the [troubleshooting entry](troubleshooting.md#every-websocket-operation-is-refused-by-a-client-header-check).
322
+
323
+ ## IDE
324
+
325
+ GraphiQL comes from `@softistx/graxia-graphiql`, a required peer; `ide`, `graphiql` and
326
+ `sandbox` keep their names, and `ide: 'apollo-sandbox'` replaces
327
+ `renderSandbox`. See [GraphiQL and Apollo Sandbox](guide/ide.md).
328
+
329
+ ## Errors and refusal codes
330
+
331
+ - Errors are always masked. Throw `exposedError(code, message)` from
332
+ `@softistx/graxia` (or a `GraphQLError`) for what a client may read.
333
+ - `extensions.http.status` and `extensions.http.headers` on an error set the
334
+ HTTP response again, as under Yoga (`@softistx/graxia` 0.10, graxia#147), for a
335
+ single operation answered as plain JSON. The first event of a subscription
336
+ refused before its stream opens honours it too, from `@softistx/graxia` 0.11.0:
337
+ the answer is an event-stream response carrying the status and headers;
338
+ `spec: true` drops the status there, as in Yoga. `errorHttp: false` turns it off:
339
+ the media type decides and `extensions` are untouched. The app's layers still
340
+ answer an auth error before.
341
+ - Server code reading `error.extensions['http']` needs index access once
342
+ Yoga's `http` augmentation is gone (with `noPropertyAccessFromIndexSignature`).
343
+
344
+ ```ts
345
+ // file: src/error-http.ts
346
+ import { type ErrorHttp, exposedError } from '@softistx/graxia';
347
+
348
+ export const taken = () =>
349
+ exposedError('CONFLICT', 'Email taken.', {
350
+ extensions: { http: { status: 409 } satisfies ErrorHttp },
351
+ }); // HTTP 409; http is stripped from the response
352
+ ```
353
+ - A refusal has a code: `BODY_TOO_LARGE` (413), `UNSUPPORTED_MEDIA_TYPE` (415),
354
+ `QUERY_REQUIRED` (400), `METHOD_NOT_ALLOWED` (405, a mutation over `GET`),
355
+ `NOT_ACCEPTABLE` (406), `CSRF_HEADER_REQUIRED` (403). Yoga's `BAD_REQUEST`
356
+ and its messages are gone: match the code, never the message. The type is
357
+ `GraxiaErrorCode`.
358
+
359
+ See [Troubleshooting](troubleshooting.md).
360
+
361
+ ## Executor and the test client
362
+
363
+ `graphqlExecutor(options)` and `graphqlClient(app)` keep their signatures. The
364
+ executor runs the same graxia as the route, with the CSRF check off (there is
365
+ no browser request to forge); a subscription is still answered
366
+ `SUBSCRIPTION_NOT_SUPPORTED` ([troubleshooting](troubleshooting.md#subscriptions-are-not-supported-over-this-transport-subscriptionssse-is-false)). A call whose `signal` is aborted does not reject:
367
+ it resolves to `{ errors: [{ message: 'The operation was aborted.', extensions: { code: 'OPERATION_ABORTED' } }] }`
368
+ with no `data` ([troubleshooting](troubleshooting.md#the-operation-was-aborted-from-graphqlexecutor)). See [Running operations in process](guide/executor.md)
369
+ and [Testing the endpoint](guide/testing.md). The executor holds a graxia instance: `await executor.dispose()` when done.
370
+
371
+ ## What stays the same
372
+
373
+ `graphql(app, options)` and its place in the chain, `path` under the app's
374
+ prefix, `GraphQLContext<typeof app>`, `oncePerRequest`, `freshPerMutation`,
375
+ `boundedStream`, `fieldRateLimit`, `health()` probes and the graceful shutdown,
376
+ `bodyLimit` and its 1 MiB default, and the telemetry through
377
+ `@softistx/alxia-telemetry`.
378
+
379
+ ## Checklist
380
+
381
+ 1. Move to `graphql@^17.1.0`.
382
+ 2. Swap the peers: remove `graphql-yoga` and `graphql-ws`, add `@softistx/graxia`,
383
+ `@softistx/graxia-graphiql`; add `@softistx/graxia-envelop` only to use Envelop plugins.
384
+ 3. Import `createSchema` from `@softistx/graxia` and curry it: `createSchema<Ctx>()({ … })`;
385
+ pass several resolver maps as an array, not a cast; print `schema.graphql`
386
+ again (graxia adds `@cost`, `@listSize` and, unless `incremental: false`,
387
+ `@defer`, `@stream`); build with `incremental: false` a schema that
388
+ graphql's plain `graphql()` or `execute()` also runs.
389
+ 4. Annotate the `context` option's argument with `ServerContext`, and read the
390
+ app's values from `serverContext`.
391
+ 5. Rewrite each Yoga plugin (`definePlugin`) or wrap it (`fromEnvelop`), the
392
+ plugins that only add headers before the ones that `respond`.
393
+ 6. Rename `maxTokens`, `maxNesting`, `parseCache` and `maskedErrors` to
394
+ `limits`, `caches` and `maskErrors`.
395
+ 7. Replace `sameOrigin()`, `renderSandbox`, `logging`, `requestId` and `cors`.
396
+ 8. Send a CSRF header from every client that uses `GET` or a non-JSON `POST`.
397
+ 9. Match refusals by their code, not by Yoga's messages.
398
+ 10. Write `ws: { keepAlive: false }` instead of `keepAlive: 0`, send text frames
399
+ over WebSocket, send subscriptions with `Accept: text/event-stream` (or over
400
+ WebSocket), and read `OPERATION_ABORTED` from an aborted executor call.
401
+ 11. Call `await executor.dispose()` when a `graphqlExecutor` is done (a spec's
402
+ `afterAll`, a job's shutdown).
403
+ 12. Replace `setResult` in an `onValidate` after-hook, accept
404
+ `extensions.code: 'BAD_USER_INPUT'` on variable errors, turn off or align
405
+ graxia's default `limits` with the app's own, and drop a redundant
406
+ hard-coded `status: 400`.
407
+ 13. Run the app's specs, then `graphqlClient` against a few refusals (an
408
+ oversized body, a mutation over `GET`, a missing header).
@@ -0,0 +1,122 @@
1
+ # Roadmap
2
+
3
+ What `@softistx/alxia-graphql` gives an app, and what is coming. This page is a
4
+ direction, not a commitment: the version something shipped in is the only
5
+ number on it. Every release, with each change it made, is in
6
+ [`CHANGELOG.md`](https://github.com/softistx/alxia/blob/develop/packages/graphql/CHANGELOG.md).
7
+
8
+ ## Now
9
+
10
+ - **Moving to the `@softistx` scope.** The package is now `@softistx/alxia-graphql` (it was `@alxia/graphql`). Same code and API; replace the dependency and the imports ([migration guide](https://github.com/softistx/alxia/blob/develop/packages/core/docs/guide/migrating-from-alxia-scope.md)). The old name is deprecated.
11
+
12
+ ## Next
13
+
14
+ ## Later
15
+
16
+ - **A configurable WebSocket message limit.** A `subscribe` message over the
17
+ socket is bounded by Bun's `maxPayloadLength` (16 MiB by default), not by
18
+ `bodyLimit`. A `ws` option would set the limit the way `bodyLimit` does
19
+ for a `POST`.
20
+
21
+ ## Shipped
22
+
23
+ ### Unreleased
24
+
25
+ - **graxia 0.10.** `@graxia/core` `^0.10.0` (and `@graxia/graphiql` `^0.2.4`) is the peer floor: an error's `extensions.http.status` and headers set the HTTP response again, as under Yoga, and `errorHttp: false` turns it off. `freshPerMutation` takes the array of resolver maps `createSchema` accepts and returns it as an array. A field defined twice across maps throws (graxia's rule, not last wins). The migration guide covers `janusGraxia` and `extensions['http']`.
26
+ - **Runs on graxia.** `@alxia/graphql` serves the endpoint with `@graxia/core` (0.10) instead of graphql-yoga: graxia's plugins (and Envelop's through `@graxia/envelop`), limits, caches, refusal codes, CSRF check, server-sent events and WebSocket, and `@graxia/graphiql` for the IDE. A breaking release: see [Migrating to graxia](migrating-to-graxia.md).
27
+ - **Two temporary workarounds dropped.** graxia 0.8.0 ships `telemetry.operationSpans: false` (graxia#137) and hands a plugin the `serverContext` at validation (graxia#135), so `graphql()` sets `telemetry: { operationSpans: false }` and a validation failure over a socket reaches its observers natively; a throwing subscription source is seen by `onResultChunk` too (graxia#136).
28
+ - **Body limit and refusal codes from graxia.** `bodyLimit` is graxia's `limits.bodyBytes`: a body past it is a `413` with `extensions.code: 'BODY_TOO_LARGE'`, a form or `application/graphql` body a `415 UNSUPPORTED_MEDIA_TYPE`, and every refusal graxia builds has a stable code (`GraxiaErrorCode` is re-exported as a type); `@graxia/core` `^0.9.0` was the peer floor (now `^0.10.0`) ([guide](guide/production.md#cap-what-a-request-costs)).
29
+ - **`sameOrigin()` removed.** The Yoga-era plugin is gone with no shim: a cookie-authenticated endpoint uses graxia's `csrf: { sameOrigin: true }` (a foreign `Origin` is refused), beside the CSRF header check that is on by default ([guide](guide/production.md#csrf-for-a-cookie-authenticated-api)).
30
+ - **`fieldRateLimit`.** A graxia plugin that counts every selection of chosen fields (aliases and fragments expanded) and consumes that cost on a limit keyed by the client, answering a 429 `RATE_LIMITED` (or the `code` you pass) with `retryAfter`, the client grouped by its IPv6 network under `ipv6Prefix`; `limitFromStore` adapts an `@alxia/rate-limit` store, `single` refuses a field written twice ([guide](guide/production.md#count-a-field-not-a-request)).
31
+ - **`graphqlExecutor(options)`.** A query or a mutation run in process through the same graxia setup as `graphql()` (plugins, token and nesting limits, parse cache, error masking), with a server context the caller gives, for an MCP tool or a job ([guide](guide/executor.md)).
32
+
33
+ ### 0.9.2
34
+
35
+ - **A declared oversize body refused where `bodyLimit()` stands.** With
36
+ `@alxia/core` 0.16.0, a `Content-Length` past the limit is refused at the
37
+ app's `bodyLimit()`, before the middlewares after it, and the endpoint
38
+ leaves an inherited limit there. The endpoint's own `bodyLimit` option, or
39
+ the 1 MiB default, refuses at the head of the endpoint's steps. A chunked
40
+ body is still refused at the read, with Yoga's headers.
41
+
42
+ ### 0.9.0
43
+
44
+ - **Bounded parsing.** A document may hold 15 000 tokens (`maxTokens`, `false`
45
+ to opt out); a longer one is refused as `GRAPHQL_PARSE_FAILED`. The parse
46
+ cache is bounded by weight, 64 MiB per endpoint (`parseCache`), in place of
47
+ Yoga's, which has no size bound. A `POST` body may hold 1 MiB (`bodyLimit`)
48
+ unless the app declared its own limit; the 413 keeps the headers Yoga's
49
+ plugins set and logs nothing. A query over 15 000 tokens and an upload past
50
+ 1 MiB need an option ([production guide](guide/production.md#cap-what-a-request-costs)).
51
+
52
+ ### 0.8.0
53
+
54
+ - **`GET` and persisted operations in the test client.** `graphqlClient`
55
+ sends `method: 'GET'` with the operation in the URL, and `persisted`, the
56
+ hash of a registered operation, with no document, so an app that allows
57
+ nothing else can be tested; it adds no CSRF header of its own ([testing guide](guide/testing.md#persisted-operations)).
58
+
59
+ ### 0.7.0
60
+
61
+ - **A test client.** `graphqlClient(app)` from `@alxia/graphql/testing`
62
+ sends a query, its variables and headers to the endpoint in process, and
63
+ returns `{ status, data, errors, response }`; a `TypedDocumentNode` types
64
+ the answer; `app` is anything with a `fetch(Request)` ([testing guide](guide/testing.md)).
65
+
66
+ ### 0.6.0
67
+
68
+ - **Each operation over a socket.** Over `ws: true`, every query, mutation and subscription on a socket is told to the observers around its upgrade, from its `subscribe` message to its end, with whether it was answered with errors: `@alxia/logger` writes a line for each, `@alxia/telemetry` a span, a child of the upgrade's, named `subscription OnNote` ([WebSocket guide](guide/websockets.md#logging-and-tracing)).
69
+
70
+ ### 0.5.0
71
+
72
+ - **The operation, told to the observers.** Each operation the endpoint executes is reported to the middlewares around it: `@alxia/logger` writes `operationName` and `operationType` on the request's line, `@alxia/telemetry` names its span `query GetNotes` with `graphql.operation.name` and `graphql.operation.type`. A batched body is one line and one span, `batch`, with every name ([endpoint guide](guide/endpoint.md#the-operation-in-the-log-and-the-trace)).
73
+
74
+ ### 0.4.0
75
+
76
+ - **GraphQL over WebSocket.** `ws: true` serves the endpoint over
77
+ WebSocket too, with the `graphql-transport-ws` protocol of `graphql-ws`
78
+ — Apollo Client's and urql's default — beside server-sent events: the
79
+ upgrade runs the app's middlewares, so a guard refuses the socket and a
80
+ resolver reads what they added; each operation runs through Yoga's
81
+ plugins, with the client's `connectionParams` in its context; a
82
+ shutdown closes the sockets with 1001 and completes their subscriptions
83
+ ([WebSocket guide](guide/websockets.md)).
84
+
85
+ ### 0.3.0
86
+
87
+ - **GraphiQL in dev alone, under a pinned policy.** Without `ide`, a
88
+ browser gets GraphiQL only while the serving app is in dev
89
+ (`NODE_ENV=development`, or `alxia({ dev: true })`); `ide: 'graphiql'`
90
+ serves it everywhere. Its `Content-Security-Policy` allows the one
91
+ pinned `@graphql-yoga/graphiql` folder it loads from, the Monaco workers
92
+ included, and no frame ([IDE guide](guide/ide.md)).
93
+ - **Subscriptions drained on shutdown.** When the app starts shutting
94
+ down — `SIGTERM`, `SIGINT`, `stop()` — a subscription over server-sent
95
+ events ends, so `@alxia/core`'s drain answers the queries in flight and
96
+ exits without waiting for it; `health()` probes mount beside the
97
+ endpoint, and GraphQL errors stay in `errors[]` under core's problem
98
+ details ([endpoint guide](guide/endpoint.md#errors-health-and-shutdown)).
99
+
100
+ ### 0.1.0
101
+
102
+ - **GraphQL Yoga as a route.** `graphql(app, options)` serves a schema at
103
+ `GET` and `POST` `/graphql`, or any `path`, under the app's prefix and
104
+ the prefix of every app it is mounted into. The endpoint runs behind the
105
+ app's middlewares like any route: a guard given to `use` before it guards it, and its
106
+ reply is part of the endpoint's type.
107
+ - **The app's context in every resolver, typed and checked.**
108
+ `GraphQLContext<typeof app>` types a schema with Yoga's context and
109
+ everything the app's middlewares add — a user, a database handle — plus `set`,
110
+ through which a resolver sets a header or a cookie. A schema whose
111
+ resolvers read what the app does not build is a compile error naming the
112
+ missing field, and `GraphQLContext` of anything but an app is a message
113
+ that fails the first resolver reading a field.
114
+ - **Yoga whole.** Every Yoga option passes through: its plugins and
115
+ Envelop's, the `context` factory, error masking, batching, logging.
116
+ Subscriptions are served over server-sent events.
117
+ - **An IDE, or none.** A browser at the endpoint gets Yoga's GraphiQL by
118
+ default, or Apollo Sandbox pointed at the address it was opened at —
119
+ `https` behind a proxy that terminates TLS — each with
120
+ a `Content-Security-Policy` that lets it load; `ide: false` turns it off.
121
+ - **CORS left to the app.** Yoga's own CORS is off, so `@alxia/cors`
122
+ answers for the whole app, the endpoint included.