# @envelop/execute-subscription-event

Latest version **9.0.1** (published 2026-11-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install @envelop/execute-subscription-event
pnpm add @envelop/execute-subscription-event
yarn add @envelop/execute-subscription-event
bun add @envelop/execute-subscription-event
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 9.0.1 |
| Published | 2026-11-12 |
| First published | 2021-05-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=22.15.0 |
| Dependencies | 2 |
| Unpacked size | 15.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 8535 |
| Author | Laurin Quast <laurinquast@googlemail.com> |
| Maintainers | dotansimha, enisdenjo, theguild-bot |

## Links

- npm: https://www.npmjs.com/package/@envelop/execute-subscription-event
- Repository: https://github.com/graphql-hive/graphql-yoga
- Homepage: https://github.com/graphql-hive/graphql-yoga/tree/main/packages/envelop/plugins/execute-subscription-event#readme
- npm.io page: https://npm.io/package/@envelop/execute-subscription-event

## Dependencies (2)

- [tslib](https://npm.io/package/tslib.md) ^2.5.0
- [@whatwg-node/promise-helpers](https://npm.io/package/@whatwg-node/promise-helpers.md) ^2.0.2

## Recent versions

- 9.0.1 (latest) — 2026-11-12
- 9.0.1-alpha-20261112141330-38ba3951f67b0d318166a9440eade51b2f5e9cf9 (alpha) — 2026-11-12
- 9.0.1-rc-20261112141317-184086d94be0f21d781bea0446e4791b6a018507 (rc) — 2026-11-12
- 9.0.1-rc-20261111185655-c5cf052ddf41ad176b870cc0d16f11174fab5c0b — 2026-11-11
- 9.0.1-alpha-20261111175152-e39c721ee7ae5562ccdc6db5ec8239098e4af153 — 2026-11-11
- 9.0.0 — 2026-10-22
- 9.0.0-rc-20261022165416-7c29decb398764e6ac3915e1c539c478cbf19237 — 2026-10-22
- 9.0.0-alpha-20261019231601-b21e6cedc1a444383d9ce69fe6180f5b4ff67120 — 2026-10-19
- 9.0.0-alpha-20261019165905-4e993e96c2903cbe3084f9b49dfbf05042e3fe57 — 2026-10-19
- 9.0.0-alpha-20261019135505-9270088a653c3b9c07f54ef1cb67e69488e4e188 — 2026-10-19
- 9.0.0-alpha-20261009120802-464ace7b331b5693c49d18e270d79cb071e59247 — 2026-10-09
- 9.0.0-alpha-20261006205119-381bef34d7da2fde417073fec18c06eb58224f87 — 2026-10-06
- 9.0.0-alpha-20260929215310-f756e1d4981e8dd5ac5e128b5c2554893ae24a52 — 2026-09-29
- 8.2.1 — 2026-09-16
- 8.2.0 — 2026-08-19
- … 1561 more at https://npm.io/package/@envelop/execute-subscription-event/versions

## README

## `@envelop/execute-subscription-event`

Utilities for hooking into the
[ExecuteSubscriptionEvent](<https://spec.graphql.org/draft/#ExecuteSubscriptionEvent()>) phase.

### `useContextValuePerExecuteSubscriptionEvent`

Create a new context object per `ExecuteSubscriptionEvent` phase, allowing to bypass common issues
with context objects such as [`DataLoader`](https://github.com/graphql-hive/envelop/issues/80)
[caching](https://github.com/graphql/graphql-js/issues/894)
[issues](https://github.com/apollographql/subscriptions-transport-ws/issues/330).

```ts
import { execute, parse, specifiedRules, subscribe, validate } from 'graphql'
import { envelop, useEngine } from '@envelop/core'
import { useContextValuePerExecuteSubscriptionEvent } from '@envelop/execute-subscription-event'
import { createContext, createDataLoaders } from './context'

const getEnveloped = envelop({
  plugins: [
    useEngine({ parse, validate, specifiedRules, execute, subscribe }),
    useContext(() => createContext()),
    useContextValuePerExecuteSubscriptionEvent(() => ({
      // Existing context is merged with this context partial
      // By recreating the DataLoader we ensure no DataLoader caches from the previous event/initial field subscribe call are are hit
      contextPartial: {
        dataLoaders: createDataLoaders()
      }
    }))
    // ... other plugins ...
  ]
})
```

Alternatively, you can also provide a callback that is invoked after each
[`ExecuteSubscriptionEvent`](<https://spec.graphql.org/draft/#ExecuteSubscriptionEvent()>) phase.

```ts
import { execute, parse, specifiedRules, subscribe, validate } from 'graphql'
import { envelop, useEngine } from '@envelop/core'
import { useContextValuePerExecuteSubscriptionEvent } from '@envelop/execute-subscription-event'
import { createContext, createDataLoaders } from './context'

const getEnveloped = envelop({
  plugins: [
    useEngine({ parse, validate, specifiedRules, execute, subscribe }),
    useContext(() => createContext()),
    useContextValuePerExecuteSubscriptionEvent(({ args }) => ({
      onEnd: () => {
        // Note that onEnd is invoked only after each ExecuteSubscriptionEvent phase
        // This means the initial event will still use the cache from potential subscribe dataloader calls
        // If you use this to clear DataLoader caches it is recommended to not do any DataLoader calls within your field subscribe function.
        args.contextValue.dataLoaders.users.clearAll()
        args.contextValue.dataLoaders.posts.clearAll()
      }
    }))
    // ... other plugins ...
  ]
})
```

---
_Source: https://npm.io/package/@envelop/execute-subscription-event · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
