@znight/graphql 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +19 -6
  2. package/package.json +14 -9
package/README.md CHANGED
@@ -425,8 +425,11 @@ curl -N -H 'accept: text/event-stream' -H 'content-type: application/json' \
425
425
  # data: {"data":{"bookAdded":{"title":"The Hobbit"}}}
426
426
  ```
427
427
 
428
- `PubSub<Events>` is an injectable abstract class (singleton, provided by `GraphQLPlugin`), where
429
- `Events` maps topics to payload types:
428
+ The events of a subscription are born elsewhere (a mutation, a scheduled job, a message consumer),
429
+ while the stream stays open. `PubSub<Events>` is the mailbox between them: producers
430
+ `publish(topic, payload)`, every open subscription `subscribe(topic, { signal })`s and receives what
431
+ is published on the topic from then on (nothing is stored or replayed). It is an injectable abstract
432
+ class (singleton, provided by `GraphQLPlugin`), where `Events` maps topics to payload types:
430
433
 
431
434
  ```ts
432
435
  /** Topics of the application PubSub and their payloads. */
@@ -443,8 +446,14 @@ for await (const book of this.events.subscribe('bookAdded', { signal: ctx.signal
443
446
  subscriber (`subscriptions.bufferSize`, 100 events). A subscriber that falls behind gets a final
444
447
  `SUBSCRIPTION_OVERFLOW` error and its stream ends, rather than losing events silently or buffering
445
448
  without bound. The plugin closes the `MemoryPubSub` it created when the application is disposed.
446
- - Several instances need a shared implementation (Redis, a broker): pass any object with
447
- `publish(topic, payload)` and `subscribe(topic, { signal })` as the `pubsub` option.
449
+ - `MemoryPubSub` reaches the subscribers of its own process only. Several instances need a shared
450
+ implementation (Redis pub/sub, NATS, Postgres `LISTEN`/`NOTIFY`, a broker): extend `PubSub` and
451
+ pass an instance as the `pubsub` option. `subscribe()` returns its iterator synchronously, ends
452
+ when `signal` aborts or `return()` is called, buffers a bounded number of events per subscriber
453
+ (`SUBSCRIPTION_OVERFLOW` beyond), and payloads must survive serialization. The plugin does not
454
+ close a `PubSub` it did not create. The guide's
455
+ [Write your own PubSub](../../docs/guide/graphql.md#custom-pubsub) recipe is a tested Redis
456
+ implementation (ioredis).
448
457
  - `subscribe()` ends when its `signal` aborts: the client left, the application shuts down, the
449
458
  stream reached `subscriptions.maxDuration`, or (`plugin.subscribe()`) its `return()` was called.
450
459
  Always pass `ctx.signal`.
@@ -797,7 +806,11 @@ ZNIGHT066.
797
806
  | `initRoots()` / `httpRoutes()` | The `PluginInitRoots` contract (`TestApp`) and the `PluginHttpRoutes` contract of `@znight/http` |
798
807
 
799
808
  `request` is `{ query, operationName?, variables?, extensions? }`; `options` is `{ signal?,
800
- requestId? }`. A direct execution has no HTTP guards.
809
+ requestId? }`. A direct execution has no HTTP guards of its own: inside a controller, it runs in the
810
+ route's request scope, after the route's guards. With `http: false`, a controller can hand its
811
+ requests to another GraphQL server that delegates the execution to `execute()` and `subscribe()`:
812
+ the guide's [Serve the schema with GraphQL Yoga](../../docs/guide/graphql.md#yoga) recipe keeps
813
+ guards, loaders, the request scope and error formatting.
801
814
 
802
815
  ```ts
803
816
  const plugin = app.getPlugin<GraphQLPlugin>('graphql')
@@ -1332,7 +1345,7 @@ are emitted by schema-first only: code-first sections, hashes and artifacts are
1332
1345
  cache, no federation or schema stitching, no file uploads (use an HTTP upload route), no operation
1333
1346
  batching.
1334
1347
  - `MemoryPubSub` serves one process; a multi-instance `PubSub` is the application's (`pubsub`
1335
- option).
1348
+ option, Redis recipe in the guide).
1336
1349
  - Types must be written: the compiler reads annotations, it never infers return or property types.
1337
1350
  - The SDL artifact and `schemaHash` see the `description` and `specifiedByURL` of a
1338
1351
  `ScalarDefinition` written as literals only; a graphql-js `GraphQLScalarType` (`graphql-scalars`)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@znight/graphql",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Znight GraphQL: code-first GraphQL whose schema is derived from TypeScript types at build time, on graphql-js 17",
5
5
  "license": "MIT",
6
6
  "author": "Ugho STEPHAN",
@@ -40,19 +40,20 @@
40
40
  "scripts": {
41
41
  "build": "tsdown",
42
42
  "typecheck": "tsc --noEmit && tsc --noEmit -p test",
43
- "test": "bun test --conditions=@znight/source test"
43
+ "test": "bun test --conditions=@znight/source test",
44
+ "test:integration": "ZNIGHT_INTEGRATION=1 bun test --conditions=@znight/source --timeout 180000 test/recipes/redis-pubsub.integration.test.ts"
44
45
  },
45
46
  "publishConfig": {
46
47
  "access": "public"
47
48
  },
48
49
  "dependencies": {
49
- "@znight/core": "0.2.1",
50
+ "@znight/core": "0.2.2",
50
51
  "dataloader": "^2.2.3"
51
52
  },
52
53
  "peerDependencies": {
53
- "@znight/http": "^0.2.1",
54
- "@znight/compiler": "^0.2.1",
55
- "@znight/testing": "^0.2.1",
54
+ "@znight/http": "^0.2.2",
55
+ "@znight/compiler": "^0.2.2",
56
+ "@znight/testing": "^0.2.2",
56
57
  "graphql": "^17.0.2"
57
58
  },
58
59
  "peerDependenciesMeta": {
@@ -64,12 +65,16 @@
64
65
  }
65
66
  },
66
67
  "devDependencies": {
67
- "@znight/http": "0.2.1",
68
- "@znight/compiler": "0.2.1",
69
- "@znight/testing": "0.2.1",
68
+ "@testcontainers/redis": "12.2.1",
69
+ "@znight/compiler": "0.2.2",
70
+ "@znight/http": "0.2.2",
71
+ "@znight/testing": "0.2.2",
70
72
  "graphql": "17.0.2",
71
73
  "graphql-http": "1.23.1",
72
74
  "graphql-sse": "2.6.3",
75
+ "graphql-yoga": "6.0.1",
76
+ "ioredis": "6.0.0",
77
+ "testcontainers": "12.2.1",
73
78
  "valibot": "1.5.0",
74
79
  "zod": "4.6.7"
75
80
  },