@alxia/graphql 0.14.0 → 0.15.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.
- package/README.md +53 -0
- package/dist/field-rate-limit/count.d.ts +28 -0
- package/dist/field-rate-limit/count.d.ts.map +1 -0
- package/dist/field-rate-limit/from-store.d.ts +21 -0
- package/dist/field-rate-limit/from-store.d.ts.map +1 -0
- package/dist/field-rate-limit/index.d.ts +5 -0
- package/dist/field-rate-limit/index.d.ts.map +1 -0
- package/dist/field-rate-limit/ipv6-network.d.ts +8 -0
- package/dist/field-rate-limit/ipv6-network.d.ts.map +1 -0
- package/dist/field-rate-limit/plugin.d.ts +28 -0
- package/dist/field-rate-limit/plugin.d.ts.map +1 -0
- package/dist/field-rate-limit/types.d.ts +60 -0
- package/dist/field-rate-limit/types.d.ts.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +259 -3
- package/dist/index.js.map +8 -4
- package/dist/sandbox.d.ts +1 -1
- package/docs/README.md +1 -1
- package/docs/guide/production.md +82 -1
- package/docs/roadmap.md +1 -0
- package/docs/troubleshooting.md +65 -0
- package/package.json +7 -6
package/README.md
CHANGED
|
@@ -290,6 +290,56 @@ where `graphql()` is declared.
|
|
|
290
290
|
A client query is a few thousand tokens; the introspection query is 163. See
|
|
291
291
|
[Cap what a request costs](https://github.com/softistx/alxia/blob/develop/packages/graphql/docs/guide/production.md#cap-what-a-request-costs).
|
|
292
292
|
|
|
293
|
+
## Count a field, not a request
|
|
294
|
+
|
|
295
|
+
A limit on HTTP requests counts one request however many times it selects
|
|
296
|
+
`signIn` under aliases (`a: signIn(...) b: signIn(...) …`). `fieldRateLimit`
|
|
297
|
+
is a Yoga plugin that walks the operation about to run, aliases, inline
|
|
298
|
+
fragments and fragment spreads expanded, and consumes the number of
|
|
299
|
+
selections of each chosen field on a limit keyed by the client. Past the
|
|
300
|
+
limit nothing executes: a 429 `RATE_LIMITED` (the `code` option names it
|
|
301
|
+
otherwise, `TOO_MANY_ATTEMPTS` say) with `extensions.retryAfter` (seconds) and
|
|
302
|
+
a `Retry-After` header. List it first in `plugins`.
|
|
303
|
+
|
|
304
|
+
```ts
|
|
305
|
+
import { alxia } from '@alxia/core';
|
|
306
|
+
import { MemoryStore } from '@alxia/rate-limit';
|
|
307
|
+
import { fieldRateLimit, graphql, limitFromStore } from '@alxia/graphql';
|
|
308
|
+
import { schema } from './schema';
|
|
309
|
+
|
|
310
|
+
const store = new MemoryStore();
|
|
311
|
+
|
|
312
|
+
graphql(alxia(), {
|
|
313
|
+
schema,
|
|
314
|
+
plugins: [
|
|
315
|
+
fieldRateLimit({
|
|
316
|
+
// Optional: who is counted. The client's address by default, and
|
|
317
|
+
// ipv6Prefix: 64 counts an IPv6 client by its network.
|
|
318
|
+
// key: ({ ip }) => ip,
|
|
319
|
+
fields: {
|
|
320
|
+
signIn: { limit: limitFromStore(store, { limit: 5, windowMs: 60_000 }), single: true },
|
|
321
|
+
},
|
|
322
|
+
}),
|
|
323
|
+
],
|
|
324
|
+
});
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
A limit is anything with `consume(key, cost)` answering `{ allowed,
|
|
328
|
+
retryAfter }` (milliseconds): `limitFromStore` makes one of an
|
|
329
|
+
`@alxia/rate-limit` store, one store call per unit of cost (up to `limit + 1`
|
|
330
|
+
round trips), and a `@softistx/redis` bound limit, which takes the cost in
|
|
331
|
+
one call and suits a large limit, fits as
|
|
332
|
+
`{ consume: async (key, cost) => limit.consume({ ip: key }, cost) }` (`limit`
|
|
333
|
+
is the entry of your wired Redis handle). Units spent before a refusal stay
|
|
334
|
+
spent, and so do the fields charged before a refused one. `single: true`
|
|
335
|
+
refuses the field written more than once in the document (400
|
|
336
|
+
`FIELD_SELECTED_ONCE`), counting a selection written the same way twice as
|
|
337
|
+
one. Counting is per selection in the document: a list parent costs 1,
|
|
338
|
+
`@skip` and `@include` are not evaluated, and a field matches by name on any
|
|
339
|
+
type. Under `batching` a refused element is an error in a 200 array, with no
|
|
340
|
+
`Retry-After`. See
|
|
341
|
+
[Count a field, not a request](https://github.com/softistx/alxia/blob/develop/packages/graphql/docs/guide/production.md#count-a-field-not-a-request).
|
|
342
|
+
|
|
293
343
|
## Errors, health and shutdown
|
|
294
344
|
|
|
295
345
|
A GraphQL error stays GraphQL's — an entry of `errors[]`, inside a 200 —
|
|
@@ -368,6 +418,9 @@ See
|
|
|
368
418
|
| `oncePerRequest(request, key, load)` | `load()`'s value, computed at most once per request object and `key` (a `string`); returns `T`, a promise kept as the same promise, a throw or rejection not kept |
|
|
369
419
|
| `clearRequestCache(request)` | empties what `oncePerRequest` kept for that request object; the next call loads again; returns `void` |
|
|
370
420
|
| `freshPerMutation(resolvers)` | the same resolvers (same type) with each function of `Mutation` wrapped to call `clearRequestCache(context)` first: each root mutation field starts empty, its sub-fields share, a query is untouched |
|
|
421
|
+
| `fieldRateLimit({ fields, key?, ipv6Prefix?, code? })` | a Yoga plugin, listed first: consumes the number of selections (aliases and fragments expanded) of each chosen field on its limit, keyed by `key(context)` (the client address by default, its IPv6 network under `ipv6Prefix`); 429 `RATE_LIMITED` (`code`) with `retryAfter`, or 400 `FIELD_SELECTED_ONCE` for a `single` field; units spent before a refusal stay spent |
|
|
422
|
+
| `limitFromStore(store, policy?)` | an `@alxia/rate-limit` store as a `FieldLimit`: one consume per unit of cost, stopped at the first refusal (up to `limit + 1` round trips); `policy` may come from `store.policy` and must not differ from it |
|
|
423
|
+
| `FieldLimit`, `FieldDecision`, `FieldRule`, `FieldRateLimitOptions`, `CostlessStore` | their types |
|
|
371
424
|
| `boundedStream(source, options)` | `source` (an `AsyncIterable` or `AsyncIterator`) as an `AsyncIterableIterator<T>` for a subscription's `subscribe`: ends cleanly after `idleMs` without an event and `totalMs` in all, runs `check` every `checkEveryMs` and before an event when the last check is `checkDebounceMs` old, throws `mapError(error)` when `check` fails or the source itself throws, and calls the source's `return()` on disconnect or any end |
|
|
372
425
|
| `BoundedStreamOptions` | its options: `idleMs`, `totalMs`, `checkEveryMs`, `checkDebounceMs?`, `check`, `mapError?`, `signal?` |
|
|
373
426
|
| `ServerContext<Ctx>`, `GraphQLOptions` | its types |
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type DocumentNode, type SelectionSetNode } from 'graphql';
|
|
2
|
+
/** How a field was selected: how many times, and under how many distinct response keys and arguments. */
|
|
3
|
+
export interface Selected {
|
|
4
|
+
count: number;
|
|
5
|
+
readonly distinct: Set<string>;
|
|
6
|
+
}
|
|
7
|
+
type Counts = Map<string, Selected>;
|
|
8
|
+
/**
|
|
9
|
+
* `distinct` only has to tell one path from two or more (`single`), so it is
|
|
10
|
+
* built for the `singles` alone and holds at most 2 paths. That is sound: a
|
|
11
|
+
* set of 2 or more distinct relative paths stays that after any prefix; a
|
|
12
|
+
* union of sets cut to 2 has 2 or more elements whenever the true union does
|
|
13
|
+
* (one input already has 2, or all have at most 1 and are exact). A document
|
|
14
|
+
* whose fragments fan out (`{ x: y { ...F1 } z: y { ...F1 } }` down forty
|
|
15
|
+
* levels) has 2^40 paths, and costs a few set entries here.
|
|
16
|
+
*
|
|
17
|
+
* How many times each of `names` is selected by `selections`, fragments
|
|
18
|
+
* expanded. Counted per selection in the document, as written: a list
|
|
19
|
+
* parent costs 1 however long the list, `@skip` and `@include` are not
|
|
20
|
+
* evaluated, selections that merge at execution (the same alias twice) still
|
|
21
|
+
* count each, and a field matches by name alone, on any type. A fragment is
|
|
22
|
+
* walked once, so a document whose fragments spread each other many times
|
|
23
|
+
* is counted in linear time. `distinct` holds each selection's response key
|
|
24
|
+
* and arguments, so a field written twice the same way is one, under the same parents (the response keys and arguments above it).
|
|
25
|
+
*/
|
|
26
|
+
export declare function countSelections(document: DocumentNode, selections: SelectionSetNode, names: ReadonlySet<string>, singles?: ReadonlySet<string>): Counts;
|
|
27
|
+
export {};
|
|
28
|
+
//# sourceMappingURL=count.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"count.d.ts","sourceRoot":"","sources":["../../src/field-rate-limit/count.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,YAAY,EAGjB,KAAK,gBAAgB,EACrB,MAAM,SAAS,CAAC;AAEjB,yGAAyG;AACzG,MAAM,WAAW,QAAQ;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CAC/B;AAED,KAAK,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AAEpC;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,eAAe,CAC9B,QAAQ,EAAE,YAAY,EACtB,UAAU,EAAE,gBAAgB,EAC5B,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,EAC1B,OAAO,GAAE,WAAW,CAAC,MAAM,CAAa,GACtC,MAAM,CA8DR"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { CostlessStore, FieldLimit } from './types';
|
|
2
|
+
interface Given {
|
|
3
|
+
readonly limit?: number;
|
|
4
|
+
readonly windowMs?: number;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* A `@alxia/rate-limit` store as a `FieldLimit`. The store counts one hit
|
|
8
|
+
* per call, so a cost of N is N consumes, stopped at the first refusal: up
|
|
9
|
+
* to `limit + 1` round trips for one selection count, which a Redis-backed
|
|
10
|
+
* store feels. The units spent before a refusal stay spent. For a large
|
|
11
|
+
* limit, give `fieldRateLimit` a limit that takes the cost in one call (a
|
|
12
|
+
* `@softistx/redis` bound limit).
|
|
13
|
+
*
|
|
14
|
+
* `policy` may be left out for a store that declares its own (`store.policy`,
|
|
15
|
+
* as `redisStore` of a wired limit does); numbers that differ from the
|
|
16
|
+
* store's are an error here, as in `rateLimit`. `limit` and `windowMs` are
|
|
17
|
+
* whole numbers of 1 or more.
|
|
18
|
+
*/
|
|
19
|
+
export declare function limitFromStore(store: CostlessStore, policy?: Given): FieldLimit;
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=from-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"from-store.d.ts","sourceRoot":"","sources":["../../src/field-rate-limit/from-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAEzD,UAAU,KAAK;IACd,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAC7B,KAAK,EAAE,aAAa,EACpB,MAAM,CAAC,EAAE,KAAK,GACZ,UAAU,CA8BZ"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { countSelections } from './count';
|
|
2
|
+
export { limitFromStore } from './from-store';
|
|
3
|
+
export { DEFAULT_LIMIT_CODE, fieldRateLimit } from './plugin';
|
|
4
|
+
export type { CostlessStore, FieldDecision, FieldLimit, FieldRateLimitOptions, FieldRule, } from './types';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/field-rate-limit/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC9D,YAAY,EACX,aAAa,EACb,aAAa,EACb,UAAU,EACV,qBAAqB,EACrB,SAAS,GACT,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The network of an IPv6 `address` under `prefix` bits, as `2001:db8:1:2::/64`
|
|
3
|
+
* writes it. An IPv4-mapped address (`::ffff:203.0.113.9`) is its IPv4 address,
|
|
4
|
+
* a zone id (`%eth0`) is dropped, and a text that is not an IPv6 address
|
|
5
|
+
* (an IPv4 one included) is returned as it is.
|
|
6
|
+
*/
|
|
7
|
+
export declare function ipv6Network(address: string, prefix: number): string;
|
|
8
|
+
//# sourceMappingURL=ipv6-network.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ipv6-network.d.ts","sourceRoot":"","sources":["../../src/field-rate-limit/ipv6-network.ts"],"names":[],"mappings":"AAsEA;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAenE"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Plugin } from 'graphql-yoga';
|
|
2
|
+
import type { FieldRateLimitOptions } from './types';
|
|
3
|
+
/** The `extensions.code` of an over-limit refusal, unless `code` says otherwise. */
|
|
4
|
+
export declare const DEFAULT_LIMIT_CODE = "RATE_LIMITED";
|
|
5
|
+
/**
|
|
6
|
+
* A Yoga plugin that counts every selection of the chosen fields in the
|
|
7
|
+
* operation about to execute (aliases and fragments included) and consumes
|
|
8
|
+
* that cost on each field's limit, keyed by the client. Past a limit the
|
|
9
|
+
* operation does not run: a 429 with `extensions.code` `RATE_LIMITED`
|
|
10
|
+
* (the `code` option; `TOO_MANY_ATTEMPTS` for a sign-in, say) and `retryAfter` (seconds, also the `Retry-After`
|
|
11
|
+
* header). `{ limit, single: true }` refuses the field selected more than
|
|
12
|
+
* once in the document with a 400 `FIELD_SELECTED_ONCE`, a field written the
|
|
13
|
+
* same way twice (same parents, response key and arguments) counting once.
|
|
14
|
+
*
|
|
15
|
+
* The check runs in `onExecute` itself, so a plugin after it that replaces
|
|
16
|
+
* the execute function does not drop it; still, list it first in
|
|
17
|
+
* `graphql({ plugins })`. Fields are charged in the order the document first selects them: units spent
|
|
18
|
+
* on one field before a refusal stay spent, and so do earlier fields when a
|
|
19
|
+
* later one is refused. Subscriptions are not counted. Under `batching` each
|
|
20
|
+
* operation is checked on its own, and a refused one is an error in a 200
|
|
21
|
+
* array, with no `Retry-After` header.
|
|
22
|
+
*
|
|
23
|
+
* ```ts
|
|
24
|
+
* fieldRateLimit({ fields: { signIn: limitFromStore(store, { limit: 5, windowMs: 60_000 }) } })
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare function fieldRateLimit<Ctx extends object = any>(options: FieldRateLimitOptions<Ctx>): Plugin;
|
|
28
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/field-rate-limit/plugin.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAG3C,OAAO,KAAK,EAAc,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAEjE,oFAAoF;AACpF,eAAO,MAAM,kBAAkB,iBAAiB,CAAC;AA+EjD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,cAAc,CAAC,GAAG,SAAS,MAAM,GAAG,GAAG,EACtD,OAAO,EAAE,qBAAqB,CAAC,GAAG,CAAC,GACjC,MAAM,CA8DR"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/** What a limit answers: allowed or not, and, when not, the delay until it would be, in milliseconds. */
|
|
2
|
+
export interface FieldDecision {
|
|
3
|
+
readonly allowed: boolean;
|
|
4
|
+
readonly retryAfter: number;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Where selections are counted: anything that consumes `cost` for `key`.
|
|
8
|
+
* A `@softistx/redis` bound limit (`limit`, from the app's wired Redis
|
|
9
|
+
* handle) fits through `{ consume: (key, cost) => limit.consume({ ip: key },
|
|
10
|
+
* cost) }`; a `@alxia/rate-limit` store, through `limitFromStore`.
|
|
11
|
+
*
|
|
12
|
+
* A limit that takes the cost in one call (as the Redis one does) is the
|
|
13
|
+
* right one for a large limit: `limitFromStore` makes one store call per unit.
|
|
14
|
+
*/
|
|
15
|
+
export interface FieldLimit {
|
|
16
|
+
consume(key: string, cost: number): FieldDecision | Promise<FieldDecision>;
|
|
17
|
+
}
|
|
18
|
+
/** A field's rule: a limit, or a limit with `single`, which refuses the field selected more than once in the document. */
|
|
19
|
+
export type FieldRule = FieldLimit | {
|
|
20
|
+
readonly limit: FieldLimit;
|
|
21
|
+
readonly single?: boolean;
|
|
22
|
+
};
|
|
23
|
+
export interface FieldRateLimitOptions<Ctx extends object = any> {
|
|
24
|
+
/** The fields to count, by name (at any depth), each with its limit. */
|
|
25
|
+
readonly fields: Readonly<Record<string, FieldRule>>;
|
|
26
|
+
/**
|
|
27
|
+
* Who is counted, from the context (`ip`, `request`, the app's own);
|
|
28
|
+
* `undefined` counts nothing. The client's address (`ctx.ip`) by default,
|
|
29
|
+
* grouped by `ipv6Prefix`. Not required: leave it out to count by address.
|
|
30
|
+
*/
|
|
31
|
+
readonly key?: (ctx: Ctx) => string | undefined | Promise<string | undefined>;
|
|
32
|
+
/**
|
|
33
|
+
* Count an IPv6 client by its network: the first `ipv6Prefix` bits of the
|
|
34
|
+
* default key, as `rateLimit`'s option of the same name does (a whole number
|
|
35
|
+
* from 0 to 128; none by default, so each address counts apart). Goes with
|
|
36
|
+
* the default key: with a `key` of your own, group the address in it.
|
|
37
|
+
*/
|
|
38
|
+
readonly ipv6Prefix?: number;
|
|
39
|
+
/** The `extensions.code` of the over-limit refusal; `RATE_LIMITED` by default (`TOO_MANY_ATTEMPTS`, say, for a sign-in). */
|
|
40
|
+
readonly code?: string;
|
|
41
|
+
}
|
|
42
|
+
/** The part of a `@alxia/rate-limit` `RateLimitStore` that `limitFromStore` uses. */
|
|
43
|
+
export interface CostlessStore {
|
|
44
|
+
consume(key: string, policy: {
|
|
45
|
+
readonly limit: number;
|
|
46
|
+
readonly windowMs: number;
|
|
47
|
+
}): {
|
|
48
|
+
readonly allowed: boolean;
|
|
49
|
+
readonly retryAfter: number;
|
|
50
|
+
} | Promise<{
|
|
51
|
+
readonly allowed: boolean;
|
|
52
|
+
readonly retryAfter: number;
|
|
53
|
+
}>;
|
|
54
|
+
/** The policy the store counts by itself, when it has one. */
|
|
55
|
+
readonly policy?: {
|
|
56
|
+
readonly limit: number;
|
|
57
|
+
readonly windowMs: number;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/field-rate-limit/types.ts"],"names":[],"mappings":"AAAA,yGAAyG;AACzG,MAAM,WAAW,aAAa;IAC7B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC5B;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,UAAU;IAC1B,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;CAC3E;AAED,0HAA0H;AAC1H,MAAM,MAAM,SAAS,GAClB,UAAU,GACV;IAAE,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAE7D,MAAM,WAAW,qBAAqB,CAAC,GAAG,SAAS,MAAM,GAAG,GAAG;IAC9D,wEAAwE;IACxE,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;IACrD;;;;OAIG;IACH,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IAC9E;;;;;OAKG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,4HAA4H;IAC5H,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,qFAAqF;AACrF,MAAM,WAAW,aAAa;IAC7B,OAAO,CACN,GAAG,EAAE,MAAM,EACX,MAAM,EAAE;QAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,GAE3D;QAAE,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;QAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;KAAE,GAC1D,OAAO,CAAC;QAAE,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;QAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACvE,8DAA8D;IAC9D,QAAQ,CAAC,MAAM,CAAC,EAAE;QAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;CACxE"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { type BoundedStreamOptions, boundedStream } from './bounded-stream';
|
|
2
2
|
export { type ExecutorCall, type ExecutorError, type ExecutorRequest, type ExecutorResult, type GraphQLExecutor, type GraphQLExecutorOptions, graphqlExecutor, } from './executor';
|
|
3
|
+
export { type CostlessStore, type FieldDecision, type FieldLimit, type FieldRateLimitOptions, type FieldRule, fieldRateLimit, limitFromStore, } from './field-rate-limit';
|
|
3
4
|
export { type GraphQLContext, type GraphQLOptions, type GraphQLWsContext, graphql, type ServerContext, } from './graphql';
|
|
4
5
|
export { clearRequestCache, freshPerMutation, oncePerRequest, } from './once-per-request';
|
|
5
6
|
export { renderSandbox, SANDBOX_POLICY, type SandboxOptions } from './sandbox';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,oBAAoB,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAC5E,OAAO,EACN,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,eAAe,GACf,MAAM,YAAY,CAAC;AACpB,OAAO,EACN,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,OAAO,EACP,KAAK,aAAa,GAClB,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,GACd,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,KAAK,cAAc,EAAE,MAAM,WAAW,CAAC;AAC/E,YAAY,EAAE,gBAAgB,EAAE,MAAM,MAAM,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,oBAAoB,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAC5E,OAAO,EACN,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,eAAe,GACf,MAAM,YAAY,CAAC;AACpB,OAAO,EACN,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,UAAU,EACf,KAAK,qBAAqB,EAC1B,KAAK,SAAS,EACd,cAAc,EACd,cAAc,GACd,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACN,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,OAAO,EACP,KAAK,aAAa,GAClB,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,GACd,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,KAAK,cAAc,EAAE,MAAM,WAAW,CAAC;AAC/E,YAAY,EAAE,gBAAgB,EAAE,MAAM,MAAM,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -681,6 +681,260 @@ function graphqlExecutor(options) {
|
|
|
681
681
|
};
|
|
682
682
|
};
|
|
683
683
|
}
|
|
684
|
+
// src/field-rate-limit/count.ts
|
|
685
|
+
import {
|
|
686
|
+
print
|
|
687
|
+
} from "graphql";
|
|
688
|
+
function countSelections(document, selections, names, singles = new Set) {
|
|
689
|
+
const fragments = new Map;
|
|
690
|
+
for (const definition of document.definitions) {
|
|
691
|
+
if (definition.kind === "FragmentDefinition") {
|
|
692
|
+
fragments.set(definition.name.value, definition);
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
const done = new Map;
|
|
696
|
+
const active = new Set;
|
|
697
|
+
const walk = (set) => {
|
|
698
|
+
const counts = new Map;
|
|
699
|
+
const add = (from, under = "") => {
|
|
700
|
+
for (const [name, selected] of from) {
|
|
701
|
+
const own = counts.get(name) ?? { count: 0, distinct: new Set };
|
|
702
|
+
own.count += selected.count;
|
|
703
|
+
for (const one of selected.distinct) {
|
|
704
|
+
if (own.distinct.size >= 2)
|
|
705
|
+
break;
|
|
706
|
+
own.distinct.add(under + one);
|
|
707
|
+
}
|
|
708
|
+
counts.set(name, own);
|
|
709
|
+
}
|
|
710
|
+
};
|
|
711
|
+
for (const selection of set.selections) {
|
|
712
|
+
if (selection.kind === "Field") {
|
|
713
|
+
const name = selection.name.value;
|
|
714
|
+
const written = `${selection.alias?.value ?? name}(${(selection.arguments ?? []).map((argument) => print(argument)).sort().join(",")})`;
|
|
715
|
+
if (names.has(name)) {
|
|
716
|
+
const own = counts.get(name) ?? { count: 0, distinct: new Set };
|
|
717
|
+
own.count += 1;
|
|
718
|
+
if (singles.has(name) && own.distinct.size < 2)
|
|
719
|
+
own.distinct.add(written);
|
|
720
|
+
counts.set(name, own);
|
|
721
|
+
}
|
|
722
|
+
if (selection.selectionSet) {
|
|
723
|
+
add(walk(selection.selectionSet), `${written}/`);
|
|
724
|
+
}
|
|
725
|
+
} else if (selection.kind === "InlineFragment") {
|
|
726
|
+
add(walk(selection.selectionSet));
|
|
727
|
+
} else {
|
|
728
|
+
const name = selection.name.value;
|
|
729
|
+
const fragment = fragments.get(name);
|
|
730
|
+
if (fragment === undefined || active.has(name))
|
|
731
|
+
continue;
|
|
732
|
+
let own = done.get(name);
|
|
733
|
+
if (own === undefined) {
|
|
734
|
+
active.add(name);
|
|
735
|
+
own = walk(fragment.selectionSet);
|
|
736
|
+
active.delete(name);
|
|
737
|
+
done.set(name, own);
|
|
738
|
+
}
|
|
739
|
+
add(own);
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
return counts;
|
|
743
|
+
};
|
|
744
|
+
return walk(selections);
|
|
745
|
+
}
|
|
746
|
+
// src/field-rate-limit/from-store.ts
|
|
747
|
+
function limitFromStore(store, policy) {
|
|
748
|
+
const own = store.policy;
|
|
749
|
+
const resolved = {
|
|
750
|
+
limit: policy?.limit ?? own?.limit ?? Number.NaN,
|
|
751
|
+
windowMs: policy?.windowMs ?? own?.windowMs ?? Number.NaN
|
|
752
|
+
};
|
|
753
|
+
for (const name of ["limit", "windowMs"]) {
|
|
754
|
+
const value = resolved[name];
|
|
755
|
+
if (!Number.isSafeInteger(value) || value < 1) {
|
|
756
|
+
throw new TypeError(`limitFromStore: ${name} must be a whole number of 1 or more, not ${String(policy?.[name] ?? own?.[name])}`);
|
|
757
|
+
}
|
|
758
|
+
if (own !== undefined && value !== own[name]) {
|
|
759
|
+
throw new TypeError(`limitFromStore: ${name} ${value} differs from the store's policy of ${own.limit} per ${own.windowMs}ms. Leave the policy out to use the store's, or give the same numbers.`);
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
return {
|
|
763
|
+
async consume(key, cost) {
|
|
764
|
+
for (let i = 0;i < cost; i++) {
|
|
765
|
+
const decision = await store.consume(key, resolved);
|
|
766
|
+
if (!decision.allowed) {
|
|
767
|
+
return { allowed: false, retryAfter: decision.retryAfter };
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
return { allowed: true, retryAfter: 0 };
|
|
771
|
+
}
|
|
772
|
+
};
|
|
773
|
+
}
|
|
774
|
+
// src/field-rate-limit/plugin.ts
|
|
775
|
+
import { GraphQLError as GraphQLError2, getOperationAST as getOperationAST2 } from "graphql";
|
|
776
|
+
|
|
777
|
+
// src/field-rate-limit/ipv6-network.ts
|
|
778
|
+
function groupsOf(text) {
|
|
779
|
+
const zone = text.indexOf("%");
|
|
780
|
+
const address = zone === -1 ? text : text.slice(0, zone);
|
|
781
|
+
const halves = address.split("::");
|
|
782
|
+
if (halves.length > 2 || !address.includes(":"))
|
|
783
|
+
return;
|
|
784
|
+
const read = (half) => half === undefined || half === "" ? [] : half.split(":");
|
|
785
|
+
const head = read(halves[0]) ?? [];
|
|
786
|
+
const tail = read(halves[1]) ?? [];
|
|
787
|
+
const written = [...head, ...tail];
|
|
788
|
+
const last = written[written.length - 1];
|
|
789
|
+
if (last?.includes(".")) {
|
|
790
|
+
if (!address.endsWith(last))
|
|
791
|
+
return;
|
|
792
|
+
const octets = last.split(".");
|
|
793
|
+
const bytes = octets.map((octet) => /^\d{1,3}$/.test(octet) ? Number(octet) : Number.NaN);
|
|
794
|
+
if (bytes.length !== 4 || bytes.some((byte) => !(byte <= 255)))
|
|
795
|
+
return;
|
|
796
|
+
const [a = 0, b = 0, c = 0, d = 0] = bytes;
|
|
797
|
+
written.splice(-1, 1, (a << 8 | b).toString(16), (c << 8 | d).toString(16));
|
|
798
|
+
if (tail.length > 0)
|
|
799
|
+
tail.splice(-1, 1, "x", "x");
|
|
800
|
+
else
|
|
801
|
+
head.splice(-1, 1, "x", "x");
|
|
802
|
+
}
|
|
803
|
+
const compressed = halves.length === 2;
|
|
804
|
+
const missing = 8 - written.length;
|
|
805
|
+
if (compressed ? missing < 1 : missing !== 0)
|
|
806
|
+
return;
|
|
807
|
+
const all = compressed ? [
|
|
808
|
+
...written.slice(0, head.length),
|
|
809
|
+
...new Array(missing).fill("0"),
|
|
810
|
+
...written.slice(head.length)
|
|
811
|
+
] : written;
|
|
812
|
+
const groups = all.map((group) => /^[0-9a-f]{1,4}$/i.test(group) ? Number.parseInt(group, 16) : Number.NaN);
|
|
813
|
+
return groups.some(Number.isNaN) ? undefined : groups;
|
|
814
|
+
}
|
|
815
|
+
function written(groups) {
|
|
816
|
+
let start = -1;
|
|
817
|
+
let length = 0;
|
|
818
|
+
for (let i = 0;i < 8; ) {
|
|
819
|
+
if (groups[i] !== 0) {
|
|
820
|
+
i++;
|
|
821
|
+
continue;
|
|
822
|
+
}
|
|
823
|
+
let end = i;
|
|
824
|
+
while (end < 8 && groups[end] === 0)
|
|
825
|
+
end++;
|
|
826
|
+
if (end - i > length) {
|
|
827
|
+
start = i;
|
|
828
|
+
length = end - i;
|
|
829
|
+
}
|
|
830
|
+
i = end;
|
|
831
|
+
}
|
|
832
|
+
const hex = (list) => list.map((group) => group.toString(16)).join(":");
|
|
833
|
+
if (length < 2)
|
|
834
|
+
return hex(groups);
|
|
835
|
+
return `${hex(groups.slice(0, start))}::${hex(groups.slice(start + length))}`;
|
|
836
|
+
}
|
|
837
|
+
function ipv6Network(address, prefix) {
|
|
838
|
+
const groups = groupsOf(address);
|
|
839
|
+
if (groups === undefined)
|
|
840
|
+
return address;
|
|
841
|
+
if (groups.slice(0, 5).every((group) => group === 0) && groups[5] === 65535) {
|
|
842
|
+
const [a = 0, b = 0] = groups.slice(6);
|
|
843
|
+
return `${a >> 8}.${a & 255}.${b >> 8}.${b & 255}`;
|
|
844
|
+
}
|
|
845
|
+
const masked = groups.map((group, index) => {
|
|
846
|
+
const kept = Math.min(16, Math.max(0, prefix - index * 16));
|
|
847
|
+
return group >> 16 - kept << 16 - kept;
|
|
848
|
+
});
|
|
849
|
+
return `${written(masked.map((group) => group & 65535))}/${prefix}`;
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
// src/field-rate-limit/plugin.ts
|
|
853
|
+
var DEFAULT_LIMIT_CODE = "RATE_LIMITED";
|
|
854
|
+
function rulesOf(fields) {
|
|
855
|
+
if (typeof fields !== "object" || fields === null || Object.keys(fields).length === 0) {
|
|
856
|
+
throw new TypeError("fieldRateLimit({ fields }): fields maps each field name to count to its limit, and holds at least one");
|
|
857
|
+
}
|
|
858
|
+
const rules = new Map;
|
|
859
|
+
for (const [name, rule] of Object.entries(fields)) {
|
|
860
|
+
const wrapped = typeof rule === "object" && rule !== null && "limit" in rule && typeof rule.limit === "object";
|
|
861
|
+
const limit = wrapped ? rule.limit : rule;
|
|
862
|
+
if (typeof limit?.consume !== "function") {
|
|
863
|
+
throw new TypeError(`fieldRateLimit({ fields: { ${name} } }): a limit has a consume(key, cost) method, or is { limit, single? }`);
|
|
864
|
+
}
|
|
865
|
+
rules.set(name, {
|
|
866
|
+
limit,
|
|
867
|
+
single: wrapped && rule.single === true
|
|
868
|
+
});
|
|
869
|
+
}
|
|
870
|
+
return rules;
|
|
871
|
+
}
|
|
872
|
+
function checked(options) {
|
|
873
|
+
const { ipv6Prefix } = options;
|
|
874
|
+
if (ipv6Prefix !== undefined) {
|
|
875
|
+
if (!Number.isInteger(ipv6Prefix) || ipv6Prefix < 0 || ipv6Prefix > 128) {
|
|
876
|
+
throw new TypeError(`fieldRateLimit: ipv6Prefix must be a whole number from 0 to 128, not ${String(ipv6Prefix)}`);
|
|
877
|
+
}
|
|
878
|
+
if (options.key !== undefined) {
|
|
879
|
+
throw new TypeError("fieldRateLimit: ipv6Prefix applies to the default key, and a key of your own was given. Drop one, or group the address in your key.");
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
const { code } = options;
|
|
883
|
+
if (code !== undefined && (typeof code !== "string" || code === "")) {
|
|
884
|
+
throw new TypeError("fieldRateLimit: code is a non-empty string");
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
function refusal(message, code, status, extensions = {}, headers) {
|
|
888
|
+
return {
|
|
889
|
+
errors: [
|
|
890
|
+
new GraphQLError2(message, {
|
|
891
|
+
extensions: {
|
|
892
|
+
code,
|
|
893
|
+
...extensions,
|
|
894
|
+
http: headers === undefined ? { status } : { status, headers }
|
|
895
|
+
}
|
|
896
|
+
})
|
|
897
|
+
]
|
|
898
|
+
};
|
|
899
|
+
}
|
|
900
|
+
function fieldRateLimit(options) {
|
|
901
|
+
const rules = rulesOf(options.fields);
|
|
902
|
+
checked(options);
|
|
903
|
+
const names = new Set(rules.keys());
|
|
904
|
+
const singles = new Set([...rules].filter(([, r]) => r.single).map(([n]) => n));
|
|
905
|
+
const code = options.code ?? DEFAULT_LIMIT_CODE;
|
|
906
|
+
const prefix = options.ipv6Prefix;
|
|
907
|
+
const keyOf = options.key ?? ((ctx) => {
|
|
908
|
+
const { ip } = ctx;
|
|
909
|
+
return prefix === undefined || ip === undefined ? ip : ipv6Network(ip, prefix);
|
|
910
|
+
});
|
|
911
|
+
return {
|
|
912
|
+
async onExecute({ args, setResultAndStopExecution }) {
|
|
913
|
+
const operation = getOperationAST2(args.document, args.operationName);
|
|
914
|
+
if (!operation)
|
|
915
|
+
return;
|
|
916
|
+
const counts = countSelections(args.document, operation.selectionSet, names, singles);
|
|
917
|
+
if (counts.size === 0)
|
|
918
|
+
return;
|
|
919
|
+
for (const [name, selected] of counts) {
|
|
920
|
+
if (rules.get(name)?.single && selected.distinct.size > 1) {
|
|
921
|
+
return setResultAndStopExecution(refusal(`${name} may be selected once per operation`, "FIELD_SELECTED_ONCE", 400));
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
const who = await keyOf(args.contextValue);
|
|
925
|
+
if (who === undefined)
|
|
926
|
+
return;
|
|
927
|
+
for (const [name, selected] of counts) {
|
|
928
|
+
const decision = await rules.get(name).limit.consume(`${name}:${who}`, selected.count);
|
|
929
|
+
if (!decision.allowed) {
|
|
930
|
+
const wait = Math.ceil(decision.retryAfter / 1000);
|
|
931
|
+
const retryAfter = Number.isFinite(wait) ? Math.max(1, wait) : 1;
|
|
932
|
+
return setResultAndStopExecution(refusal("Too many attempts, try again later", code, 429, { retryAfter }, { "retry-after": String(retryAfter) }));
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
};
|
|
937
|
+
}
|
|
684
938
|
// src/endpoint.ts
|
|
685
939
|
var DEFAULT_BODY_LIMIT = 1048576;
|
|
686
940
|
function declareEndpoint(app, path, handler, bodyLimit, socket) {
|
|
@@ -699,7 +953,7 @@ function declareEndpoint(app, path, handler, bodyLimit, socket) {
|
|
|
699
953
|
|
|
700
954
|
// src/ws-operations.ts
|
|
701
955
|
import { startOperation } from "@alxia/core";
|
|
702
|
-
import { getOperationAST as
|
|
956
|
+
import { getOperationAST as getOperationAST3 } from "graphql";
|
|
703
957
|
|
|
704
958
|
class SocketOperations {
|
|
705
959
|
#ctx;
|
|
@@ -709,7 +963,7 @@ class SocketOperations {
|
|
|
709
963
|
}
|
|
710
964
|
begin(id, document, operationName) {
|
|
711
965
|
this.end(id);
|
|
712
|
-
const operation =
|
|
966
|
+
const operation = getOperationAST3(document, operationName);
|
|
713
967
|
if (operation === undefined || operation === null)
|
|
714
968
|
return;
|
|
715
969
|
const end = startOperation(this.#ctx, {
|
|
@@ -955,12 +1209,14 @@ export {
|
|
|
955
1209
|
SANDBOX_POLICY,
|
|
956
1210
|
boundedStream,
|
|
957
1211
|
clearRequestCache,
|
|
1212
|
+
fieldRateLimit,
|
|
958
1213
|
freshPerMutation,
|
|
959
1214
|
graphql,
|
|
960
1215
|
graphqlExecutor,
|
|
1216
|
+
limitFromStore,
|
|
961
1217
|
oncePerRequest,
|
|
962
1218
|
renderSandbox
|
|
963
1219
|
};
|
|
964
1220
|
|
|
965
|
-
//# debugId=
|
|
1221
|
+
//# debugId=21672915486E17F964756E2164756E21
|
|
966
1222
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/bounded-stream.ts", "../src/yoga.ts", "../src/handler.ts", "../src/body-refusal.ts", "../src/sandbox.ts", "../src/operation.ts", "../src/parse-limits.ts", "../src/document-cache.ts", "../src/nesting.ts", "../src/executor.ts", "../src/endpoint.ts", "../src/ws-operations.ts", "../src/ws-server.ts", "../src/ws.ts", "../src/graphql.ts", "../src/once-per-request.ts"],
|
|
3
|
+
"sources": ["../src/bounded-stream.ts", "../src/yoga.ts", "../src/handler.ts", "../src/body-refusal.ts", "../src/sandbox.ts", "../src/operation.ts", "../src/parse-limits.ts", "../src/document-cache.ts", "../src/nesting.ts", "../src/executor.ts", "../src/field-rate-limit/count.ts", "../src/field-rate-limit/from-store.ts", "../src/field-rate-limit/plugin.ts", "../src/field-rate-limit/ipv6-network.ts", "../src/endpoint.ts", "../src/ws-operations.ts", "../src/ws-server.ts", "../src/ws.ts", "../src/graphql.ts", "../src/once-per-request.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"/** What bounds a stream, and what keeps it authorized. All durations in ms. */\nexport interface BoundedStreamOptions {\n\t/** The stream ends, cleanly, after this long without an event. */\n\tidleMs: number;\n\t/** The stream ends, cleanly, this long after it began, however chatty. */\n\ttotalMs: number;\n\t/** `check` runs at least this often, also while no event comes. */\n\tcheckEveryMs: number;\n\t/**\n\t * Before an event is yielded, `check` runs when the last check is at least\n\t * this old. Default `0`: every event is checked. Raise it when events come\n\t * in bursts and one check per event would cost more than the delay of a\n\t * revocation it saves.\n\t */\n\tcheckDebounceMs?: number;\n\t/** Throws to refuse (a session that ended, a role that was lost). */\n\tcheck: () => Promise<void> | void;\n\t/** Turns what `check` (or the source) threw into the error the stream throws. Default: rethrown as is. */\n\tmapError?: (error: unknown) => unknown;\n\t/** Aborted when the client leaves: the stream ends and releases the source. */\n\tsignal?: AbortSignal;\n}\n\ntype Woke<T> =\n\t| { kind: 'read'; result: IteratorResult<T> }\n\t| { kind: 'failed'; error: unknown }\n\t| { kind: 'timer' }\n\t| { kind: 'interrupted' };\n\nconst DONE = { done: true, value: undefined } as const;\n\n/**\n * `source` bounded by an idle and a total lifetime and re-checked while it\n * lives, to return as a subscription's `subscribe` result.\n *\n * It ends, without an error, when the source ends, on the idle bound, on the\n * total bound and on `signal`'s abort. It throws `mapError(error)` (the\n * error itself by default) when `check` fails, or when the source does. The\n * source's `return()` is called at once on the consumer's `return()` (a\n * client that disconnected) and on any end, even while a read is pending: the\n * iterator is written by hand because a generator's `return()` waits behind a\n * pending `next()`. Read it one `next()` at a time, as `for await` does. No\n * timer outlives a step.\n */\nexport function boundedStream<T>(\n\tsource: AsyncIterable<T> | AsyncIterator<T>,\n\toptions: BoundedStreamOptions,\n): AsyncIterableIterator<T> {\n\tconst { idleMs, totalMs, checkEveryMs, check, signal } = options;\n\tconst debounceMs = options.checkDebounceMs ?? 0;\n\tconst mapError = options.mapError ?? ((error: unknown) => error);\n\tconst iterator: AsyncIterator<T> =\n\t\tSymbol.asyncIterator in source\n\t\t\t? (source as AsyncIterable<T>)[Symbol.asyncIterator]()\n\t\t\t: (source as AsyncIterator<T>);\n\n\tconst startedAt = Date.now();\n\tlet lastEventAt = startedAt;\n\tlet lastCheckAt = startedAt;\n\tlet finished = false;\n\tlet interrupt: (() => void) | undefined;\n\tlet pending: Promise<IteratorResult<T>> | undefined;\n\tlet released: Promise<void> | undefined;\n\n\tconst release = (): Promise<void> => {\n\t\tfinished = true;\n\t\tinterrupt?.();\n\t\treleased ??= (async () => {\n\t\t\ttry {\n\t\t\t\tawait iterator.return?.(undefined);\n\t\t\t} catch {}\n\t\t})();\n\t\treturn released;\n\t};\n\n\tconst onAbort = () => void release();\n\tif (signal?.aborted) void release();\n\telse signal?.addEventListener('abort', onAbort, { once: true });\n\tconst detach = () => signal?.removeEventListener('abort', onAbort);\n\n\tconst checked = async () => {\n\t\tawait check();\n\t\tlastCheckAt = Date.now();\n\t};\n\n\t// Waits for the source, the nearest bound or the abort, whichever is first.\n\tconst wait = (read: Promise<IteratorResult<T>>, ms: number) =>\n\t\tnew Promise<Woke<T>>((resolve) => {\n\t\t\tconst settle = (woke: Woke<T>) => {\n\t\t\t\tclearTimeout(timer);\n\t\t\t\tinterrupt = undefined;\n\t\t\t\tresolve(woke);\n\t\t\t};\n\t\t\tconst timer = setTimeout(() => settle({ kind: 'timer' }), ms);\n\t\t\tinterrupt = () => settle({ kind: 'interrupted' });\n\t\t\tread.then(\n\t\t\t\t(result) => settle({ kind: 'read', result }),\n\t\t\t\t(error: unknown) => settle({ kind: 'failed', error }),\n\t\t\t);\n\t\t});\n\n\tconst step = async (): Promise<IteratorResult<T>> => {\n\t\tfor (;;) {\n\t\t\tif (finished) return DONE;\n\t\t\tconst t = Date.now();\n\t\t\tconst left = [totalMs - (t - startedAt), idleMs - (t - lastEventAt)];\n\t\t\tif (Math.min(...left) <= 0) {\n\t\t\t\tawait release();\n\t\t\t\treturn DONE;\n\t\t\t}\n\t\t\tconst dueIn = checkEveryMs - (t - lastCheckAt);\n\t\t\tif (dueIn <= 0) {\n\t\t\t\tawait checked();\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (!pending) {\n\t\t\t\tpending = iterator.next();\n\t\t\t\tpending.catch(() => {});\n\t\t\t}\n\t\t\tconst woke = await wait(pending, Math.max(1, Math.min(dueIn, ...left)));\n\t\t\tif (woke.kind === 'interrupted') {\n\t\t\t\tawait release();\n\t\t\t\treturn DONE;\n\t\t\t}\n\t\t\tif (woke.kind === 'timer') continue;\n\t\t\tpending = undefined;\n\t\t\tif (woke.kind === 'failed') throw woke.error;\n\t\t\tif (woke.result.done) {\n\t\t\t\tawait release();\n\t\t\t\treturn DONE;\n\t\t\t}\n\t\t\tlastEventAt = Date.now();\n\t\t\tif (lastEventAt - lastCheckAt >= debounceMs) await checked();\n\t\t\tif (finished) return DONE;\n\t\t\treturn { done: false, value: woke.result.value };\n\t\t}\n\t};\n\n\tconst stream: AsyncIterableIterator<T> = {\n\t\t[Symbol.asyncIterator]: () => stream,\n\t\tnext: async () => {\n\t\t\ttry {\n\t\t\t\tconst result = await step();\n\t\t\t\tif (result.done) detach();\n\t\t\t\treturn result;\n\t\t\t} catch (error) {\n\t\t\t\tawait release();\n\t\t\t\tdetach();\n\t\t\t\tthrow mapError(error);\n\t\t\t}\n\t\t},\n\t\treturn: async () => {\n\t\t\tawait release();\n\t\t\tdetach();\n\t\t\treturn DONE;\n\t\t},\n\t};\n\treturn stream;\n}\n",
|
|
6
6
|
"import { isDev } from '@alxia/core';\nimport type { YogaServerOptions } from 'graphql-yoga';\nimport { type YogaContext, yogaServers } from './handler';\nimport { reportsOperations } from './operation';\nimport {\n\tlimitsParsing,\n\ttype ParseCacheOptions,\n\tparseCaches,\n\tresolveLimits,\n} from './parse-limits';\n\n/**\n * The Yoga behind an endpoint, from the options `graphql()` and\n * `graphqlExecutor()` share: the limits, the parse cache, the logging and\n * request id defaults, and `reportsOperations`. One Yoga per path.\n */\nexport function yogaFor<UserCtx extends YogaContext>(\n\tyogaOptions: object,\n\tpage: {\n\t\treadonly cors: unknown;\n\t\treadonly ide?: 'graphiql' | 'apollo-sandbox' | false | undefined;\n\t\treadonly graphiql?: unknown | undefined;\n\t},\n) {\n\tconst { maxTokens, maxNesting, parseCache, ...rest } = yogaOptions as Record<\n\t\tstring,\n\t\tany\n\t> & {\n\t\treadonly maxTokens?: number | false;\n\t\treadonly maxNesting?: number | false;\n\t\treadonly parseCache?: false | ParseCacheOptions;\n\t};\n\tconst { cors, ide, graphiql } = page;\n\tconst limits = resolveLimits(maxTokens, maxNesting, parseCache, rest);\n\tconst shown = graphiql ?? true;\n\treturn yogaServers<UserCtx>(\n\t\t{\n\t\t\t...(rest as YogaServerOptions<YogaContext, UserCtx>),\n\t\t\t...(rest['logging'] === undefined ? { logging: 'warn' } : {}),\n\t\t\t...untrustedRequestId(rest),\n\t\t\tplugins: [\n\t\t\t\tlimitsParsing(limits.tokens, limits.depth),\n\t\t\t\t...(rest['plugins'] ?? []),\n\t\t\t\treportsOperations(),\n\t\t\t],\n\t\t\tcors,\n\t\t\tgraphiql: (ide === undefined\n\t\t\t\t? (_request: Request, context: object) => isDev(context) && shown\n\t\t\t\t: ide === 'graphiql'\n\t\t\t\t\t? shown\n\t\t\t\t\t: false) as YogaServerOptions<YogaContext, UserCtx>['graphiql'],\n\t\t} as never,\n\t\trest['parserAndValidationCache'] === undefined\n\t\t\t? () => parseCaches(parseCache)\n\t\t\t: undefined,\n\t);\n}\n\n/**\n * Yoga 6 reads the client's `x-request-id`, answers with it and tags its\n * logger with it: log forging. Off by default (the app issues its own id);\n * an app that turns Yoga's id on keeps `trustHeader: false` unless it sets it.\n */\nfunction untrustedRequestId(options: object): object {\n\tconst { requestId } = options as { requestId?: unknown };\n\tif (requestId === undefined) return { requestId: false };\n\tif (requestId === true) return { requestId: { trustHeader: false } };\n\tif (typeof requestId === 'object' && requestId !== null) {\n\t\treturn { requestId: { trustHeader: false, ...requestId } };\n\t}\n\treturn {};\n}\n",
|
|
7
7
|
"/**\n * The endpoint behind `graphql()`: one Yoga per path it is served at, and\n * the route handler that hands each request to it.\n */\nimport {\n\ttype BaseContext,\n\ttype StatusCode,\n\tshutdownSignal,\n\tvary,\n} from '@alxia/core';\nimport {\n\tcreateYoga,\n\ttype YogaServerInstance,\n\ttype YogaServerOptions,\n} from 'graphql-yoga';\nimport { watchBody, withoutOriginalError } from './body-refusal';\nimport { renderSandbox, SANDBOX_POLICY, type SandboxOptions } from './sandbox';\n\nexport type YogaContext = Record<string, any>;\n\n/** Where Yoga's GraphiQL page loads its files from: one pinned version on unpkg. */\nconst GRAPHIQL_FILES =\n\t/https:\\/\\/unpkg\\.com\\/@graphql-yoga\\/graphiql@[\\w.-]+\\//;\n\n/**\n * What GraphiQL's page may load: its scripts, styles and Monaco's\n * workers from the exact version of `@graphql-yoga/graphiql` the page\n * names, fetched and run as blobs; queries to this server alone; framed\n * by no one. A page that names none (a `renderGraphiQL` of the app's own)\n * gets this server alone. `@alxia/secure-headers` keeps a policy a\n * response already has.\n */\nexport function graphiqlPolicy(html: string): string {\n\tconst files = html.match(GRAPHIQL_FILES)?.[0] ?? '';\n\tconst from = files === '' ? '' : ` ${files}`;\n\treturn [\n\t\t\"default-src 'self'\",\n\t\t`script-src 'self' 'unsafe-inline'${from}`,\n\t\t`style-src 'self' 'unsafe-inline'${from}`,\n\t\t\"img-src 'self' data: https:\",\n\t\t`font-src 'self' data:${from}`,\n\t\t\"worker-src 'self' blob:\",\n\t\t`connect-src 'self'${from}`,\n\t\t\"frame-ancestors 'none'\",\n\t].join('; ');\n}\n\n/**\n * The Yoga serving `endpoint`, created on first use. One per path: a plugin\n * mounted under a prefix serves the same routes at a longer path, and\n * GraphiQL must ask that one.\n */\nexport function yogaServers<UserCtx extends YogaContext>(\n\toptions: Omit<YogaServerOptions<YogaContext, UserCtx>, 'graphqlEndpoint'>,\n\tcaches?: () => YogaServerOptions<\n\t\tYogaContext,\n\t\tUserCtx\n\t>['parserAndValidationCache'],\n): (endpoint: string) => YogaServerInstance<YogaContext, UserCtx> {\n\tconst servers = new Map<string, YogaServerInstance<YogaContext, UserCtx>>();\n\treturn (endpoint) => {\n\t\tlet yoga = servers.get(endpoint);\n\t\tif (yoga === undefined) {\n\t\t\tyoga = createYoga<YogaContext, UserCtx>({\n\t\t\t\t...options,\n\t\t\t\t...(caches === undefined ? {} : { parserAndValidationCache: caches() }),\n\t\t\t\tgraphqlEndpoint: endpoint,\n\t\t\t});\n\t\t\tservers.set(endpoint, yoga);\n\t\t}\n\t\treturn yoga;\n\t};\n}\n\n/**\n * What Yoga is handed as its server context: the route's context — the\n * middlewares' work — minus what a resolver has no use for.\n */\nexport function serverContext(\n\tctx: Record<string, unknown>,\n): Record<string, unknown> {\n\tconst {\n\t\tparams: _params,\n\t\tquery: _query,\n\t\theaders: _headers,\n\t\tcookies: _cookies,\n\t\tbody: _body,\n\t\treply: _reply,\n\t\tredirect: _redirect,\n\t\t...server\n\t} = ctx;\n\treturn server;\n}\n\n/** Yoga's headers a 413 does not take: they frame or type Yoga's own body. */\nconst REFUSAL_OWN_HEADERS = new Set([\n\t'content-type',\n\t'content-length',\n\t'content-encoding',\n\t'transfer-encoding',\n]);\n\n/**\n * The handler of the endpoint's `GET` and `POST`: Apollo Sandbox's page to\n * a browser when `sandbox` is not `false`, else the request to Yoga, with\n * the route's context — the middlewares' work, minus what a resolver has no use\n * for — as Yoga's server context.\n */\nexport function graphqlHandler<UserCtx extends YogaContext>(\n\tyogaAt: (endpoint: string) => YogaServerInstance<YogaContext, UserCtx>,\n\tsandbox: SandboxOptions | false,\n) {\n\t// A handler's context: its route is the one it was declared at. Named\n\t// `graphql`, the name the route table `listen` prints in dev shows.\n\treturn async function graphql(\n\t\tctx: Record<string, unknown> & BaseContext & { readonly route: string },\n\t) {\n\t\tconst { reply } = ctx;\n\t\tconst server = serverContext(ctx);\n\t\tif (\n\t\t\tsandbox !== false &&\n\t\t\tctx.request.method === 'GET' &&\n\t\t\tctx.request.headers.get('accept')?.includes('text/html') &&\n\t\t\t!ctx.url.searchParams.has('query')\n\t\t) {\n\t\t\t// A path: the page resolves it against its own address, so behind\n\t\t\t// a TLS proxy the Sandbox asks over https, as the browser did.\n\t\t\treturn reply(200, renderSandbox(ctx.route, sandbox), {\n\t\t\t\theaders: {\n\t\t\t\t\t'content-type': 'text/html;charset=utf-8',\n\t\t\t\t\t'content-security-policy': SANDBOX_POLICY,\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\t\tconst watched = watchBody(ctx.request);\n\t\tconst answered = await yogaAt(ctx.route).fetch(watched.request, server);\n\t\t// Yoga answered a body past `bodyLimit` with its own 400: core's 413\n\t\t// is the answer, in the app's format.\n\t\tconst refusal = watched.refusal();\n\t\tif (refusal !== undefined) {\n\t\t\tvoid answered.body?.cancel();\n\t\t\t// What Yoga's plugins set (`cache-control: no-store`…) stays on the\n\t\t\t// 413; its body and framing are core's.\n\t\t\tfor (const [name, value] of answered.headers) {\n\t\t\t\tif (REFUSAL_OWN_HEADERS.has(name)) continue;\n\t\t\t\tif (name === 'set-cookie') ctx.set.headers.append(name, value);\n\t\t\t\telse if (name === 'vary') {\n\t\t\t\t\t// Added to the app's own, as core's `send` does.\n\t\t\t\t\tfor (const part of value.split(',')) vary(ctx.set.headers, part);\n\t\t\t\t} else ctx.set.headers.set(name, value);\n\t\t\t}\n\t\t\tthrow refusal;\n\t\t}\n\t\tconst response = await withoutOriginalError(answered);\n\t\tconst headers = new Headers(response.headers);\n\t\tif (\n\t\t\theaders.get('content-type')?.startsWith('text/html') &&\n\t\t\t!headers.has('content-security-policy')\n\t\t) {\n\t\t\t// GraphiQL's page: its policy names the files it loads.\n\t\t\tconst html = await response.text();\n\t\t\theaders.set('content-security-policy', graphiqlPolicy(html));\n\t\t\treturn reply(response.status as StatusCode, html, { headers });\n\t\t}\n\t\tconst body = endedOnShutdown(response, shutdownSignal(ctx));\n\t\treturn reply(response.status as StatusCode, body ?? undefined, {\n\t\t\theaders,\n\t\t});\n\t};\n}\n\n/**\n * A subscription's or an incremental delivery's body, which streams until\n * its reader stops: ended when the app starts shutting down — Yoga's\n * stream cancelled, as when the client leaves, and the client reading its\n * end — so the drain does not wait for it. Any other body finishes within\n * the drain as it is.\n */\nfunction endedOnShutdown(\n\tresponse: Response,\n\tsignal: AbortSignal,\n): ReadableStream<Uint8Array> | null {\n\tconst body = response.body;\n\tconst type = response.headers.get('content-type') ?? '';\n\tif (body === null || !/text\\/event-stream|multipart\\/mixed/.test(type)) {\n\t\treturn body;\n\t}\n\tconst reader = body.getReader();\n\t// The signal lives as long as the process: the listener goes as soon as\n\t// the stream is over, however it ended, or each response would leave one.\n\tconst end = () => {\n\t\tsignal.removeEventListener('abort', end);\n\t\tvoid reader.cancel();\n\t\ttry {\n\t\t\tcontroller.close();\n\t\t} catch {\n\t\t\t// Closed already: the stream had ended.\n\t\t}\n\t};\n\tlet controller: ReadableStreamDefaultController<Uint8Array>;\n\treturn new ReadableStream<Uint8Array>({\n\t\tstart(started) {\n\t\t\tcontroller = started;\n\t\t\tif (signal.aborted) end();\n\t\t\telse signal.addEventListener('abort', end, { once: true });\n\t\t},\n\t\tasync pull(controller) {\n\t\t\tconst result = await reader.read().catch((error: unknown) => {\n\t\t\t\tsignal.removeEventListener('abort', end);\n\t\t\t\tthrow error;\n\t\t\t});\n\t\t\tif (result.done) {\n\t\t\t\tsignal.removeEventListener('abort', end);\n\t\t\t\ttry {\n\t\t\t\t\tcontroller.close();\n\t\t\t\t} catch {\n\t\t\t\t\t// Closed already: the shutdown ended it.\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcontroller.enqueue(result.value);\n\t\t},\n\t\tcancel: (reason) => {\n\t\t\tsignal.removeEventListener('abort', end);\n\t\t\treturn reader.cancel(reason);\n\t\t},\n\t});\n}\n",
|
|
8
8
|
"/**\n * Yoga reads the request body itself, and turns any failure of the read\n * into its own 400. A body past core's `bodyLimit` fails the read with a\n * `ContentTooLargeError`; `watchBody` keeps that error and hands Yoga its\n * own 413 error in its place, so Yoga logs nothing, and the handler can\n * throw core's again once Yoga has answered: the app's own boundary\n * answers the 413 in its error format, leaking nothing of Yoga's.\n */\nimport type { ContentTooLargeError } from '@alxia/core';\nimport { GraphQLError } from 'graphql';\n\n/**\n * By its name and its limit, not `instanceof`: the copy of core that\n * limited the body may not be the one this package resolves.\n */\nfunction isTooLarge(error: unknown): error is ContentTooLargeError {\n\treturn (\n\t\terror instanceof Error &&\n\t\terror.name === 'ContentTooLargeError' &&\n\t\ttypeof (error as { limit?: unknown }).limit === 'number'\n\t);\n}\n\nexport interface WatchedRequest {\n\t/** The request to hand to Yoga: the same, its body watched. */\n\treadonly request: Request;\n\t/** The `ContentTooLargeError` the body's read failed with, if it did. */\n\trefusal(): ContentTooLargeError | undefined;\n}\n\n/** `request` with its body's failure recorded; a request with no body is as it is. */\nexport function watchBody(request: Request): WatchedRequest {\n\tconst source = request.body;\n\tif (source === null || request.bodyUsed || source.locked) {\n\t\treturn { request, refusal: () => undefined };\n\t}\n\tlet refused: ContentTooLargeError | undefined;\n\tconst reader = source.getReader();\n\tconst body = new ReadableStream<Uint8Array>({\n\t\tasync pull(controller) {\n\t\t\ttry {\n\t\t\t\tconst { value, done } = await reader.read();\n\t\t\t\tif (done) controller.close();\n\t\t\t\telse controller.enqueue(value);\n\t\t\t} catch (error) {\n\t\t\t\tif (!isTooLarge(error)) throw error;\n\t\t\t\trefused = error;\n\t\t\t\t// Yoga's own refusal, which it neither masks nor logs, for\n\t\t\t\t// every content type: the handler answers core's 413 instead.\n\t\t\t\tthrow new GraphQLError('Request body too large', {\n\t\t\t\t\textensions: {\n\t\t\t\t\t\tcode: 'REQUEST_ENTITY_TOO_LARGE',\n\t\t\t\t\t\thttp: { status: 413 },\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t\tcancel: (reason) => reader.cancel(reason),\n\t});\n\treturn {\n\t\trequest: new Request(request, { body, duplex: 'half' } as RequestInit),\n\t\trefusal: () => refused,\n\t};\n}\n\ninterface Failure {\n\terrors?: { extensions?: Record<string, unknown> }[];\n}\n\n/**\n * Yoga's 400 for a request it cannot read — a body that is not JSON, a\n * query string that is not valid — carries the parser's own error as\n * `extensions.originalError`. A client reads the message and the code, not\n * what a parser said: the response without it, any other as it is.\n */\nexport async function withoutOriginalError(\n\tresponse: Response,\n): Promise<Response> {\n\tconst type = response.headers.get('content-type') ?? '';\n\tif (\n\t\tresponse.status !== 400 ||\n\t\t!/^application\\/(?:[\\w.-]+\\+)?json/.test(type)\n\t) {\n\t\treturn response;\n\t}\n\tconst text = await response.text();\n\tlet failure: Failure;\n\ttry {\n\t\tfailure = JSON.parse(text) as Failure;\n\t} catch {\n\t\treturn new Response(text, response);\n\t}\n\tfor (const error of failure.errors ?? []) {\n\t\tdelete error.extensions?.['originalError'];\n\t}\n\tconst headers = new Headers(response.headers);\n\theaders.delete('content-length');\n\treturn new Response(JSON.stringify(failure), { status: 400, headers });\n}\n",
|
|
9
|
-
"/**\n * [Apollo Sandbox](https://www.apollographql.com/docs/graphos/platform/sandbox),\n * embedded: the page a browser gets at the endpoint when the IDE is\n * `apollo-sandbox`. `@
|
|
9
|
+
"/**\n * [Apollo Sandbox](https://www.apollographql.com/docs/graphos/platform/sandbox),\n * embedded: the page a browser gets at the endpoint when the IDE is\n * `apollo-sandbox`. `@softistx/shared-graphql`'s `renderSandbox`, kept twice: the\n * Sandbox asks the address the page was opened at, as there since\n * nxgt-core#171, but here the page resolves the path itself, so a TLS proxy\n * in front changes nothing.\n */\n\nexport interface SandboxOptions {\n\t/** The page's title. `Sandbox Explorer` by default. */\n\treadonly title?: string;\n\t/** The operation the Sandbox opens with. */\n\treadonly initialDocument?: string;\n\t/** Headers every operation sends, shown and editable in the Sandbox. */\n\treadonly initialHeaders?: Readonly<Record<string, string>>;\n\t/** Whether the Sandbox polls the schema as it changes. On by default. */\n\treadonly pollForSchemaUpdates?: boolean;\n\t/** Whether operations send the browser's cookies: a session cookie. On by default. */\n\treadonly includeCookies?: boolean;\n}\n\n/** What the page loads: the Sandbox's script, its frame, and operations to this server. */\nexport const SANDBOX_POLICY = [\n\t\"default-src 'self'\",\n\t\"script-src 'self' 'unsafe-inline' https://embeddable-sandbox.cdn.apollographql.com\",\n\t\"style-src 'self' 'unsafe-inline'\",\n\t'frame-src https://sandbox.embed.apollographql.com',\n\t\"img-src 'self' data: https:\",\n\t\"connect-src 'self'\",\n].join('; ');\n\n/**\n * The page, its endpoint `endpoint`: a URL, or a path the page resolves\n * against its own address. Every value is escaped into its JavaScript and\n * HTML.\n */\nexport function renderSandbox(\n\tendpoint: string,\n\toptions: SandboxOptions = {},\n): string {\n\tconst config = {\n\t\ttarget: '#sandbox',\n\t\tinitialEndpoint: endpoint,\n\t\tinitialState: {\n\t\t\tincludeCookies: options.includeCookies ?? true,\n\t\t\tpollForSchemaUpdates: options.pollForSchemaUpdates ?? true,\n\t\t\t...(options.initialDocument === undefined\n\t\t\t\t? {}\n\t\t\t\t: { document: options.initialDocument }),\n\t\t\t...(options.initialHeaders === undefined\n\t\t\t\t? {}\n\t\t\t\t: { headers: options.initialHeaders }),\n\t\t},\n\t\thideCookieToggle: false,\n\t\tendpointIsEditable: false,\n\t};\n\treturn `<!doctype html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\" />\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n<title>${html(options.title ?? 'Sandbox Explorer')}</title>\n<style>html, body { margin: 0; height: 100%; } #sandbox { position: absolute; inset: 0; }</style>\n</head>\n<body>\n<div id=\"sandbox\"></div>\n<script src=\"https://embeddable-sandbox.cdn.apollographql.com/_latest/embeddable-sandbox.umd.production.min.js\"></script>\n<script>\n{\nconst config = ${script(config)};\nconfig.initialEndpoint = new URL(config.initialEndpoint, location.href).href;\nnew window.EmbeddedSandbox(config);\n}\n</script>\n</body>\n</html>`;\n}\n\nfunction html(text: string): string {\n\treturn text.replace(/[&<>\"']/g, (char) => `&#${char.charCodeAt(0)};`);\n}\n\n/** JSON that cannot close the `<script>` it is written in. */\nfunction script(value: unknown): string {\n\treturn JSON.stringify(value)\n\t\t.replace(/</g, '\\\\u003c')\n\t\t.replace(/>/g, '\\\\u003e')\n\t\t.replace(/\\u2028/g, '\\\\u2028')\n\t\t.replace(/\\u2029/g, '\\\\u2029');\n}\n",
|
|
10
10
|
"/**\n * The plugin that tells the observers around the endpoint — `@alxia/logger`,\n * `@alxia/telemetry` — which operation each request executes.\n */\nimport { reportOperation } from '@alxia/core';\nimport { getOperationAST } from 'graphql';\nimport type { Plugin } from 'graphql-yoga';\n\ninterface Executed {\n\treadonly document: Parameters<typeof getOperationAST>[0];\n\treadonly operationName?: string | null | undefined;\n\treadonly contextValue: unknown;\n}\n\n/** Reports the operation of `args`: its type, and its name when it has one. */\nfunction report(args: Executed): void {\n\tconst operation = getOperationAST(args.document, args.operationName);\n\tif (operation === undefined || operation === null) return;\n\treportOperation(args.contextValue as object, {\n\t\ttype: operation.operation,\n\t\tname: operation.name?.value,\n\t});\n}\n\n/**\n * A Yoga plugin reporting each operation Yoga executes or subscribes to,\n * through core's `reportOperation`: a batched body reports each of its\n * operations, a request refused before it executes none.\n */\nexport function reportsOperations(): Plugin {\n\treturn {\n\t\tonExecute: ({ args }) => report(args),\n\t\tonSubscribe: ({ args }) => report(args),\n\t};\n}\n",
|
|
11
11
|
"/**\n * What `graphql()` bounds about parsing: the tokens a document may hold,\n * and the cache of what was parsed.\n */\nimport { type DocumentNode, Source, syntaxError } from 'graphql';\nimport type { Plugin, YogaServerOptions } from 'graphql-yoga';\nimport {\n\tboundedCache,\n\ttype Cache,\n\tdocumentWeight,\n\terrorWeight,\n} from './document-cache';\nimport type { YogaContext } from './handler';\nimport { nestingLimit, tooDeepAt } from './nesting';\n\n/** The most tokens a document may hold, unless `maxTokens` says otherwise. */\nexport const DEFAULT_MAX_TOKENS = 15_000;\n\n/** The sizes of the parse cache, of each endpoint. */\nexport interface ParseCacheOptions {\n\t/** The most estimated bytes of parsed documents kept. 64 MiB by default. */\n\treadonly maxBytes?: number;\n\t/** The most documents kept. 1 024 by default. */\n\treadonly max?: number;\n\t/** How long a document is kept, in milliseconds. One hour by default. */\n\treadonly ttl?: number;\n}\n\nconst DEFAULT_BYTES = 64 * 1024 * 1024;\n\nfunction positive(\n\tname: string,\n\tvalue: unknown,\n\twhat: string,\n\talternative = '',\n): number {\n\tif (typeof value === 'number' && Number.isSafeInteger(value) && value > 0) {\n\t\treturn value;\n\t}\n\tthrow new TypeError(\n\t\t`graphql(app, { ${name} }): ${what}, a positive whole number${alternative}; got ${String(value)}`,\n\t);\n}\n\n/** `maxTokens` checked where `graphql()` is declared. */\nexport function tokenLimit(\n\tmaxTokens: number | false | undefined,\n): number | false {\n\tif (maxTokens === undefined) return DEFAULT_MAX_TOKENS;\n\tif (maxTokens === false) return false;\n\treturn positive(\n\t\t'maxTokens',\n\t\tmaxTokens,\n\t\t'maxTokens is the most tokens a document may hold',\n\t\t', or false for none',\n\t);\n}\n\n/** A `RangeError` about the call stack is the stack overflowing, which parsing a nested document can cause. */\nconst overflowed = (error: unknown): boolean =>\n\terror instanceof RangeError && /call stack/i.test(error.message);\n\n/**\n * A Yoga plugin bounding what the parser is given: the tokens of every\n * document (`maxTokens`) and the levels it nests (`maxNesting`, a scan of the\n * source before any recursion). A document the parser still overflows the\n * stack on is refused the same way, never a 500. It wraps the parse function\n * Envelop already holds, never graphql's own `parse`: a second copy of\n * graphql would throw errors Yoga does not recognise, masked as a 500.\n */\nexport function limitsParsing(\n\tmaxTokens: number | false,\n\tmaxNesting: number | false,\n): Plugin {\n\treturn {\n\t\tonParse({ parseFn, setParseFn }) {\n\t\t\tsetParseFn((source, options) => {\n\t\t\t\tconst body = typeof source === 'string' ? source : source.body;\n\t\t\t\tconst refuse = (position: number, why: string) =>\n\t\t\t\t\tsyntaxError(\n\t\t\t\t\t\ttypeof source === 'string' ? new Source(source) : source,\n\t\t\t\t\t\tposition,\n\t\t\t\t\t\twhy,\n\t\t\t\t\t);\n\t\t\t\tif (maxNesting !== false) {\n\t\t\t\t\tconst at = tooDeepAt(body, maxNesting);\n\t\t\t\t\tif (at >= 0) {\n\t\t\t\t\t\tthrow refuse(\n\t\t\t\t\t\t\tat,\n\t\t\t\t\t\t\t`Document is nested more than ${maxNesting} levels deep. Parsing aborted.`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\treturn parseFn(\n\t\t\t\t\t\tsource,\n\t\t\t\t\t\tmaxTokens === false ? options : { ...options, maxTokens },\n\t\t\t\t\t);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (!overflowed(error)) throw error;\n\t\t\t\t\tthrow refuse(0, 'Document is nested too deeply to parse.');\n\t\t\t\t}\n\t\t\t});\n\t\t},\n\t};\n}\n\n/** What Yoga's `parserAndValidationCache` takes from alxia. */\nexport type ParseCaches =\n\t| false\n\t| {\n\t\t\tdocumentCache: Cache<DocumentNode>;\n\t\t\terrorCache: Cache<unknown>;\n\t };\n\n/** The sizes of a parse cache, checked. */\ninterface CacheSizes {\n\treadonly maxBytes: number;\n\treadonly max: number;\n\treadonly ttl: number;\n}\n\n/** `parseCache` checked where `graphql()` is declared; allocates nothing. */\nfunction cacheSizes(\n\tparseCache: false | ParseCacheOptions | undefined,\n): CacheSizes | false {\n\tif (parseCache === false) return false;\n\tif (\n\t\tparseCache !== undefined &&\n\t\t(typeof parseCache !== 'object' || parseCache === null)\n\t) {\n\t\tthrow new TypeError(\n\t\t\t`graphql(app, { parseCache }): parseCache is an object of cache sizes, or false for none; got ${String(parseCache)}`,\n\t\t);\n\t}\n\tconst given = parseCache ?? {};\n\treturn {\n\t\tmaxBytes: positive(\n\t\t\t'parseCache.maxBytes',\n\t\t\tgiven.maxBytes ?? DEFAULT_BYTES,\n\t\t\t'maxBytes is the most estimated bytes of documents kept',\n\t\t),\n\t\tmax: positive(\n\t\t\t'parseCache.max',\n\t\t\tgiven.max ?? 1024,\n\t\t\t'max is the most documents kept',\n\t\t),\n\t\tttl: positive(\n\t\t\t'parseCache.ttl',\n\t\t\tgiven.ttl ?? 3_600_000,\n\t\t\t'ttl is the milliseconds a document is kept',\n\t\t),\n\t};\n}\n\n/**\n * The limits `graphql()` was given, checked once at declaration: the token\n * cap and the nesting limit, resolved, and the parse cache, which cannot be given beside Yoga's\n * own. Each endpoint's Yoga builds its caches from the same options.\n */\nexport function resolveLimits(\n\tmaxTokens: number | false | undefined,\n\tmaxNesting: number | false | undefined,\n\tparseCache: false | ParseCacheOptions | undefined,\n\tyogaOptions: Pick<\n\t\tYogaServerOptions<YogaContext, YogaContext>,\n\t\t'parserAndValidationCache'\n\t>,\n): { readonly tokens: number | false; readonly depth: number | false } {\n\tconst tokens = tokenLimit(maxTokens);\n\tconst depth = nestingLimit(maxNesting);\n\tif (\n\t\tparseCache !== undefined &&\n\t\tyogaOptions.parserAndValidationCache !== undefined\n\t) {\n\t\tthrow new TypeError(\n\t\t\t\"graphql(app, { parseCache, parserAndValidationCache }): give one: parseCache sizes alxia's bounded cache, parserAndValidationCache replaces it\",\n\t\t);\n\t}\n\tcacheSizes(parseCache);\n\treturn { tokens, depth };\n}\n\n/**\n * The `parserAndValidationCache` of one Yoga: a pair of bounded caches,\n * created per call so each endpoint has its own. `false` gives none.\n */\nexport function parseCaches(\n\tparseCache: false | ParseCacheOptions | undefined,\n): ParseCaches {\n\tconst sizes = cacheSizes(parseCache);\n\tif (sizes === false) return false;\n\tconst { maxBytes, max, ttl } = sizes;\n\tconst documentCache = boundedCache<DocumentNode>({\n\t\tmax,\n\t\tttl,\n\t\tmaxBytes,\n\t\tweigh: (source, document) => documentWeight(source, document),\n\t});\n\tconst errorCache = boundedCache<unknown>({\n\t\tmax,\n\t\tttl,\n\t\tmaxBytes: Math.floor(maxBytes / 8),\n\t\tweigh: (source) => errorWeight(source),\n\t});\n\treturn { documentCache, errorCache };\n}\n",
|
|
12
12
|
"/**\n * The parse cache `graphql()` gives Yoga: a least-recently-used map bounded\n * by entries, by age and by estimated bytes, since a parsed document costs\n * by its tokens and no count of entries bounds that.\n */\nimport { type DocumentNode, type Token, TokenKind } from 'graphql';\n\n/** Yoga's `Cache` contract. */\nexport interface Cache<T> {\n\tget(key: string): T | undefined;\n\tset(key: string, value: T): void;\n}\n\nexport interface BoundedCacheOptions<T> {\n\t/** The most entries kept. */\n\treadonly max: number;\n\t/** How long an entry lives, in milliseconds. */\n\treadonly ttl: number;\n\t/** The most estimated bytes kept, the sum of the weights. */\n\treadonly maxBytes: number;\n\t/** The estimated bytes an entry holds. */\n\treadonly weigh: (key: string, value: T) => number;\n\t/** The clock, in milliseconds; injectable for the specs. */\n\treadonly now?: () => number;\n}\n\ninterface Entry<T> {\n\treadonly value: T;\n\treadonly weight: number;\n\treadonly expires: number;\n}\n\n/**\n * A least-recently-used cache that evicts by `max`, `ttl` and `maxBytes`.\n * An entry heavier than `maxBytes / 8` is not stored and evicts nothing.\n */\nexport function boundedCache<T>(options: BoundedCacheOptions<T>): Cache<T> {\n\tconst { max, ttl, maxBytes, weigh, now = Date.now } = options;\n\tconst entries = new Map<string, Entry<T>>();\n\tlet total = 0;\n\n\tconst drop = (key: string, entry: Entry<T>): void => {\n\t\tentries.delete(key);\n\t\ttotal -= entry.weight;\n\t};\n\n\treturn {\n\t\tget(key) {\n\t\t\tconst entry = entries.get(key);\n\t\t\tif (entry === undefined) return undefined;\n\t\t\tif (entry.expires <= now()) {\n\t\t\t\tdrop(key, entry);\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\t// Map keeps insertion order: re-insert to mark it recent.\n\t\t\tentries.delete(key);\n\t\t\tentries.set(key, entry);\n\t\t\treturn entry.value;\n\t\t},\n\t\tset(key, value) {\n\t\t\tconst previous = entries.get(key);\n\t\t\tif (previous !== undefined) drop(key, previous);\n\t\t\tconst weight = weigh(key, value);\n\t\t\tif (weight > maxBytes / 8) return;\n\t\t\tentries.set(key, { value, weight, expires: now() + ttl });\n\t\t\ttotal += weight;\n\t\t\tfor (const [oldest, entry] of entries) {\n\t\t\t\tif (entries.size <= max && total <= maxBytes) break;\n\t\t\t\tdrop(oldest, entry);\n\t\t\t}\n\t\t},\n\t};\n}\n\n/** The measured upper bound of a parsed token's heap cost, in bytes. */\nconst BYTES_PER_TOKEN = 512;\n\n/** The bytes counted per source character: the source key, plus a token's value. */\nconst BYTES_PER_CHAR = 4;\n\n/**\n * The bytes counted per source character of a string literal with escapes.\n * graphql 16 builds its value with `+=`, once per escape, which in\n * JavaScriptCore leaves a rope the token and its node keep alive. Measured\n * without the flatten: 31.6 B per source char for `\\n`, 28 for `Ā\\n`, 13.7\n * for `Ā`; 32 covers them.\n */\nconst BYTES_PER_ESCAPED_CHAR = 32;\n\n/** The bytes counted per source character of a document without `loc`: 4 + 32. */\nconst BYTES_PER_CHAR_NO_LOC = BYTES_PER_CHAR + BYTES_PER_ESCAPED_CHAR;\n\n/**\n * The last character read to flatten a string. The JIT removes a read whose\n * result nobody uses, and the flatten with it, so the result is stored.\n */\nlet flattened = 0;\n\n/**\n * The tokens the lexer linked for a document, comments included (graphql's\n * `tokenCount` and `maxTokens` skip comments, yet `loc.startToken` keeps the\n * whole chain alive), and the extra bytes of its escaped string literals.\n * Undefined when the document has no `loc`.\n */\nfunction chainWalk(\n\tdocument: DocumentNode,\n): { tokens: number; extra: number } | undefined {\n\tconst first = document.loc?.startToken;\n\tif (first === undefined) return undefined;\n\tlet tokens = 0;\n\tlet extra = 0;\n\tfor (let token: Token | null = first; token !== null; token = token.next) {\n\t\ttokens++;\n\t\t// A string with escapes has a value shorter than its source span (minus\n\t\t// the two quotes). Its rope is charged by the span, and flattened as an\n\t\t// optimisation: reading a character flattens it in place (the token and\n\t\t// the node share it). A raw literal or a block string is already flat or\n\t\t// a substring of the key, and flattening would copy it out. Keep\n\t\t// `flattened` used: see above.\n\t\tif (\n\t\t\ttoken.kind === TokenKind.STRING &&\n\t\t\ttoken.value.length < token.end - token.start - 2\n\t\t) {\n\t\t\textra += BYTES_PER_ESCAPED_CHAR * (token.end - token.start);\n\t\t\tif (token.value.length > 0) flattened = token.value.charCodeAt(0);\n\t\t}\n\t}\n\t// Read here so the writes above are not dead code.\n\treturn { tokens, extra: extra + (flattened & 0) };\n}\n\n/**\n * A parsed document's estimated bytes: every token the lexer linked,\n * comments included, plus the source as the key and as token values, plus\n * 32 B per char of escaped string literals. Without `loc` (`noLocation`),\n * nothing tells where the strings are: `tokenCount` and 36 B per char stand\n * in; without `tokenCount` (older graphql), the source's length does.\n */\nexport function documentWeight(source: string, document: DocumentNode): number {\n\tconst walk = chainWalk(document);\n\tif (walk !== undefined) {\n\t\treturn (\n\t\t\tBYTES_PER_TOKEN * walk.tokens +\n\t\t\tBYTES_PER_CHAR * source.length +\n\t\t\twalk.extra\n\t\t);\n\t}\n\tconst tokenCount = (document as { tokenCount?: number }).tokenCount;\n\tif (typeof tokenCount !== 'number') {\n\t\treturn Math.max(256, BYTES_PER_CHAR_NO_LOC) * source.length;\n\t}\n\treturn BYTES_PER_TOKEN * tokenCount + BYTES_PER_CHAR_NO_LOC * source.length;\n}\n\n/** A parse error's estimated bytes: its source as the key, and the error (1 024 B). */\nexport function errorWeight(source: string): number {\n\treturn BYTES_PER_CHAR * source.length + 1024;\n}\n",
|
|
13
13
|
"/**\n * How deep a document may nest. graphql-js parses by recursion, one set of\n * frames per `{`, `(` or `[`, so a document a few thousand levels deep\n * overflows the stack (a `RangeError`) long before `maxTokens` stops it,\n * and Yoga answers that with a 500. A linear scan of the source counts the\n * nesting first, without recursing.\n */\n\n/** The most levels of `{`, `(` and `[` a document may nest, unless `maxNesting` says otherwise. */\nexport const DEFAULT_MAX_NESTING = 1000;\n\n/** `maxNesting` checked where `graphql()` is declared. */\nexport function nestingLimit(\n\tmaxNesting: number | false | undefined,\n): number | false {\n\tif (maxNesting === undefined) return DEFAULT_MAX_NESTING;\n\tif (maxNesting === false) return false;\n\tif (typeof maxNesting === 'number' && Number.isSafeInteger(maxNesting)) {\n\t\tif (maxNesting > 0) return maxNesting;\n\t}\n\tthrow new TypeError(\n\t\t`graphql(app, { maxNesting }): maxNesting is the most levels of { ( [ a document may nest, a positive whole number, or false for none; got ${String(maxNesting)}`,\n\t);\n}\n\nconst QUOTE = 34; // \"\nconst BACKSLASH = 92;\nconst HASH = 35; // #\nconst LF = 10;\nconst CR = 13;\n\n/**\n * The offset of the first bracket that nests `body` deeper than `max`\n * levels, or -1. Brackets inside strings, block strings and comments are\n * text, not nesting; an unbalanced closing bracket is left to the parser.\n */\nexport function tooDeepAt(body: string, max: number): number {\n\tlet depth = 0;\n\tconst end = body.length;\n\tfor (let i = 0; i < end; i++) {\n\t\tconst code = body.charCodeAt(i);\n\t\tif (code === 123 || code === 40 || code === 91) {\n\t\t\t// { ( [\n\t\t\tif (++depth > max) return i;\n\t\t} else if (code === 125 || code === 41 || code === 93) {\n\t\t\t// } ) ]\n\t\t\tif (depth > 0) depth--;\n\t\t} else if (code === HASH) {\n\t\t\twhile (i + 1 < end) {\n\t\t\t\tconst next = body.charCodeAt(i + 1);\n\t\t\t\tif (next === LF || next === CR) break;\n\t\t\t\ti++;\n\t\t\t}\n\t\t} else if (code === QUOTE) {\n\t\t\tif (body.startsWith('\"\"\"', i)) {\n\t\t\t\ti += 3;\n\t\t\t\twhile (i < end) {\n\t\t\t\t\tif (body.startsWith('\\\\\"\"\"', i)) i += 4;\n\t\t\t\t\telse if (body.startsWith('\"\"\"', i)) break;\n\t\t\t\t\telse i++;\n\t\t\t\t}\n\t\t\t\ti += 2;\n\t\t\t} else {\n\t\t\t\ti++;\n\t\t\t\twhile (i < end) {\n\t\t\t\t\tconst inString = body.charCodeAt(i);\n\t\t\t\t\tif (inString === BACKSLASH) i += 2;\n\t\t\t\t\telse if (inString === QUOTE || inString === LF || inString === CR) {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t} else i++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn -1;\n}\n",
|
|
14
14
|
"import type { Empty } from '@alxia/core';\nimport type {\n\tGraphQLSchemaWithContext,\n\tYogaInitialContext,\n\tYogaServerOptions,\n} from 'graphql-yoga';\nimport type { YogaContext } from './handler';\nimport type { ParseCacheOptions } from './parse-limits';\nimport { yogaFor } from './yoga';\n\n/** What an in-process call asks for: a GraphQL-over-HTTP request's parameters. */\nexport interface ExecutorRequest {\n\treadonly query: string;\n\treadonly operationName?: string | undefined;\n\treadonly variables?: Readonly<Record<string, unknown>> | undefined;\n}\n\n/** A plain, JSON-shaped error, as the route answers it. */\nexport interface ExecutorError {\n\treadonly message: string;\n\treadonly path?: readonly (string | number)[];\n\treadonly locations?: readonly { line: number; column: number }[];\n\treadonly extensions?: Readonly<Record<string, unknown>>;\n}\n\n/** The answer: `data` and `errors`, as the endpoint's JSON body. */\nexport interface ExecutorResult {\n\treadonly data?: unknown;\n\treadonly errors?: readonly ExecutorError[];\n}\n\n/** Per call: the signal that stops the operation, as a client leaving does. */\nexport interface ExecutorCall {\n\treadonly signal?: AbortSignal;\n}\n\n/**\n * The options of `graphqlExecutor()`: those of `graphql()` that mean\n * something without a route. Put an HTTP-only plugin (a client-header\n * check, `cache-control`) in the route's list and not here.\n */\nexport interface GraphQLExecutorOptions<\n\tServerCtx extends YogaContext,\n\tUserCtx extends YogaContext,\n\tSchemaCtx = unknown,\n> extends Omit<\n\t\tYogaServerOptions<ServerCtx, UserCtx>,\n\t\t| 'graphqlEndpoint'\n\t\t| 'cors'\n\t\t| 'schema'\n\t\t| 'graphiql'\n\t\t| 'landingPage'\n\t\t| 'parserAndValidationCache'\n\t> {\n\t/** The schema, as for `graphql()`. */\n\treadonly schema: GraphQLSchemaWithContext<SchemaCtx>;\n\t/** At most this many tokens in a document, 15 000 by default, or `false`. */\n\treadonly maxTokens?: number | false;\n\t/** At most this many levels of `{`, `(` and `[`, 1 000 by default, or `false`. */\n\treadonly maxNesting?: number | false;\n\t/** The cache of parsed documents, this executor's own. `false` parses every call. */\n\treadonly parseCache?: false | ParseCacheOptions;\n}\n\n/** Runs one operation in process. */\nexport type GraphQLExecutor<ServerCtx> = (\n\trequest: ExecutorRequest,\n\tcontext: ServerCtx,\n\tcall?: ExecutorCall,\n) => Promise<ExecutorResult>;\n\nconst SUBSCRIPTION_REFUSED: ExecutorResult = {\n\terrors: [\n\t\t{\n\t\t\tmessage:\n\t\t\t\t'graphqlExecutor runs queries and mutations, not a subscription.',\n\t\t\textensions: { code: 'SUBSCRIPTION_NOT_SUPPORTED' },\n\t\t},\n\t],\n};\n\n/**\n * Runs a GraphQL operation in the process, through the same Yoga setup as\n * `graphql()` — its plugins, `maxTokens`, `maxNesting`, the parse cache, the\n * masking of errors — with a server context the caller gives, and no HTTP\n * route in between. For a caller that is not a browser: an MCP tool, a job.\n * Queries and mutations only.\n *\n * ```ts\n * const execute = graphqlExecutor({ schema, plugins: [useJanus(...)] });\n * const { data, errors } = await execute(\n * { query: '{ me { id } }' },\n * { viewer, services },\n * );\n * ```\n *\n * It does not run `graphql()`'s middlewares: the context is whatever is\n * passed. It keeps its own parse cache, apart from the route's.\n */\nexport function graphqlExecutor<\n\tSchemaCtx,\n\tUserCtx extends YogaContext = Empty,\n\tServerCtx = Omit<SchemaCtx, keyof YogaInitialContext>,\n>(\n\toptions: GraphQLExecutorOptions<YogaContext, UserCtx, SchemaCtx>,\n): GraphQLExecutor<ServerCtx> {\n\tconst yoga = yogaFor<UserCtx>(options, { cors: false, ide: false })(\n\t\t'/graphql',\n\t);\n\treturn async (request, context, call) => {\n\t\tconst response = await yoga.fetch(\n\t\t\tnew Request('http://in-process/graphql', {\n\t\t\t\tmethod: 'POST',\n\t\t\t\theaders: {\n\t\t\t\t\t'content-type': 'application/json',\n\t\t\t\t\taccept: 'application/json, text/event-stream',\n\t\t\t\t},\n\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\tquery: request.query,\n\t\t\t\t\t...(request.operationName !== undefined && {\n\t\t\t\t\t\toperationName: request.operationName,\n\t\t\t\t\t}),\n\t\t\t\t\t...(request.variables !== undefined && {\n\t\t\t\t\t\tvariables: request.variables,\n\t\t\t\t\t}),\n\t\t\t\t}),\n\t\t\t\t...(call?.signal !== undefined && { signal: call.signal }),\n\t\t\t}),\n\t\t\tcontext as never,\n\t\t);\n\t\tif (\n\t\t\t/text\\/event-stream|multipart\\/mixed/.test(\n\t\t\t\tresponse.headers.get('content-type') ?? '',\n\t\t\t)\n\t\t) {\n\t\t\tvoid response.body?.cancel();\n\t\t\treturn SUBSCRIPTION_REFUSED;\n\t\t}\n\t\tconst body = (await response.json()) as ExecutorResult;\n\t\treturn {\n\t\t\t...(body.data !== undefined && { data: body.data }),\n\t\t\t...(body.errors !== undefined && { errors: body.errors }),\n\t\t};\n\t};\n}\n",
|
|
15
|
+
"import {\n\ttype DocumentNode,\n\ttype FragmentDefinitionNode,\n\tprint,\n\ttype SelectionSetNode,\n} from 'graphql';\n\n/** How a field was selected: how many times, and under how many distinct response keys and arguments. */\nexport interface Selected {\n\tcount: number;\n\treadonly distinct: Set<string>;\n}\n\ntype Counts = Map<string, Selected>;\n\n/**\n * `distinct` only has to tell one path from two or more (`single`), so it is\n * built for the `singles` alone and holds at most 2 paths. That is sound: a\n * set of 2 or more distinct relative paths stays that after any prefix; a\n * union of sets cut to 2 has 2 or more elements whenever the true union does\n * (one input already has 2, or all have at most 1 and are exact). A document\n * whose fragments fan out (`{ x: y { ...F1 } z: y { ...F1 } }` down forty\n * levels) has 2^40 paths, and costs a few set entries here.\n *\n * How many times each of `names` is selected by `selections`, fragments\n * expanded. Counted per selection in the document, as written: a list\n * parent costs 1 however long the list, `@skip` and `@include` are not\n * evaluated, selections that merge at execution (the same alias twice) still\n * count each, and a field matches by name alone, on any type. A fragment is\n * walked once, so a document whose fragments spread each other many times\n * is counted in linear time. `distinct` holds each selection's response key\n * and arguments, so a field written twice the same way is one, under the same parents (the response keys and arguments above it).\n */\nexport function countSelections(\n\tdocument: DocumentNode,\n\tselections: SelectionSetNode,\n\tnames: ReadonlySet<string>,\n\tsingles: ReadonlySet<string> = new Set(),\n): Counts {\n\tconst fragments = new Map<string, FragmentDefinitionNode>();\n\tfor (const definition of document.definitions) {\n\t\tif (definition.kind === 'FragmentDefinition') {\n\t\t\tfragments.set(definition.name.value, definition);\n\t\t}\n\t}\n\tconst done = new Map<string, Counts>();\n\tconst active = new Set<string>();\n\tconst walk = (set: SelectionSetNode): Counts => {\n\t\tconst counts: Counts = new Map();\n\t\t// `from` merged in, each key under `under`: the path of the response\n\t\t// keys and arguments above it, which a fragment holds relative to itself.\n\t\tconst add = (from: Counts, under = '') => {\n\t\t\tfor (const [name, selected] of from) {\n\t\t\t\tconst own = counts.get(name) ?? { count: 0, distinct: new Set() };\n\t\t\t\town.count += selected.count;\n\t\t\t\tfor (const one of selected.distinct) {\n\t\t\t\t\tif (own.distinct.size >= 2) break;\n\t\t\t\t\town.distinct.add(under + one);\n\t\t\t\t}\n\t\t\t\tcounts.set(name, own);\n\t\t\t}\n\t\t};\n\t\tfor (const selection of set.selections) {\n\t\t\tif (selection.kind === 'Field') {\n\t\t\t\tconst name = selection.name.value;\n\t\t\t\tconst written = `${selection.alias?.value ?? name}(${(\n\t\t\t\t\tselection.arguments ?? []\n\t\t\t\t)\n\t\t\t\t\t.map((argument) => print(argument))\n\t\t\t\t\t.sort()\n\t\t\t\t\t.join(',')})`;\n\t\t\t\tif (names.has(name)) {\n\t\t\t\t\tconst own = counts.get(name) ?? { count: 0, distinct: new Set() };\n\t\t\t\t\town.count += 1;\n\t\t\t\t\tif (singles.has(name) && own.distinct.size < 2)\n\t\t\t\t\t\town.distinct.add(written);\n\t\t\t\t\tcounts.set(name, own);\n\t\t\t\t}\n\t\t\t\tif (selection.selectionSet) {\n\t\t\t\t\tadd(walk(selection.selectionSet), `${written}/`);\n\t\t\t\t}\n\t\t\t} else if (selection.kind === 'InlineFragment') {\n\t\t\t\tadd(walk(selection.selectionSet));\n\t\t\t} else {\n\t\t\t\tconst name = selection.name.value;\n\t\t\t\tconst fragment = fragments.get(name);\n\t\t\t\tif (fragment === undefined || active.has(name)) continue;\n\t\t\t\tlet own = done.get(name);\n\t\t\t\tif (own === undefined) {\n\t\t\t\t\tactive.add(name);\n\t\t\t\t\town = walk(fragment.selectionSet);\n\t\t\t\t\tactive.delete(name);\n\t\t\t\t\tdone.set(name, own);\n\t\t\t\t}\n\t\t\t\tadd(own);\n\t\t\t}\n\t\t}\n\t\treturn counts;\n\t};\n\treturn walk(selections);\n}\n",
|
|
16
|
+
"import type { CostlessStore, FieldLimit } from './types';\n\ninterface Given {\n\treadonly limit?: number;\n\treadonly windowMs?: number;\n}\n\n/**\n * A `@alxia/rate-limit` store as a `FieldLimit`. The store counts one hit\n * per call, so a cost of N is N consumes, stopped at the first refusal: up\n * to `limit + 1` round trips for one selection count, which a Redis-backed\n * store feels. The units spent before a refusal stay spent. For a large\n * limit, give `fieldRateLimit` a limit that takes the cost in one call (a\n * `@softistx/redis` bound limit).\n *\n * `policy` may be left out for a store that declares its own (`store.policy`,\n * as `redisStore` of a wired limit does); numbers that differ from the\n * store's are an error here, as in `rateLimit`. `limit` and `windowMs` are\n * whole numbers of 1 or more.\n */\nexport function limitFromStore(\n\tstore: CostlessStore,\n\tpolicy?: Given,\n): FieldLimit {\n\tconst own = store.policy;\n\tconst resolved = {\n\t\tlimit: policy?.limit ?? own?.limit ?? Number.NaN,\n\t\twindowMs: policy?.windowMs ?? own?.windowMs ?? Number.NaN,\n\t};\n\tfor (const name of ['limit', 'windowMs'] as const) {\n\t\tconst value = resolved[name];\n\t\tif (!Number.isSafeInteger(value) || value < 1) {\n\t\t\tthrow new TypeError(\n\t\t\t\t`limitFromStore: ${name} must be a whole number of 1 or more, not ${String(policy?.[name] ?? own?.[name])}`,\n\t\t\t);\n\t\t}\n\t\tif (own !== undefined && value !== own[name]) {\n\t\t\tthrow new TypeError(\n\t\t\t\t`limitFromStore: ${name} ${value} differs from the store's policy of ${own.limit} per ${own.windowMs}ms. Leave the policy out to use the store's, or give the same numbers.`,\n\t\t\t);\n\t\t}\n\t}\n\treturn {\n\t\tasync consume(key, cost) {\n\t\t\tfor (let i = 0; i < cost; i++) {\n\t\t\t\tconst decision = await store.consume(key, resolved);\n\t\t\t\tif (!decision.allowed) {\n\t\t\t\t\treturn { allowed: false, retryAfter: decision.retryAfter };\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn { allowed: true, retryAfter: 0 };\n\t\t},\n\t};\n}\n",
|
|
17
|
+
"import { GraphQLError, getOperationAST } from 'graphql';\nimport type { Plugin } from 'graphql-yoga';\nimport { countSelections } from './count';\nimport { ipv6Network } from './ipv6-network';\nimport type { FieldLimit, FieldRateLimitOptions } from './types';\n\n/** The `extensions.code` of an over-limit refusal, unless `code` says otherwise. */\nexport const DEFAULT_LIMIT_CODE = 'RATE_LIMITED';\n\ninterface Rule {\n\treadonly limit: FieldLimit;\n\treadonly single: boolean;\n}\n\nfunction rulesOf(fields: FieldRateLimitOptions['fields']): Map<string, Rule> {\n\tif (\n\t\ttypeof fields !== 'object' ||\n\t\tfields === null ||\n\t\tObject.keys(fields).length === 0\n\t) {\n\t\tthrow new TypeError(\n\t\t\t'fieldRateLimit({ fields }): fields maps each field name to count to its limit, and holds at least one',\n\t\t);\n\t}\n\tconst rules = new Map<string, Rule>();\n\tfor (const [name, rule] of Object.entries(fields)) {\n\t\tconst wrapped =\n\t\t\ttypeof rule === 'object' &&\n\t\t\trule !== null &&\n\t\t\t'limit' in rule &&\n\t\t\ttypeof rule.limit === 'object';\n\t\tconst limit = (wrapped ? rule.limit : rule) as FieldLimit | null;\n\t\tif (typeof limit?.consume !== 'function') {\n\t\t\tthrow new TypeError(\n\t\t\t\t`fieldRateLimit({ fields: { ${name} } }): a limit has a consume(key, cost) method, or is { limit, single? }`,\n\t\t\t);\n\t\t}\n\t\trules.set(name, {\n\t\t\tlimit,\n\t\t\tsingle: wrapped && (rule as { single?: boolean }).single === true,\n\t\t});\n\t}\n\treturn rules;\n}\n\nfunction checked(options: FieldRateLimitOptions): void {\n\tconst { ipv6Prefix } = options;\n\tif (ipv6Prefix !== undefined) {\n\t\tif (!Number.isInteger(ipv6Prefix) || ipv6Prefix < 0 || ipv6Prefix > 128) {\n\t\t\tthrow new TypeError(\n\t\t\t\t`fieldRateLimit: ipv6Prefix must be a whole number from 0 to 128, not ${String(ipv6Prefix)}`,\n\t\t\t);\n\t\t}\n\t\tif (options.key !== undefined) {\n\t\t\tthrow new TypeError(\n\t\t\t\t'fieldRateLimit: ipv6Prefix applies to the default key, and a key of your own was given. Drop one, or group the address in your key.',\n\t\t\t);\n\t\t}\n\t}\n\tconst { code } = options;\n\tif (code !== undefined && (typeof code !== 'string' || code === '')) {\n\t\tthrow new TypeError('fieldRateLimit: code is a non-empty string');\n\t}\n}\n\n/** One refusal, as the answer Yoga sends: the error carries its status and headers. */\nfunction refusal(\n\tmessage: string,\n\tcode: string,\n\tstatus: number,\n\textensions: Record<string, unknown> = {},\n\theaders?: Record<string, string>,\n) {\n\treturn {\n\t\terrors: [\n\t\t\tnew GraphQLError(message, {\n\t\t\t\textensions: {\n\t\t\t\t\tcode,\n\t\t\t\t\t...extensions,\n\t\t\t\t\thttp: headers === undefined ? { status } : { status, headers },\n\t\t\t\t},\n\t\t\t}),\n\t\t],\n\t};\n}\n\n/**\n * A Yoga plugin that counts every selection of the chosen fields in the\n * operation about to execute (aliases and fragments included) and consumes\n * that cost on each field's limit, keyed by the client. Past a limit the\n * operation does not run: a 429 with `extensions.code` `RATE_LIMITED`\n * (the `code` option; `TOO_MANY_ATTEMPTS` for a sign-in, say) and `retryAfter` (seconds, also the `Retry-After`\n * header). `{ limit, single: true }` refuses the field selected more than\n * once in the document with a 400 `FIELD_SELECTED_ONCE`, a field written the\n * same way twice (same parents, response key and arguments) counting once.\n *\n * The check runs in `onExecute` itself, so a plugin after it that replaces\n * the execute function does not drop it; still, list it first in\n * `graphql({ plugins })`. Fields are charged in the order the document first selects them: units spent\n * on one field before a refusal stay spent, and so do earlier fields when a\n * later one is refused. Subscriptions are not counted. Under `batching` each\n * operation is checked on its own, and a refused one is an error in a 200\n * array, with no `Retry-After` header.\n *\n * ```ts\n * fieldRateLimit({ fields: { signIn: limitFromStore(store, { limit: 5, windowMs: 60_000 }) } })\n * ```\n */\nexport function fieldRateLimit<Ctx extends object = any>(\n\toptions: FieldRateLimitOptions<Ctx>,\n): Plugin {\n\tconst rules = rulesOf(options.fields);\n\tchecked(options);\n\tconst names = new Set(rules.keys());\n\tconst singles = new Set(\n\t\t[...rules].filter(([, r]) => r.single).map(([n]) => n),\n\t);\n\tconst code = options.code ?? DEFAULT_LIMIT_CODE;\n\tconst prefix = options.ipv6Prefix;\n\tconst keyOf =\n\t\toptions.key ??\n\t\t((ctx: Ctx) => {\n\t\t\tconst { ip } = ctx as { ip?: string };\n\t\t\treturn prefix === undefined || ip === undefined\n\t\t\t\t? ip\n\t\t\t\t: ipv6Network(ip, prefix);\n\t\t});\n\treturn {\n\t\tasync onExecute({ args, setResultAndStopExecution }) {\n\t\t\tconst operation = getOperationAST(args.document, args.operationName);\n\t\t\tif (!operation) return;\n\t\t\tconst counts = countSelections(\n\t\t\t\targs.document,\n\t\t\t\toperation.selectionSet,\n\t\t\t\tnames,\n\t\t\t\tsingles,\n\t\t\t);\n\t\t\tif (counts.size === 0) return;\n\t\t\tfor (const [name, selected] of counts) {\n\t\t\t\tif (rules.get(name)?.single && selected.distinct.size > 1) {\n\t\t\t\t\treturn setResultAndStopExecution(\n\t\t\t\t\t\trefusal(\n\t\t\t\t\t\t\t`${name} may be selected once per operation`,\n\t\t\t\t\t\t\t'FIELD_SELECTED_ONCE',\n\t\t\t\t\t\t\t400,\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst who = await keyOf(args.contextValue as Ctx);\n\t\t\tif (who === undefined) return;\n\t\t\tfor (const [name, selected] of counts) {\n\t\t\t\tconst decision = await (rules.get(name) as Rule).limit.consume(\n\t\t\t\t\t`${name}:${who}`,\n\t\t\t\t\tselected.count,\n\t\t\t\t);\n\t\t\t\tif (!decision.allowed) {\n\t\t\t\t\tconst wait = Math.ceil(decision.retryAfter / 1000);\n\t\t\t\t\tconst retryAfter = Number.isFinite(wait) ? Math.max(1, wait) : 1;\n\t\t\t\t\treturn setResultAndStopExecution(\n\t\t\t\t\t\trefusal(\n\t\t\t\t\t\t\t'Too many attempts, try again later',\n\t\t\t\t\t\t\tcode,\n\t\t\t\t\t\t\t429,\n\t\t\t\t\t\t\t{ retryAfter },\n\t\t\t\t\t\t\t{ 'retry-after': String(retryAfter) },\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t};\n}\n",
|
|
18
|
+
"/** The eight 16-bit groups of an IPv6 address, or `undefined` when `text` is not one. */\nfunction groupsOf(text: string): number[] | undefined {\n\tconst zone = text.indexOf('%');\n\tconst address = zone === -1 ? text : text.slice(0, zone);\n\tconst halves = address.split('::');\n\tif (halves.length > 2 || !address.includes(':')) return undefined;\n\tconst read = (half: string | undefined): string[] | undefined =>\n\t\thalf === undefined || half === '' ? [] : half.split(':');\n\tconst head = read(halves[0]) ?? [];\n\tconst tail = read(halves[1]) ?? [];\n\tconst written = [...head, ...tail];\n\tconst last = written[written.length - 1];\n\tif (last?.includes('.')) {\n\t\t// The dotted form ends the address: `1.2.3.4::` is not one.\n\t\tif (!address.endsWith(last)) return undefined;\n\t\tconst octets = last.split('.');\n\t\tconst bytes = octets.map((octet) =>\n\t\t\t/^\\d{1,3}$/.test(octet) ? Number(octet) : Number.NaN,\n\t\t);\n\t\tif (bytes.length !== 4 || bytes.some((byte) => !(byte <= 255)))\n\t\t\treturn undefined;\n\t\tconst [a = 0, b = 0, c = 0, d = 0] = bytes;\n\t\twritten.splice(\n\t\t\t-1,\n\t\t\t1,\n\t\t\t((a << 8) | b).toString(16),\n\t\t\t((c << 8) | d).toString(16),\n\t\t);\n\t\tif (tail.length > 0) tail.splice(-1, 1, 'x', 'x');\n\t\telse head.splice(-1, 1, 'x', 'x');\n\t}\n\tconst compressed = halves.length === 2;\n\tconst missing = 8 - written.length;\n\tif (compressed ? missing < 1 : missing !== 0) return undefined;\n\tconst all = compressed\n\t\t? [\n\t\t\t\t...written.slice(0, head.length),\n\t\t\t\t...new Array<string>(missing).fill('0'),\n\t\t\t\t...written.slice(head.length),\n\t\t\t]\n\t\t: written;\n\tconst groups = all.map((group) =>\n\t\t/^[0-9a-f]{1,4}$/i.test(group) ? Number.parseInt(group, 16) : Number.NaN,\n\t);\n\treturn groups.some(Number.isNaN) ? undefined : groups;\n}\n\n/** RFC 5952: the longest run of two or more zero groups (the first on a tie) as `::`. */\nfunction written(groups: readonly number[]): string {\n\tlet start = -1;\n\tlet length = 0;\n\tfor (let i = 0; i < 8; ) {\n\t\tif (groups[i] !== 0) {\n\t\t\ti++;\n\t\t\tcontinue;\n\t\t}\n\t\tlet end = i;\n\t\twhile (end < 8 && groups[end] === 0) end++;\n\t\tif (end - i > length) {\n\t\t\tstart = i;\n\t\t\tlength = end - i;\n\t\t}\n\t\ti = end;\n\t}\n\tconst hex = (list: readonly number[]) =>\n\t\tlist.map((group) => group.toString(16)).join(':');\n\tif (length < 2) return hex(groups);\n\treturn `${hex(groups.slice(0, start))}::${hex(groups.slice(start + length))}`;\n}\n\n/**\n * The network of an IPv6 `address` under `prefix` bits, as `2001:db8:1:2::/64`\n * writes it. An IPv4-mapped address (`::ffff:203.0.113.9`) is its IPv4 address,\n * a zone id (`%eth0`) is dropped, and a text that is not an IPv6 address\n * (an IPv4 one included) is returned as it is.\n */\nexport function ipv6Network(address: string, prefix: number): string {\n\tconst groups = groupsOf(address);\n\tif (groups === undefined) return address;\n\tif (\n\t\tgroups.slice(0, 5).every((group) => group === 0) &&\n\t\tgroups[5] === 0xffff\n\t) {\n\t\tconst [a = 0, b = 0] = groups.slice(6);\n\t\treturn `${a >> 8}.${a & 255}.${b >> 8}.${b & 255}`;\n\t}\n\tconst masked = groups.map((group, index) => {\n\t\tconst kept = Math.min(16, Math.max(0, prefix - index * 16));\n\t\treturn (group >> (16 - kept)) << (16 - kept);\n\t});\n\treturn `${written(masked.map((group) => group & 0xffff))}/${prefix}`;\n}\n",
|
|
15
19
|
"import type { Alxia } from '@alxia/core';\nimport type { graphqlSocket } from './ws';\n\n/** The body limit of a `POST` when neither the option nor the app gives one: 1 MiB. */\nconst DEFAULT_BODY_LIMIT = 1_048_576;\n\n/** `GET` and `POST` at `path` on `app`, and the WebSocket when `ws` is on. */\nexport function declareEndpoint(\n\tapp: Alxia<never, string>,\n\tpath: string,\n\thandler: unknown,\n\tbodyLimit: number | undefined,\n\tsocket: ReturnType<typeof graphqlSocket> | undefined,\n): void {\n\tconst route = app as unknown as {\n\t\tget(path: string, handler: unknown): unknown;\n\t\tpost(path: string, ...rest: unknown[]): unknown;\n\t\tws(path: string, ...rest: unknown[]): unknown;\n\t};\n\troute.get(path, handler);\n\t// The GET just declared has the POST's scope: a limit an earlier\n\t// `bodyLimit()` gives it is the one the POST keeps, and core refuses a\n\t// declared oversize body where that `bodyLimit()` stands, so the POST\n\t// passes no option of its own then (a route's own option would move the\n\t// refusal to the head of its steps).\n\tconst inherited = app.routes.at(-1)?.bodyLimit;\n\tconst own =\n\t\tbodyLimit ?? (inherited === undefined ? DEFAULT_BODY_LIMIT : undefined);\n\tif (own === undefined) route.post(path, handler);\n\telse route.post(path, { bodyLimit: own }, handler);\n\tif (socket !== undefined) {\n\t\troute.ws(socket.path, socket.middleware, socket.handlers);\n\t}\n}\n",
|
|
16
20
|
"/**\n * Each operation of a socket, from its `subscribe` to its end, told to the\n * observers around the socket's upgrade — `@alxia/logger`,\n * `@alxia/telemetry` — through core's `startOperation`: its type and name,\n * then whether it ended with errors.\n */\nimport { type OperationOutcome, startOperation } from '@alxia/core';\nimport { type DocumentNode, getOperationAST } from 'graphql';\nimport type { ServerOptions } from 'graphql-ws';\n\n/** An operation started, until it ends. */\ninterface Open {\n\treadonly end: (outcome: OperationOutcome) => void;\n\toutcome: OperationOutcome;\n}\n\n/** The operations of one socket, by their `graphql-ws` id. */\nexport class SocketOperations {\n\treadonly #ctx: object;\n\treadonly #open = new Map<string, Open>();\n\n\t/** `ctx`: the socket's context, which carries its upgrade's observers. */\n\tconstructor(ctx: object) {\n\t\tthis.#ctx = ctx;\n\t}\n\n\t/** The operation `id` starts: the one of `document` that `operationName` names. */\n\tbegin(\n\t\tid: string,\n\t\tdocument: DocumentNode,\n\t\toperationName: string | null | undefined,\n\t): void {\n\t\t// graphql-ws closes a socket that reuses an open id; end it all the same.\n\t\tthis.end(id);\n\t\tconst operation = getOperationAST(document, operationName);\n\t\tif (operation === undefined || operation === null) return;\n\t\tconst end = startOperation(this.#ctx, {\n\t\t\ttype: operation.operation,\n\t\t\tname: operation.name?.value,\n\t\t});\n\t\tthis.#open.set(id, { end, outcome: 'ok' });\n\t}\n\n\t/** The operation `id` answered with errors: a result's `errors`, or an error message. */\n\tfailed(id: string): void {\n\t\tconst open = this.#open.get(id);\n\t\tif (open !== undefined) open.outcome = 'errors';\n\t}\n\n\t/** The operation `id` ended: completed, stopped by its client, or failed. */\n\tend(id: string): void {\n\t\tconst open = this.#open.get(id);\n\t\tif (open === undefined) return;\n\t\tthis.#open.delete(id);\n\t\topen.end(open.outcome);\n\t}\n\n\t/**\n\t * The socket closed: an operation still open then is one whose run threw,\n\t * which `graphql-ws` answers by closing the socket, and ends with errors.\n\t */\n\tclosed(): void {\n\t\tfor (const id of [...this.#open.keys()]) {\n\t\t\tthis.failed(id);\n\t\t\tthis.end(id);\n\t\t}\n\t}\n}\n\n/** What `graphql-ws` keeps of each socket for its hooks: its operations. */\ninterface Followed {\n\treadonly operations: SocketOperations;\n}\n\n/**\n * `graphql-ws`'s hooks that follow each operation: a result with errors\n * marks it, an error message ends it, and so does its completion — sent,\n * stopped by the client, or cut by the socket's close.\n */\nexport function following<E extends Followed>(): Pick<\n\tServerOptions<Record<string, unknown> | undefined, E>,\n\t'onNext' | 'onError' | 'onComplete'\n> {\n\treturn {\n\t\tonNext({ extra }, id, _payload, _args, result) {\n\t\t\tif (result.errors !== undefined && result.errors.length > 0) {\n\t\t\t\textra.operations.failed(id);\n\t\t\t}\n\t\t},\n\t\tonError({ extra }, id) {\n\t\t\textra.operations.failed(id);\n\t\t\textra.operations.end(id);\n\t\t},\n\t\tonComplete({ extra }, id) {\n\t\t\textra.operations.end(id);\n\t\t},\n\t};\n}\n",
|
|
17
21
|
"/**\n * `graphql-ws`'s server options for a socket route: each operation parsed,\n * validated, executed and subscribed through the endpoint's Yoga, and\n * followed to its end for the observers around the upgrade.\n */\nimport type { BaseContext } from '@alxia/core';\nimport type { ServerOptions, SubscribePayload } from 'graphql-ws';\nimport type { YogaInitialContext, YogaServerInstance } from 'graphql-yoga';\nimport { serverContext, type YogaContext } from './handler';\nimport { following, type SocketOperations } from './ws-operations';\n\n/**\n * What `graphql-ws` keeps of each socket: the context its upgrade built,\n * the request each of its operations reads as Yoga's `request`, and its\n * operations, told to the upgrade's observers.\n */\nexport interface Extra {\n\treadonly ctx: Record<string, unknown> & BaseContext;\n\treadonly request: Request;\n\treadonly operations: SocketOperations;\n}\n\n/** The rest of each operation, run by the functions Yoga's envelop gave it. */\ninterface Enveloped {\n\treadonly execute: (args: never) => unknown;\n\treadonly subscribe: (args: never) => unknown;\n}\n\n/** Where the socket route is, and the endpoint whose Yoga it runs. */\nexport interface Paths {\n\treadonly endpoint: string;\n\treadonly socket: string;\n}\n\n/**\n * The Yoga of the endpoint a socket route serves: the HTTP one, so its\n * plugins are set up once. The socket's route is its full path, the\n * prefix of each app it is mounted into included, then its own `path`.\n */\nfunction endpointOf(route: string, paths: Paths): string {\n\t// A path of `/` adds nothing to a prefix: `/api` + `/` is `/api`.\n\tconst own = paths.socket === '/' ? '' : paths.socket;\n\tconst at = paths.endpoint === '/' ? '' : paths.endpoint;\n\treturn route.slice(0, route.length - own.length) + at || '/';\n}\n\n/**\n * `graphql-ws`'s options: each operation parsed, validated, executed and\n * subscribed through Yoga's envelop, with the context the upgrade built,\n * the operation's `params` and the client's `connectionParams`.\n */\nexport function serverOptions<UserCtx extends YogaContext>(\n\tyogaAt: (endpoint: string) => YogaServerInstance<YogaContext, UserCtx>,\n\tpaths: Paths,\n): ServerOptions<Record<string, unknown> | undefined, Extra> {\n\t// Each operation's envelop, found by its context: one object per\n\t// operation, which the root resolvers' `parent` is not.\n\tconst enveloped = new WeakMap<object, Enveloped>();\n\tconst of = (args: { contextValue?: unknown }) =>\n\t\tenveloped.get(args.contextValue as object) as Enveloped;\n\treturn {\n\t\texecute: (args) => of(args).execute(args as never) as never,\n\t\tsubscribe: (args) => of(args).subscribe(args as never) as never,\n\t\t...following<Extra>(),\n\t\tasync onSubscribe(context, id, params: SubscribePayload) {\n\t\t\tconst { ctx, request } = context.extra;\n\t\t\tconst initial = {\n\t\t\t\t...serverContext(ctx),\n\t\t\t\trequest,\n\t\t\t\tparams,\n\t\t\t\tconnectionParams: context.connectionParams,\n\t\t\t} as unknown as YogaInitialContext & YogaContext;\n\t\t\tconst { schema, execute, subscribe, contextFactory, parse, validate } =\n\t\t\t\tyogaAt(endpointOf(ctx.route as string, paths)).getEnveloped(initial);\n\t\t\tlet document: ReturnType<typeof parse>;\n\t\t\ttry {\n\t\t\t\tdocument = parse(params.query);\n\t\t\t} catch (error) {\n\t\t\t\treturn [error as never];\n\t\t\t}\n\t\t\tcontext.extra.operations.begin(id, document, params.operationName);\n\t\t\tconst errors = validate(schema, document);\n\t\t\tif (errors.length > 0) return errors;\n\t\t\tconst contextValue = await contextFactory();\n\t\t\tenveloped.set(contextValue, { execute, subscribe });\n\t\t\treturn {\n\t\t\t\tschema,\n\t\t\t\tdocument,\n\t\t\t\toperationName: params.operationName,\n\t\t\t\tvariableValues: params.variables,\n\t\t\t\tcontextValue,\n\t\t\t};\n\t\t},\n\t};\n}\n",
|
|
@@ -19,7 +23,7 @@
|
|
|
19
23
|
"import type { Alxia, BaseContext, Empty, RoutePath } from '@alxia/core';\nimport type {\n\tGraphQLSchemaWithContext,\n\tYogaInitialContext,\n\tYogaServerOptions,\n} from 'graphql-yoga';\nimport { declareEndpoint } from './endpoint';\nimport { graphqlHandler, type YogaContext } from './handler';\nimport type { ParseCacheOptions } from './parse-limits';\nimport type { SandboxOptions } from './sandbox';\nimport { type GraphQLWsOptions, graphqlSocket } from './ws';\nimport { yogaFor } from './yoga';\n\n/** The parts of a route's context Yoga owns, or that mean nothing to a resolver. */\ntype RouteOnly =\n\t| 'params'\n\t| 'query'\n\t| 'headers'\n\t| 'cookies'\n\t| 'body'\n\t| 'reply'\n\t| 'redirect';\n\n/**\n * What alxia hands Yoga for each request: the context its middlewares built —\n * `user`, `db`, `log`… — with `request`, `url`, `ip` and `set`, through\n * which a resolver sets a cookie or a header on the response.\n */\nexport type ServerContext<Ctx> = Omit<BaseContext & Ctx, RouteOnly>;\n\n/**\n * What an operation over WebSocket adds to its context (`ws` on): the\n * `connectionParams` the client sent when it connected. `undefined` over\n * HTTP, and for a client that sent none.\n */\nexport interface GraphQLWsContext {\n\treadonly connectionParams?: Readonly<Record<string, unknown>>;\n}\n\n/**\n * What a resolver reads as its context: Yoga's own, the app's, what\n * the `context` option adds, and over WebSocket the `connectionParams`. Type a schema with it:\n *\n * ```ts\n * const base = alxia().use(bearer({ jwt }));\n * const schema = createSchema<GraphQLContext<typeof base>>({ ... });\n * ```\n */\nexport type GraphQLContext<App, UserContext = Empty> = App extends {\n\treadonly '~context': infer Ctx;\n}\n\t? YogaInitialContext & ServerContext<Ctx> & GraphQLWsContext & UserContext\n\t: // Not `never`: a schema typed with `never` would let every resolver\n\t\t// read anything until `graphql()` refused it.\n\t\t{\n\t\t\treadonly '~error': 'GraphQLContext needs the type of an app: GraphQLContext<typeof app>';\n\t\t};\n\nexport interface GraphQLOptions<\n\tServerCtx extends YogaContext,\n\tUserCtx extends YogaContext,\n\tPath extends RoutePath,\n\tSchemaCtx = unknown,\n> extends Omit<\n\t\tYogaServerOptions<ServerCtx, UserCtx>,\n\t\t'graphqlEndpoint' | 'cors' | 'schema' | 'graphiql'\n\t> {\n\t/**\n\t * What a browser gets at the endpoint: Yoga's GraphiQL, Apollo Sandbox,\n\t * or nothing. By default, GraphiQL in the serving app's dev alone\n\t * (`isDev`: `alxia({ dev })`, else `NODE_ENV=development`), nothing\n\t * otherwise; `graphiql` or `apollo-sandbox` serves one everywhere.\n\t */\n\treadonly ide?: 'graphiql' | 'apollo-sandbox' | false;\n\t/** GraphiQL's options, Yoga's own, when `ide` is `graphiql`. */\n\treadonly graphiql?: Exclude<\n\t\tYogaServerOptions<ServerCtx, UserCtx>['graphiql'],\n\t\tboolean\n\t>;\n\t/** Apollo Sandbox's options, when `ide` is `apollo-sandbox`. */\n\treadonly sandbox?: SandboxOptions;\n\t/**\n\t * The schema, from Yoga's `createSchema`, Pothos, or any tool that types\n\t * its context. Its context must be one the app builds: a resolver that\n\t * reads `user` behind no middleware that adds one is a compile error.\n\t */\n\treadonly schema: GraphQLSchemaWithContext<SchemaCtx>;\n\t/** Where the endpoint is, under the app's prefix. `/graphql` by default. */\n\treadonly path?: Path;\n\t/**\n\t * Yoga's own CORS. Off by default: `@alxia/cors` answers for the whole\n\t * app, this endpoint included.\n\t */\n\treadonly cors?: YogaServerOptions<ServerCtx, UserCtx>['cors'];\n\t/**\n\t * GraphQL over WebSocket too, the `graphql-transport-ws` protocol of\n\t * Apollo Client's and urql's default link, served by the optional peer\n\t * `graphql-ws` at the endpoint's path: `true`, or where and how often it\n\t * pings. Off by default: subscriptions are served over server-sent\n\t * events, which stay served beside it.\n\t */\n\treadonly ws?: boolean | GraphQLWsOptions;\n\t/**\n\t * The most tokens a document may hold, 15 000 by default (Apollo\n\t * Router's own), or `false` for no cap. A longer document is refused by\n\t * the parser before anything runs, as Yoga refuses any document it\n\t * cannot parse: `GRAPHQL_PARSE_FAILED`.\n\t */\n\treadonly maxTokens?: number | false;\n\t/**\n\t * The most levels of `{`, `(` and `[` a document may nest, 1 000 by\n\t * default, or `false` for no limit. A deeper document is refused before\n\t * the parser recurses into it, as `GRAPHQL_PARSE_FAILED`: graphql-js\n\t * overflows the stack a few thousand levels down, well under\n\t * `maxTokens`. A document that overflows it anyway is refused the same\n\t * way.\n\t */\n\treadonly maxNesting?: number | false;\n\t/**\n\t * The cache of parsed documents, one per endpoint, weighed by its tokens and bytes:\n\t * `maxBytes` (64 MiB by default), `max` documents (1 024) and `ttl`\n\t * milliseconds (one hour). `false` parses every request. Yoga's own\n\t * `parserAndValidationCache` replaces it, and cannot be given with it.\n\t */\n\treadonly parseCache?: false | ParseCacheOptions;\n\t/**\n\t * The most bytes a `POST` body may hold, over which core answers a 413.\n\t * Without it, the `bodyLimit()` the app declared before `graphql()`\n\t * applies as it is; without that, 1 MiB. An upload through a\n\t * `multipart` mutation needs a larger one.\n\t */\n\treadonly bodyLimit?: number;\n}\n\n/**\n * The check Yoga's types leave out: the context the app builds must hold\n * what the schema's resolvers read. A mistake comes back as a `schema`\n * whose type is the message.\n */\ntype ProvidesContext<Provided, Required> = Provided extends Required\n\t? unknown\n\t: {\n\t\t\treadonly schema: `the schema's resolvers read a context the app does not build: missing ${Exclude<\n\t\t\t\tkeyof Required,\n\t\t\t\tkeyof Provided\n\t\t\t> &\n\t\t\t\tstring}`;\n\t\t};\n\n/**\n * A GraphQL endpoint on `app`, served by [GraphQL Yoga](https://the-guild.dev/graphql/yoga-server):\n * `GET` and `POST` at `path`, behind every middleware given to `use` on `app`\n * before it. A guard before it guards it; what the middlewares added is in each\n * resolver's context, typed. Yoga's options pass through — `plugins`\n * (Envelop's and Yoga's), `graphiql`, `maskedErrors`, `batching`… —\n * and subscriptions are served over server-sent events, and over\n * WebSocket too with `ws: true`.\n *\n * ```ts\n * const app = alxia()\n * .use(bearer({ jwt }))\n * .plugin((app) => graphql(app, { schema, plugins: [useDepthLimit()] }));\n * ```\n */\nexport function graphql<\n\tCtx extends object,\n\tPrefix extends string,\n\tSchemaCtx,\n\tUserCtx extends YogaContext = Empty,\n\tconst Path extends RoutePath = '/graphql',\n>(\n\tapp: Alxia<Ctx, Prefix>,\n\toptions: GraphQLOptions<ServerContext<Ctx>, UserCtx, Path, SchemaCtx> &\n\t\tProvidesContext<\n\t\t\tYogaInitialContext & ServerContext<Ctx> & UserCtx,\n\t\t\tSchemaCtx\n\t\t>,\n): Alxia<Ctx, Prefix> {\n\tconst {\n\t\tpath = '/graphql' as Path,\n\t\tcors = false,\n\t\tide,\n\t\tgraphiql,\n\t\tsandbox,\n\t\tws = false,\n\t\tbodyLimit,\n\t\t...yogaOptions\n\t} = options;\n\tconst yogaAt = yogaFor<UserCtx>(yogaOptions, { cors, ide, graphiql });\n\tconst handler = graphqlHandler(\n\t\tyogaAt,\n\t\tide === 'apollo-sandbox' ? (sandbox ?? {}) : false,\n\t);\n\n\tdeclareEndpoint(\n\t\tapp as never,\n\t\tpath,\n\t\thandler,\n\t\tbodyLimit,\n\t\tws === false\n\t\t\t? undefined\n\t\t\t: graphqlSocket(yogaAt, path, ws === true ? {} : ws),\n\t);\n\treturn app as never;\n}\n",
|
|
20
24
|
"const caches = new WeakMap<object, Map<string, unknown>>();\n\n/**\n * A value loaded at most once per request and key. `request` is any object\n * that lives as long as the request (the resolvers' context); the cache is\n * released with it. A `load` that throws, or returns a promise that rejects,\n * is not kept, so the next call tries again.\n */\nexport function oncePerRequest<T>(\n\trequest: object,\n\tkey: string,\n\tload: () => T,\n): T {\n\tlet cache = caches.get(request);\n\tif (!cache) {\n\t\tcache = new Map();\n\t\tcaches.set(request, cache);\n\t}\n\tif (cache.has(key)) return cache.get(key) as T;\n\tconst loaded = load();\n\tcache.set(key, loaded);\n\tif (loaded instanceof Promise) {\n\t\tconst mine = cache;\n\t\tloaded.catch(() => {\n\t\t\tif (mine.get(key) === loaded) mine.delete(key);\n\t\t});\n\t}\n\treturn loaded;\n}\n\n/**\n * Forgets what `oncePerRequest` kept for this request, so the next call for\n * any key loads again. A call to `oncePerRequest` already in flight keeps its\n * own value; only later calls see the empty cache.\n */\nexport function clearRequestCache(request: object): void {\n\tcaches.delete(request);\n}\n\n/**\n * A mutation's root fields run one after the other in one request, and one\n * may change what a later one reads. `freshPerMutation(resolvers)` returns\n * the resolvers with every function of `Mutation` wrapped to call\n * `clearRequestCache(context)` before it runs: each root mutation field starts\n * with an empty cache, its own sub-fields share it, and a query (no wrapped\n * field) keeps one cache for the whole request. Other types are untouched.\n */\nexport function freshPerMutation<R extends object>(resolvers: R): R {\n\tconst mutation = (resolvers as { Mutation?: unknown }).Mutation as\n\t\t| Record<string, unknown>\n\t\t| undefined;\n\tif (!mutation) return resolvers;\n\tconst wrapped: Record<string, unknown> = {};\n\tfor (const [name, field] of Object.entries(mutation)) {\n\t\tif (typeof field !== 'function') {\n\t\t\twrapped[name] = field;\n\t\t\tcontinue;\n\t\t}\n\t\twrapped[name] = function (\n\t\t\tthis: unknown,\n\t\t\tparent: unknown,\n\t\t\targs: unknown,\n\t\t\tcontext: unknown,\n\t\t\tinfo: unknown,\n\t\t) {\n\t\t\tif (typeof context === 'object' && context !== null) {\n\t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
|
}
|
package/dist/sandbox.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* [Apollo Sandbox](https://www.apollographql.com/docs/graphos/platform/sandbox),
|
|
3
3
|
* embedded: the page a browser gets at the endpoint when the IDE is
|
|
4
|
-
* `apollo-sandbox`. `@
|
|
4
|
+
* `apollo-sandbox`. `@softistx/shared-graphql`'s `renderSandbox`, kept twice: the
|
|
5
5
|
* Sandbox asks the address the page was opened at, as there since
|
|
6
6
|
* nxgt-core#171, but here the page resolves the path itself, so a TLS proxy
|
|
7
7
|
* in front changes nothing.
|
package/docs/README.md
CHANGED
|
@@ -13,7 +13,7 @@ a realistic example for each.
|
|
|
13
13
|
| [Yoga's plugins and options](guide/yoga.md) | adding Yoga or Envelop plugins, exposing or masking errors, batching, serving subscriptions, bounding them with `boundedStream`, or calling the endpoint from another origin |
|
|
14
14
|
| [GraphQL over WebSocket](guide/websockets.md) | serving Apollo Client's, urql's or `graphql-ws`'s WebSocket clients with `ws: true`, guarding the upgrade, reading `connectionParams`, the subprotocol, closing the sockets on shutdown, or testing a subscription over a socket |
|
|
15
15
|
| [Running operations in process](guide/executor.md) | calling the schema from an MCP tool, a job or a script with `graphqlExecutor`: the same plugins, limits and error masking as the route, a server context you pass, a signal, what it leaves out |
|
|
16
|
-
| [Harden it for production](guide/production.md) | putting a GraphQL API on the internet: rate limiting the endpoint, depth limits, the token cap, the nesting cap, the parse cache and the body limit, introspection off outside development, masked errors and the errors a client may read, a body limit, CSRF for a cookie session, persisted operations |
|
|
16
|
+
| [Harden it for production](guide/production.md) | putting a GraphQL API on the internet: rate limiting the endpoint, counting a field selected under aliases (`fieldRateLimit`), depth limits, the token cap, the nesting cap, the parse cache and the body limit, introspection off outside development, masked errors and the errors a client may read, a body limit, CSRF for a cookie session, persisted operations |
|
|
17
17
|
| [GraphiQL and Apollo Sandbox](guide/ide.md) | choosing the IDE a browser gets, configuring it, keeping it working under a strict `Content-Security-Policy`, or serving it outside dev with `ide: 'graphiql'` |
|
|
18
18
|
| [Testing the endpoint](guide/testing.md) | testing a GraphQL app without a server: `graphqlClient`, an auth header, a custom path, `GET`, persisted operations, the CSRF header, a typed document, the HTTP status of a 400 or a 413 |
|
|
19
19
|
| [Troubleshooting](troubleshooting.md) | something went wrong and you have the message |
|
package/docs/guide/production.md
CHANGED
|
@@ -47,7 +47,88 @@ export const limitTo = (max: number) =>
|
|
|
47
47
|
operations in a single `POST` when `batching` is on, and a document may ask
|
|
48
48
|
for a hundred fields, or the same expensive field a hundred times under
|
|
49
49
|
aliases. The limit counts the request: keep `batching` off, or give it a
|
|
50
|
-
small `limit`, and
|
|
50
|
+
small `limit`, and count the fields that matter with the next point.
|
|
51
|
+
|
|
52
|
+
## Count a field, not a request
|
|
53
|
+
|
|
54
|
+
A sign-in selected 300 times under aliases is one HTTP request and 300
|
|
55
|
+
credential guesses. `fieldRateLimit` counts every selection of the fields you
|
|
56
|
+
name (aliases, inline fragments and fragment spreads expanded; a fragment
|
|
57
|
+
spread twice counts twice) and consumes that cost on a limit keyed by the
|
|
58
|
+
client, before the operation runs.
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
// file: src/field-limits.ts
|
|
62
|
+
import { fieldRateLimit, limitFromStore } from '@alxia/graphql';
|
|
63
|
+
import { MemoryStore } from '@alxia/rate-limit';
|
|
64
|
+
|
|
65
|
+
const store = new MemoryStore();
|
|
66
|
+
|
|
67
|
+
// `signIn` selected N times costs N: 5 a minute for each client address.
|
|
68
|
+
export const fieldLimits = fieldRateLimit({
|
|
69
|
+
code: 'TOO_MANY_ATTEMPTS', // optional: RATE_LIMITED by default
|
|
70
|
+
fields: {
|
|
71
|
+
signIn: {
|
|
72
|
+
limit: limitFromStore(store, { limit: 5, windowMs: 60_000 }),
|
|
73
|
+
single: true, // and a document writing it twice is refused outright
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Give it to `graphql(app, { plugins: [fieldLimits] })`, **first** in the list.
|
|
80
|
+
The check runs in the plugin's `onExecute`, so a plugin after it that replaces
|
|
81
|
+
the execute function does not drop it, but a plugin before it that does would
|
|
82
|
+
change what it sees. Past the limit the operation does not run: a 429 whose
|
|
83
|
+
error has `code: 'RATE_LIMITED'` and `extensions.retryAfter` in seconds, with
|
|
84
|
+
the `Retry-After` header. A field with `single: true` written more than once
|
|
85
|
+
(a selection reached twice with the same response key and arguments counts
|
|
86
|
+
once) is a 400 `FIELD_SELECTED_ONCE`, and nothing is consumed.
|
|
87
|
+
|
|
88
|
+
| Option | Default | Effect |
|
|
89
|
+
| --- | --- | --- |
|
|
90
|
+
| `fields` | required | field name (at any depth) to its limit, or `{ limit, single? }` |
|
|
91
|
+
| `key` | `ctx.ip` | who is counted, from the context; `undefined` counts nothing (a call in process has no address) |
|
|
92
|
+
| `ipv6Prefix` | none | the default key becomes the IPv6 network of `ctx.ip`, its first `ipv6Prefix` bits (0 to 128), as in [`rateLimit`](https://github.com/softistx/alxia/blob/develop/packages/rate-limit/docs/guide.md#ipv6prefix); throws with a `key` |
|
|
93
|
+
| `code` | `RATE_LIMITED` | the `extensions.code` of the over-limit refusal |
|
|
94
|
+
|
|
95
|
+
A limit is any `{ consume(key, cost) }` answering `{ allowed, retryAfter }`
|
|
96
|
+
(milliseconds). The key it receives is `<field>:<client>`, so two fields never
|
|
97
|
+
share a count. Two ways to build one:
|
|
98
|
+
|
|
99
|
+
```ts no-check
|
|
100
|
+
// An @alxia/rate-limit store (the memory store, or redisStore for many processes):
|
|
101
|
+
// one consume per unit of cost, stopped at the first refusal. A store that
|
|
102
|
+
// declares its own policy needs none here, and one that differs is an error.
|
|
103
|
+
const fromStore = limitFromStore(store, { limit: 5, windowMs: 60_000 });
|
|
104
|
+
|
|
105
|
+
// A @softistx/redis bound limit, which takes the cost itself. `handle` is the
|
|
106
|
+
// wired Redis handle of your app (see @alxia/redis), `signIn` a limit defined on it.
|
|
107
|
+
const fromRedis = {
|
|
108
|
+
consume: (key: string, cost: number) =>
|
|
109
|
+
handle.limits.signIn.consume({ ip: key }, cost),
|
|
110
|
+
};
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
What to know when you pick a limit:
|
|
114
|
+
|
|
115
|
+
- **Partial charge.** Every unit the store accepted before a refusal stays
|
|
116
|
+
spent, and fields are charged in the order the document selects them:
|
|
117
|
+
earlier fields stay charged when a later one is refused.
|
|
118
|
+
- **Round trips.** `limitFromStore` calls the store once per unit, so one
|
|
119
|
+
selection count of N makes up to `limit + 1` calls (a refusal stops it).
|
|
120
|
+
With a large limit on a Redis store, use the cost-taking limit above.
|
|
121
|
+
- **What is counted.** Selections in the document as written: a list parent
|
|
122
|
+
costs 1 however long the list, `@skip` and `@include` are not evaluated,
|
|
123
|
+
selections that merge at execution still count each, and a field matches by
|
|
124
|
+
name on any type.
|
|
125
|
+
- **Batching.** Each operation of a batch is checked on its own. A refused
|
|
126
|
+
element is an error in an array answered 200, and there is no `Retry-After`
|
|
127
|
+
header: read `extensions.retryAfter`.
|
|
128
|
+
- **No address, no count.** `graphqlExecutor` has no `ip` in its server
|
|
129
|
+
context unless you give one, so a field is counted there only when `key` is
|
|
130
|
+
given.
|
|
131
|
+
- Subscriptions are not counted.
|
|
51
132
|
|
|
52
133
|
## Limit depth and complexity
|
|
53
134
|
|
package/docs/roadmap.md
CHANGED
|
@@ -27,6 +27,7 @@ Nothing scheduled yet.
|
|
|
27
27
|
|
|
28
28
|
### Unreleased
|
|
29
29
|
|
|
30
|
+
- **`fieldRateLimit`.** A Yoga 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)).
|
|
30
31
|
- **`graphqlExecutor(options)`.** A query or a mutation run in process through the same Yoga 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)).
|
|
31
32
|
- **A client's `x-request-id` is never believed on Yoga 6.** The endpoint turns Yoga's request id off (`requestId: false`), so the header is neither echoed nor logged; an app that turns it on keeps `trustHeader: false`. Yoga 6's per-request "Request processed" INFO line is off by default too: `logging` defaults to `'warn'` ([troubleshooting](troubleshooting.md#x-request-id-echoed-or-request-processed-logged-on-yoga-6)).
|
|
32
33
|
- **`graphql-yoga` 6 accepted as a peer.** The range is `^5.16.0 || ^6.0.0`; CI runs the specs on both majors. A custom `logging` on Yoga 6 must be a `@graphql-hive/logger` `Logger` ([troubleshooting](troubleshooting.md#logchild-is-not-a-function)).
|
package/docs/troubleshooting.md
CHANGED
|
@@ -338,6 +338,71 @@ subscription streams.
|
|
|
338
338
|
`ws: true`), and use the executor for queries and mutations
|
|
339
339
|
([guide](guide/executor.md)).
|
|
340
340
|
|
|
341
|
+
### `Too many attempts, try again later` (`RATE_LIMITED`, 429)
|
|
342
|
+
|
|
343
|
+
**When:** an operation selects a field given to `fieldRateLimit` more often
|
|
344
|
+
than its limit allows; nothing executed. `extensions.retryAfter` and the
|
|
345
|
+
`Retry-After` header are the wait in seconds. The code is `RATE_LIMITED`
|
|
346
|
+
unless the `code` option says otherwise (`TOO_MANY_ATTEMPTS`, say). Under
|
|
347
|
+
`batching` the refused element is an error in a 200 array with no
|
|
348
|
+
`Retry-After`: read `extensions.retryAfter`.
|
|
349
|
+
|
|
350
|
+
**Why:** every selection counts, aliases and fragments included, so one
|
|
351
|
+
request with 300 aliases costs 300, and the units spent before a refusal stay
|
|
352
|
+
spent.
|
|
353
|
+
|
|
354
|
+
**Fix:** wait, or raise the limit. A client that really needs several
|
|
355
|
+
selections sends them over several requests.
|
|
356
|
+
|
|
357
|
+
### `<field> may be selected once per operation` (`FIELD_SELECTED_ONCE`, 400)
|
|
358
|
+
|
|
359
|
+
**When:** a field declared `{ limit, single: true }` is written more than once
|
|
360
|
+
in the executed operation, with another response key or other arguments;
|
|
361
|
+
nothing is consumed. The same selection reached twice (through a fragment)
|
|
362
|
+
counts once.
|
|
363
|
+
|
|
364
|
+
**Fix:** select the field once per operation.
|
|
365
|
+
|
|
366
|
+
### `TypeError: fieldRateLimit({ fields }): fields maps each field name to count to its limit, and holds at least one`
|
|
367
|
+
|
|
368
|
+
**When:** `fieldRateLimit` is declared with no `fields`, or with none inside.
|
|
369
|
+
|
|
370
|
+
**Fix:** name the fields to count: `fieldRateLimit({ fields: { signIn: limit } })`.
|
|
371
|
+
|
|
372
|
+
### `TypeError: fieldRateLimit({ fields: { signIn } }): a limit has a consume(key, cost) method, or is { limit, single? }`
|
|
373
|
+
|
|
374
|
+
**When:** a field's value is neither a limit nor `{ limit, single? }`, a
|
|
375
|
+
`RateLimitStore` passed as it is, say.
|
|
376
|
+
|
|
377
|
+
**Fix:** adapt the store with `limitFromStore(store, { limit, windowMs })`, or
|
|
378
|
+
give an object with `consume(key, cost)`.
|
|
379
|
+
|
|
380
|
+
### `TypeError: fieldRateLimit: ipv6Prefix must be a whole number from 0 to 128`
|
|
381
|
+
|
|
382
|
+
**When:** `ipv6Prefix` is not a whole number from 0 to 128.
|
|
383
|
+
|
|
384
|
+
**Fix:** use `64` for a subscriber's network, or leave it out to count each address.
|
|
385
|
+
|
|
386
|
+
### `TypeError: fieldRateLimit: ipv6Prefix applies to the default key, and a key of your own was given`
|
|
387
|
+
|
|
388
|
+
**When:** `fieldRateLimit` is given both `ipv6Prefix` and `key`.
|
|
389
|
+
|
|
390
|
+
**Fix:** drop one, or group the address in your own key with `ipv6Network` from `@alxia/rate-limit`.
|
|
391
|
+
|
|
392
|
+
### `TypeError: fieldRateLimit: code is a non-empty string`
|
|
393
|
+
|
|
394
|
+
**When:** `code` is an empty string or not a string.
|
|
395
|
+
|
|
396
|
+
**Fix:** give the `extensions.code` you want, or leave it out for `RATE_LIMITED`.
|
|
397
|
+
|
|
398
|
+
### `TypeError: limitFromStore: limit must be a whole number of 1 or more` and `… differs from the store's policy …`
|
|
399
|
+
|
|
400
|
+
**When:** `limitFromStore` is given a `limit` or `windowMs` that is not a whole
|
|
401
|
+
number of 1 or more, none with a store that has no policy, or numbers that
|
|
402
|
+
differ from the store's own `policy`.
|
|
403
|
+
|
|
404
|
+
**Fix:** give whole numbers, or leave the policy out for a store that has one.
|
|
405
|
+
|
|
341
406
|
### `Syntax Error: Document contains more than 15000 tokens. Parsing aborted.`
|
|
342
407
|
|
|
343
408
|
**When:** a query is answered with `GRAPHQL_PARSE_FAILED` (400 under
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alxia/graphql",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"description": "GraphQL for alxia with GraphQL Yoga: its plugins, subscriptions over SSE or WebSocket (graphql-ws) and GraphiQL, behind the app's hooks, its resolvers reading the app's typed context",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -47,14 +47,15 @@
|
|
|
47
47
|
]
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@alxia/core": "^0.
|
|
51
|
-
"@alxia/logger": "^0.6.
|
|
52
|
-
"@alxia/
|
|
50
|
+
"@alxia/core": "^0.20.0",
|
|
51
|
+
"@alxia/logger": "^0.6.12",
|
|
52
|
+
"@alxia/rate-limit": "^0.6.0",
|
|
53
|
+
"@alxia/telemetry": "^0.8.1",
|
|
53
54
|
"@envelop/depth-limit": "^7.2.1",
|
|
54
55
|
"@graphql-hive/logger": "^1.1.1",
|
|
55
56
|
"@graphql-yoga/plugin-csrf-prevention": "^4.0.1",
|
|
56
57
|
"@graphql-yoga/plugin-persisted-operations": "^4.0.1",
|
|
57
|
-
"@
|
|
58
|
+
"@softistx/telemetry": "^0.3.0",
|
|
58
59
|
"@types/bun": "^1.4.4",
|
|
59
60
|
"dataloader": "^2.2.3",
|
|
60
61
|
"graphql": "^16.11.0",
|
|
@@ -62,7 +63,7 @@
|
|
|
62
63
|
"graphql-yoga": "^6.0.1"
|
|
63
64
|
},
|
|
64
65
|
"peerDependencies": {
|
|
65
|
-
"@alxia/core": "^0.
|
|
66
|
+
"@alxia/core": "^0.20.0",
|
|
66
67
|
"graphql": "^16.11.0 || ^17.0.0",
|
|
67
68
|
"graphql-ws": "^6.1.0",
|
|
68
69
|
"graphql-yoga": "^5.16.0 || ^6.0.0",
|