@graphql-hive/gateway 1.15.5-rc-020510da536b00af88be78943e8e6e1c8647df25 → 1.16.0-alpha-c8ff573391fdb1e3cf75e49cd6416879353050a1

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/CHANGELOG.md +72 -6
  2. package/package.json +6 -6
package/CHANGELOG.md CHANGED
@@ -1,16 +1,82 @@
1
1
  # @graphql-hive/gateway
2
2
 
3
- ## 1.15.5-rc-020510da536b00af88be78943e8e6e1c8647df25
3
+ ## 1.16.0-alpha-c8ff573391fdb1e3cf75e49cd6416879353050a1
4
+
5
+ ### Minor Changes
6
+
7
+ - [#1310](https://github.com/graphql-hive/gateway/pull/1310) [`c8ff573`](https://github.com/graphql-hive/gateway/commit/c8ff573391fdb1e3cf75e49cd6416879353050a1) Thanks [@EmrysMyrddin](https://github.com/EmrysMyrddin)! - Added new `withState` plugin utility for easy data sharing between hooks.
8
+
9
+ ## New plugin utility to ease data sharing between hooks
10
+
11
+ Sometimes, plugins can grow in complexity and need to share data between its hooks.
12
+
13
+ A way to solve this can be to mutate the graphql context, but this context is not always available
14
+ in all hooks in Yoga or Hive Gateway plugins. Moreover, mutating the context gives access to your
15
+ internal data to all other plugins and graphql resolvers, without mentioning performance impact on
16
+ field access on this object.
17
+
18
+ The recommended approach to this problem was to use a `WeakMap` with a stable key (often the
19
+ `context` or `request` object). While it works, it's not very convenient for plugin developers, and
20
+ is prone to error with the choice of key.
21
+
22
+ The new `withState` utility solves this DX issue by providing an easy and straightforward API for
23
+ data sharing between hooks.
24
+
25
+ ```ts
26
+ import { withState } from '@graphql-hive/gateway';
27
+
28
+ type State = { foo: string };
29
+
30
+ const myPlugin = () =>
31
+ withState<Plugin, State>(() => ({
32
+ onParse({ state }) {
33
+ state.forOperation.foo = 'foo';
34
+ },
35
+ onValidate({ state }) {
36
+ const { foo } = state.forOperation;
37
+ console.log('foo', foo);
38
+ },
39
+ }));
40
+ ```
41
+
42
+ The `state` payload field will be available in all relevant hooks, making it easy to access shared
43
+ data. It also forces the developer to choose the scope for the data:
44
+
45
+ - `forOperation` for a data scoped to GraphQL operation (Envelop, Yoga and Hive Gateway)
46
+ - `forRequest` for a data scoped to HTTP request (Yoga and Hive Gateway)
47
+ - `forSubgraphExecution` for a data scoped to the subgraph execution (Hive Gateway)
48
+
49
+ Not all scopes are available in all hooks, the type reflects which scopes are available
50
+
51
+ Under the hood, those states are kept in memory using `WeakMap`, which avoid any memory leaks.
52
+
53
+ It is also possible to manually retrieve the state with the `getState` function:
54
+
55
+ ```ts
56
+ const myPlugin = () =>
57
+ withState((getState) => ({
58
+ onParse({ context }) {
59
+ // You can provide a payload, which will dictate which scope you have access to.
60
+ // The scope can contain `context`, `request` and `executionRequest` fields.
61
+ const state = getState({ context });
62
+ // Use the state elsewhere.
63
+ },
64
+ }));
65
+ ```
4
66
 
5
67
  ### Patch Changes
6
68
 
7
- - Updated dependencies [[`9b230f3`](https://github.com/graphql-hive/gateway/commit/9b230f35b47afbf3b253e4c21720e836c5a2a8d1)]:
8
- - @graphql-hive/gateway-runtime@1.10.0-rc-020510da536b00af88be78943e8e6e1c8647df25
9
- - @graphql-hive/plugin-aws-sigv4@1.0.15
69
+ - [#1310](https://github.com/graphql-hive/gateway/pull/1310) [`82d3f6d`](https://github.com/graphql-hive/gateway/commit/82d3f6df10744eecf65f91ad73717c3c7a131aef) Thanks [@EmrysMyrddin](https://github.com/EmrysMyrddin)! - dependencies updates:
70
+
71
+ - Updated dependency [`graphql-yoga@^5.14.0` ↗︎](https://www.npmjs.com/package/graphql-yoga/v/5.14.0) (from `^5.13.5`, in `dependencies`)
72
+
73
+ - Updated dependencies [[`82d3f6d`](https://github.com/graphql-hive/gateway/commit/82d3f6df10744eecf65f91ad73717c3c7a131aef), [`c8ff573`](https://github.com/graphql-hive/gateway/commit/c8ff573391fdb1e3cf75e49cd6416879353050a1)]:
74
+ - @graphql-hive/gateway-runtime@1.10.0-alpha-c8ff573391fdb1e3cf75e49cd6416879353050a1
75
+ - @graphql-hive/plugin-aws-sigv4@1.0.16-alpha-c8ff573391fdb1e3cf75e49cd6416879353050a1
10
76
  - @graphql-hive/plugin-deduplicate-request@1.0.1
11
77
  - @graphql-mesh/hmac-upstream-signature@1.2.28
12
- - @graphql-mesh/plugin-opentelemetry@1.3.63-rc-020510da536b00af88be78943e8e6e1c8647df25
13
- - @graphql-mesh/plugin-prometheus@1.3.51-rc-020510da536b00af88be78943e8e6e1c8647df25
78
+ - @graphql-mesh/plugin-opentelemetry@1.3.63-alpha-c8ff573391fdb1e3cf75e49cd6416879353050a1
79
+ - @graphql-mesh/plugin-prometheus@1.3.51-alpha-c8ff573391fdb1e3cf75e49cd6416879353050a1
14
80
 
15
81
  ## 1.15.4
16
82
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-hive/gateway",
3
- "version": "1.15.5-rc-020510da536b00af88be78943e8e6e1c8647df25",
3
+ "version": "1.16.0-alpha-c8ff573391fdb1e3cf75e49cd6416879353050a1",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -53,9 +53,9 @@
53
53
  "@escape.tech/graphql-armor-block-field-suggestions": "^3.0.0",
54
54
  "@escape.tech/graphql-armor-max-depth": "^2.4.0",
55
55
  "@escape.tech/graphql-armor-max-tokens": "^2.5.0",
56
- "@graphql-hive/gateway-runtime": "1.10.0-rc-020510da536b00af88be78943e8e6e1c8647df25",
56
+ "@graphql-hive/gateway-runtime": "1.10.0-alpha-c8ff573391fdb1e3cf75e49cd6416879353050a1",
57
57
  "@graphql-hive/importer": "^1.1.0",
58
- "@graphql-hive/plugin-aws-sigv4": "^1.0.15",
58
+ "@graphql-hive/plugin-aws-sigv4": "1.0.16-alpha-c8ff573391fdb1e3cf75e49cd6416879353050a1",
59
59
  "@graphql-hive/plugin-deduplicate-request": "^1.0.1",
60
60
  "@graphql-hive/pubsub": "^1.0.0",
61
61
  "@graphql-mesh/cache-cfw-kv": "^0.105.5",
@@ -68,8 +68,8 @@
68
68
  "@graphql-mesh/plugin-jit": "^0.2.5",
69
69
  "@graphql-mesh/plugin-jwt-auth": "^1.5.6",
70
70
  "@graphql-mesh/plugin-mock": "^0.105.6",
71
- "@graphql-mesh/plugin-opentelemetry": "1.3.63-rc-020510da536b00af88be78943e8e6e1c8647df25",
72
- "@graphql-mesh/plugin-prometheus": "1.3.51-rc-020510da536b00af88be78943e8e6e1c8647df25",
71
+ "@graphql-mesh/plugin-opentelemetry": "1.3.63-alpha-c8ff573391fdb1e3cf75e49cd6416879353050a1",
72
+ "@graphql-mesh/plugin-prometheus": "1.3.51-alpha-c8ff573391fdb1e3cf75e49cd6416879353050a1",
73
73
  "@graphql-mesh/plugin-rate-limit": "^0.104.5",
74
74
  "@graphql-mesh/plugin-snapshot": "^0.104.5",
75
75
  "@graphql-mesh/transport-http": "^0.6.43",
@@ -85,7 +85,7 @@
85
85
  "commander": "^13.1.0",
86
86
  "dotenv": "^16.4.7",
87
87
  "graphql-ws": "^6.0.4",
88
- "graphql-yoga": "^5.13.5",
88
+ "graphql-yoga": "^5.14.0",
89
89
  "tslib": "^2.8.1",
90
90
  "ws": "^8.18.0"
91
91
  },