-
Notifications
You must be signed in to change notification settings - Fork 132
feat(core): New plugin utils withState
#2607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Contributor
🚀 Snapshot Release (
|
| Package | Version | Info |
|---|---|---|
@envelop/core |
5.3.0-alpha-20250619123936-34350ff4ef8e7fc3f05ccdfff4465668f5002b76 |
npm ↗︎ unpkg ↗︎ |
@envelop/apollo-datasources |
6.0.0-alpha-20250619123936-34350ff4ef8e7fc3f05ccdfff4465668f5002b76 |
npm ↗︎ unpkg ↗︎ |
@envelop/apollo-federation |
7.0.0-alpha-20250619123936-34350ff4ef8e7fc3f05ccdfff4465668f5002b76 |
npm ↗︎ unpkg ↗︎ |
@envelop/apollo-server-errors |
8.0.0-alpha-20250619123936-34350ff4ef8e7fc3f05ccdfff4465668f5002b76 |
npm ↗︎ unpkg ↗︎ |
@envelop/apollo-tracing |
8.0.0-alpha-20250619123936-34350ff4ef8e7fc3f05ccdfff4465668f5002b76 |
npm ↗︎ unpkg ↗︎ |
@envelop/auth0 |
8.0.0-alpha-20250619123936-34350ff4ef8e7fc3f05ccdfff4465668f5002b76 |
npm ↗︎ unpkg ↗︎ |
@envelop/dataloader |
8.0.0-alpha-20250619123936-34350ff4ef8e7fc3f05ccdfff4465668f5002b76 |
npm ↗︎ unpkg ↗︎ |
@envelop/depth-limit |
6.0.0-alpha-20250619123936-34350ff4ef8e7fc3f05ccdfff4465668f5002b76 |
npm ↗︎ unpkg ↗︎ |
@envelop/disable-introspection |
8.0.0-alpha-20250619123936-34350ff4ef8e7fc3f05ccdfff4465668f5002b76 |
npm ↗︎ unpkg ↗︎ |
@envelop/execute-subscription-event |
7.0.0-alpha-20250619123936-34350ff4ef8e7fc3f05ccdfff4465668f5002b76 |
npm ↗︎ unpkg ↗︎ |
@envelop/extended-validation |
6.0.0-alpha-20250619123936-34350ff4ef8e7fc3f05ccdfff4465668f5002b76 |
npm ↗︎ unpkg ↗︎ |
@envelop/filter-operation-type |
8.0.0-alpha-20250619123936-34350ff4ef8e7fc3f05ccdfff4465668f5002b76 |
npm ↗︎ unpkg ↗︎ |
@envelop/fragment-arguments |
8.0.0-alpha-20250619123936-34350ff4ef8e7fc3f05ccdfff4465668f5002b76 |
npm ↗︎ unpkg ↗︎ |
@envelop/generic-auth |
10.0.0-alpha-20250619123936-34350ff4ef8e7fc3f05ccdfff4465668f5002b76 |
npm ↗︎ unpkg ↗︎ |
@envelop/graphql-jit |
10.0.0-alpha-20250619123936-34350ff4ef8e7fc3f05ccdfff4465668f5002b76 |
npm ↗︎ unpkg ↗︎ |
@envelop/graphql-middleware |
8.0.0-alpha-20250619123936-34350ff4ef8e7fc3f05ccdfff4465668f5002b76 |
npm ↗︎ unpkg ↗︎ |
@envelop/graphql-modules |
8.0.0-alpha-20250619123936-34350ff4ef8e7fc3f05ccdfff4465668f5002b76 |
npm ↗︎ unpkg ↗︎ |
@envelop/immediate-introspection |
6.0.0-alpha-20250619123936-34350ff4ef8e7fc3f05ccdfff4465668f5002b76 |
npm ↗︎ unpkg ↗︎ |
@envelop/live-query |
9.0.0-alpha-20250619123936-34350ff4ef8e7fc3f05ccdfff4465668f5002b76 |
npm ↗︎ unpkg ↗︎ |
@envelop/newrelic |
9.0.0-alpha-20250619123936-34350ff4ef8e7fc3f05ccdfff4465668f5002b76 |
npm ↗︎ unpkg ↗︎ |
@envelop/on-resolve |
6.0.0-alpha-20250619123936-34350ff4ef8e7fc3f05ccdfff4465668f5002b76 |
npm ↗︎ unpkg ↗︎ |
@envelop/opentelemetry |
8.0.0-alpha-20250619123936-34350ff4ef8e7fc3f05ccdfff4465668f5002b76 |
npm ↗︎ unpkg ↗︎ |
@envelop/operation-field-permissions |
8.0.0-alpha-20250619123936-34350ff4ef8e7fc3f05ccdfff4465668f5002b76 |
npm ↗︎ unpkg ↗︎ |
@envelop/parser-cache |
9.0.0-alpha-20250619123936-34350ff4ef8e7fc3f05ccdfff4465668f5002b76 |
npm ↗︎ unpkg ↗︎ |
@envelop/persisted-operations |
9.0.0-alpha-20250619123936-34350ff4ef8e7fc3f05ccdfff4465668f5002b76 |
npm ↗︎ unpkg ↗︎ |
@envelop/preload-assets |
8.0.0-alpha-20250619123936-34350ff4ef8e7fc3f05ccdfff4465668f5002b76 |
npm ↗︎ unpkg ↗︎ |
@envelop/prometheus |
13.0.0-alpha-20250619123936-34350ff4ef8e7fc3f05ccdfff4465668f5002b76 |
npm ↗︎ unpkg ↗︎ |
@envelop/rate-limiter |
8.0.0-alpha-20250619123936-34350ff4ef8e7fc3f05ccdfff4465668f5002b76 |
npm ↗︎ unpkg ↗︎ |
@envelop/resource-limitations |
7.0.0-alpha-20250619123936-34350ff4ef8e7fc3f05ccdfff4465668f5002b76 |
npm ↗︎ unpkg ↗︎ |
@envelop/response-cache |
8.0.0-alpha-20250619123936-34350ff4ef8e7fc3f05ccdfff4465668f5002b76 |
npm ↗︎ unpkg ↗︎ |
@envelop/response-cache-cloudflare-kv |
4.0.0-alpha-20250619123936-34350ff4ef8e7fc3f05ccdfff4465668f5002b76 |
npm ↗︎ unpkg ↗︎ |
@envelop/response-cache-redis |
4.2.4-alpha-20250619123936-34350ff4ef8e7fc3f05ccdfff4465668f5002b76 |
npm ↗︎ unpkg ↗︎ |
@envelop/sentry |
14.0.0-alpha-20250619123936-34350ff4ef8e7fc3f05ccdfff4465668f5002b76 |
npm ↗︎ unpkg ↗︎ |
@envelop/statsd |
7.0.0-alpha-20250619123936-34350ff4ef8e7fc3f05ccdfff4465668f5002b76 |
npm ↗︎ unpkg ↗︎ |
@envelop/validation-cache |
9.0.0-alpha-20250619123936-34350ff4ef8e7fc3f05ccdfff4465668f5002b76 |
npm ↗︎ unpkg ↗︎ |
@envelop/testing |
9.0.0-alpha-20250619123936-34350ff4ef8e7fc3f05ccdfff4465668f5002b76 |
npm ↗︎ unpkg ↗︎ |
Contributor
enisdenjo
approved these changes
Jun 19, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
WeakMapwith a stable key (often thecontextorrequestobject). While it works, it's not very convenient for plugin developers, andis prone to error with the choice of key.
The new
withStateutility solves this DX issue by providing an easy and straightforward API fordata sharing between hooks.
The
statepayload field will be available in all relevant hooks, making it easy to access shareddata. It also forces the developer to choose the scope for the data:
forOperationfor a data scoped to GraphQL operation (Envelop, Yoga and Hive Gateway)forRequestfor a data scoped to HTTP request (Yoga and Hive Gateway)forSubgraphExecutionfor 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
getStatefunction: