Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 0 additions & 63 deletions .changeset/sharp-goats-trade.md

This file was deleted.

67 changes: 67 additions & 0 deletions packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,72 @@
# @envelop/core

## 5.3.0

### Minor Changes

- [#2607](https://github.com/graphql-hive/envelop/pull/2607)
[`3ebaa3b`](https://github.com/graphql-hive/envelop/commit/3ebaa3b75b34f9a61aa517166f538796b383bfad)
Thanks [@EmrysMyrddin](https://github.com/EmrysMyrddin)! - Added new `withState` plugin utility
for easy data sharing between hooks.

## New plugin utility to ease data sharing between hooks

Sometimes, plugins can grow in complexity and need to share data between its hooks.

A way to solve this can be to mutate the graphql context, but this context is not always available
in all hooks in Yoga or Hive Gateway plugins. Moreover, mutating the context gives access to your
internal data to all other plugins and graphql resolvers, without mentioning performance impact on
field access on this object.

The recommended approach to this problem was to use a `WeakMap` with a stable key (often the
`context` or `request` object). While it works, it's not very convenient for plugin developers,
and is prone to error with the choice of key.

The new `withState` utility solves this DX issue by providing an easy and straightforward API for
data sharing between hooks.

```ts
import { withState } from '@envelop/core'

type State = { foo: string }

const myPlugin = () =>
withState<Plugin, State>(() => ({
onParse({ state }) {
state.forOperation.foo = 'foo'
},
onValidate({ state }) {
const { foo } = state.forOperation
console.log('foo', foo)
}
}))
```

The `state` payload field will be available in all relevant hooks, making it easy to access shared
data. It also forces the developer to choose the scope for the data:

- `forOperation` for a data scoped to GraphQL operation (Envelop, Yoga and Hive Gateway)
- `forRequest` for a data scoped to HTTP request (Yoga and Hive Gateway)
- `forSubgraphExecution` for a data scoped to the subgraph execution (Hive Gateway)

Not all scopes are available in all hooks, the type reflects which scopes are available

Under the hood, those states are kept in memory using `WeakMap`, which avoid any memory leaks.

It is also possible to manually retrieve the state with the `getState` function:

```ts
const myPlugin = () =>
withState(getState => ({
onParse({ context }) {
// You can provide a payload, which will dictate which scope you have access to.
// The scope can contain `context`, `request` and `executionRequest` fields.
const state = getState({ context })
// Use the state elsewhere.
}
}))
```

## 5.2.3

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@envelop/core",
"version": "5.2.3",
"version": "5.3.0",
"type": "module",
"repository": {
"type": "git",
Expand Down
8 changes: 8 additions & 0 deletions packages/plugins/apollo-datasources/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @envelop/apollo-datasources

## 6.0.0

### Patch Changes

- Updated dependencies
[[`3ebaa3b`](https://github.com/graphql-hive/envelop/commit/3ebaa3b75b34f9a61aa517166f538796b383bfad)]:
- @envelop/core@5.3.0

## 5.1.3

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/apollo-datasources/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@envelop/apollo-datasources",
"version": "5.1.3",
"version": "6.0.0",
"type": "module",
"repository": {
"type": "git",
Expand Down
8 changes: 8 additions & 0 deletions packages/plugins/apollo-federation/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @envelop/apollo-federation

## 7.0.0

### Patch Changes

- Updated dependencies
[[`3ebaa3b`](https://github.com/graphql-hive/envelop/commit/3ebaa3b75b34f9a61aa517166f538796b383bfad)]:
- @envelop/core@5.3.0

## 6.1.3

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/apollo-federation/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@envelop/apollo-federation",
"version": "6.1.3",
"version": "7.0.0",
"type": "module",
"repository": {
"type": "git",
Expand Down
8 changes: 8 additions & 0 deletions packages/plugins/apollo-server-errors/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @envelop/apollo-server-errors

## 8.0.0

### Patch Changes

- Updated dependencies
[[`3ebaa3b`](https://github.com/graphql-hive/envelop/commit/3ebaa3b75b34f9a61aa517166f538796b383bfad)]:
- @envelop/core@5.3.0

## 7.1.3

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/apollo-server-errors/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@envelop/apollo-server-errors",
"version": "7.1.3",
"version": "8.0.0",
"type": "module",
"repository": {
"type": "git",
Expand Down
9 changes: 9 additions & 0 deletions packages/plugins/apollo-tracing/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# @envelop/apollo-tracing

## 8.0.0

### Patch Changes

- Updated dependencies
[[`3ebaa3b`](https://github.com/graphql-hive/envelop/commit/3ebaa3b75b34f9a61aa517166f538796b383bfad)]:
- @envelop/core@5.3.0
- @envelop/on-resolve@6.0.0

## 7.1.3

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/apollo-tracing/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@envelop/apollo-tracing",
"version": "7.1.3",
"version": "8.0.0",
"type": "module",
"repository": {
"type": "git",
Expand Down
8 changes: 8 additions & 0 deletions packages/plugins/auth0/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @envelop/auth0

## 8.0.0

### Patch Changes

- Updated dependencies
[[`3ebaa3b`](https://github.com/graphql-hive/envelop/commit/3ebaa3b75b34f9a61aa517166f538796b383bfad)]:
- @envelop/core@5.3.0

## 7.1.3

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/auth0/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@envelop/auth0",
"version": "7.1.3",
"version": "8.0.0",
"type": "module",
"repository": {
"type": "git",
Expand Down
8 changes: 8 additions & 0 deletions packages/plugins/dataloader/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @envelop/dataloader

## 8.0.0

### Patch Changes

- Updated dependencies
[[`3ebaa3b`](https://github.com/graphql-hive/envelop/commit/3ebaa3b75b34f9a61aa517166f538796b383bfad)]:
- @envelop/core@5.3.0

## 7.1.3

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/dataloader/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@envelop/dataloader",
"version": "7.1.3",
"version": "8.0.0",
"type": "module",
"repository": {
"type": "git",
Expand Down
8 changes: 8 additions & 0 deletions packages/plugins/depth-limit/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @envelop/depth-limit

## 6.0.0

### Patch Changes

- Updated dependencies
[[`3ebaa3b`](https://github.com/graphql-hive/envelop/commit/3ebaa3b75b34f9a61aa517166f538796b383bfad)]:
- @envelop/core@5.3.0

## 5.1.3

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/depth-limit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@envelop/depth-limit",
"version": "5.1.3",
"version": "6.0.0",
"type": "module",
"repository": {
"type": "git",
Expand Down
8 changes: 8 additions & 0 deletions packages/plugins/disable-introspection/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @envelop/disable-introspection

## 8.0.0

### Patch Changes

- Updated dependencies
[[`3ebaa3b`](https://github.com/graphql-hive/envelop/commit/3ebaa3b75b34f9a61aa517166f538796b383bfad)]:
- @envelop/core@5.3.0

## 7.1.3

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/disable-introspection/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@envelop/disable-introspection",
"version": "7.1.3",
"version": "8.0.0",
"type": "module",
"repository": {
"type": "git",
Expand Down
8 changes: 8 additions & 0 deletions packages/plugins/execute-subscription-event/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @envelop/execute-subscription-event

## 7.0.0

### Patch Changes

- Updated dependencies
[[`3ebaa3b`](https://github.com/graphql-hive/envelop/commit/3ebaa3b75b34f9a61aa517166f538796b383bfad)]:
- @envelop/core@5.3.0

## 6.1.3

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/execute-subscription-event/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@envelop/execute-subscription-event",
"version": "6.1.3",
"version": "7.0.0",
"type": "module",
"repository": {
"type": "git",
Expand Down
8 changes: 8 additions & 0 deletions packages/plugins/extended-validation/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @envelop/extended-validation

## 6.0.0

### Patch Changes

- Updated dependencies
[[`3ebaa3b`](https://github.com/graphql-hive/envelop/commit/3ebaa3b75b34f9a61aa517166f538796b383bfad)]:
- @envelop/core@5.3.0

## 5.1.3

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/extended-validation/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@envelop/extended-validation",
"version": "5.1.3",
"version": "6.0.0",
"type": "module",
"repository": {
"type": "git",
Expand Down
8 changes: 8 additions & 0 deletions packages/plugins/filter-operation-type/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @envelop/filter-operation-type

## 8.0.0

### Patch Changes

- Updated dependencies
[[`3ebaa3b`](https://github.com/graphql-hive/envelop/commit/3ebaa3b75b34f9a61aa517166f538796b383bfad)]:
- @envelop/core@5.3.0

## 7.1.3

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/filter-operation-type/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@envelop/filter-operation-type",
"version": "7.1.3",
"version": "8.0.0",
"type": "module",
"repository": {
"type": "git",
Expand Down
Loading