@reventlessdev/reventless-graphql-server 1.0.0-alpha.172 → 1.0.0-alpha.174

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,21 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # 1.0.0-alpha.174 (2026-11-01)
7
+
8
+ ### Features
9
+
10
+ * **local:** the local platform serves its logs and events to whoever watches it ([0c29b0d](https://github.com/ReventlessDev/reventless-core/commit/0c29b0d08c668ad5b948a8017178dad8692647d0))
11
+
12
+
13
+ # 1.0.0-alpha.173 (2026-10-30)
14
+
15
+ **Note:** Version bump only for package @reventlessdev/reventless-graphql-server
16
+
17
+
18
+
19
+
20
+
6
21
  # 1.0.0-alpha.172 (2026-10-30)
7
22
 
8
23
  **Note:** Version bump only for package @reventlessdev/reventless-graphql-server
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@reventlessdev/reventless-graphql-server",
3
- "version": "1.0.0-alpha.172",
3
+ "version": "1.0.0-alpha.174",
4
4
  "description": "Transport-neutral GraphQL server runtime for Reventless: schema-from-fragments, resolver registration, an HTTP + graphql-ws listener, and a subscription fan-out bridge with a pluggable PubSub backend",
5
5
  "license": "Apache-2.0",
6
6
  "dependencies": {
7
- "@reventlessdev/rescript-graphql-yoga": "1.0.0-alpha.29",
8
- "@reventlessdev/reventless-core": "3.0.0-alpha.324"
7
+ "@reventlessdev/reventless-core": "3.0.0-alpha.326",
8
+ "@reventlessdev/rescript-graphql-yoga": "1.0.0-alpha.30"
9
9
  },
10
10
  "devDependencies": {
11
11
  "rescript": "12.3.1"
@@ -77,6 +77,30 @@ let extractFieldName = (sdlField: string): string => {
77
77
  ->String.trim
78
78
  }
79
79
 
80
+ type fetchHeaders
81
+ @new external makeHeaders: dict<string> => fetchHeaders = "Headers"
82
+
83
+ /** The initial context a yoga context factory expects, built for a WebSocket
84
+ operation: the upgrade request's headers, with what the client sent as
85
+ `connectionParams` on top (a browser cannot set headers on a WebSocket, so
86
+ that is where its `Authorization` goes). */
87
+ let wsInitialContext = (ctx: YG.wsContext): YG.initialContext => {
88
+ let headers = Dict.make()
89
+ ctx.extra.request.headers
90
+ ->Dict.toArray
91
+ ->Array.forEach(((k, v)) => headers->Dict.set(k->String.toLowerCase, v))
92
+ ctx.connectionParams
93
+ ->Option.getOr(Dict.make())
94
+ ->Dict.toArray
95
+ ->Array.forEach(((k, v)) =>
96
+ switch v {
97
+ | JSON.String(s) => headers->Dict.set(k->String.toLowerCase, s)
98
+ | _ => ()
99
+ }
100
+ )
101
+ Obj.magic({"request": {"headers": makeHeaders(headers)}, "req": ctx.extra.request})
102
+ }
103
+
80
104
  let make = (~label: string="GraphQL"): t => {
81
105
  let mutationResolvers: ref<dict<resolverFn>> = ref(Dict.make())
82
106
  let queryResolvers: ref<dict<resolverFn>> = ref(Dict.make())
@@ -232,7 +256,16 @@ ${mutations}
232
256
  )
233
257
  if subscriptionResolvers.contents->Dict.keysToArray->Array.length > 0 {
234
258
  let wss = YG.newWebSocketServer({"server": server, "path": "/graphql"})
235
- YG.wsUseServer({"schema": schema}, wss)
259
+ // A subscription is checked like a query: its context is built by the same
260
+ // factory, from the connection's headers and parameters.
261
+ switch contextFactory {
262
+ | Some(factory) =>
263
+ YG.wsUseServerWithContext(
264
+ {"schema": schema, "context": ctx => factory(wsInitialContext(ctx))},
265
+ wss,
266
+ )
267
+ | None => YG.wsUseServer({"schema": schema}, wss)
268
+ }
236
269
  log.info(
237
270
  ~comp=label,
238
271
  `graphql-ws subscriptions on ws://localhost:${port->Int.toString}/graphql`,
@@ -19,6 +19,26 @@ function extractFieldName(sdlField) {
19
19
  return Stdlib_Option.getOr(Stdlib_Option.getOr(trimmed.split("(")[0], "").trim().split(":")[0], "").trim();
20
20
  }
21
21
 
22
+ function wsInitialContext(ctx) {
23
+ let headers = {};
24
+ Object.entries(ctx.extra.request.headers).forEach(param => {
25
+ headers[param[0].toLowerCase()] = param[1];
26
+ });
27
+ Object.entries(Stdlib_Option.getOr(ctx.connectionParams, {})).forEach(param => {
28
+ let v = param[1];
29
+ if (typeof v !== "string") {
30
+ return;
31
+ }
32
+ headers[param[0].toLowerCase()] = v;
33
+ });
34
+ return {
35
+ request: {
36
+ headers: new Headers(headers)
37
+ },
38
+ req: ctx.extra.request
39
+ };
40
+ }
41
+
22
42
  function make(labelOpt) {
23
43
  let label = labelOpt !== undefined ? labelOpt : "GraphQL";
24
44
  let mutationResolvers = {
@@ -176,9 +196,16 @@ type Mutation {
176
196
  server: server,
177
197
  path: "/graphql"
178
198
  });
179
- Ws$1.useServer({
180
- schema: schema
181
- }, wss);
199
+ if (contextFactory !== undefined) {
200
+ Ws$1.useServer({
201
+ schema: schema,
202
+ context: ctx => contextFactory(wsInitialContext(ctx))
203
+ }, wss);
204
+ } else {
205
+ Ws$1.useServer({
206
+ schema: schema
207
+ }, wss);
208
+ }
182
209
  log.info(label, undefined, `graphql-ws subscriptions on ws://localhost:` + port.toString() + `/graphql`);
183
210
  }
184
211
  activeServer.contents = Primitive_option.some(server);
@@ -300,6 +327,7 @@ export {
300
327
  log,
301
328
  debug,
302
329
  extractFieldName,
330
+ wsInitialContext,
303
331
  make,
304
332
  }
305
333
  /* log Not a pure module */