@envelop/types
Changelog for @envelop/types: every release with its changes and the pull requests behind them.
6.0.0
Major Changes
-
#4574
79b0e8bThanks @egoodwinx! - ### Breaking Changes- Node: minimum supported version is now Node 22. Node 18 and 20 are no longer supported. Future releases will only support Node >=22.
- GraphQL: minimum supported version is now GraphQL 16. GraphQL 14 and 15 are no longer supported.
- Request body parsing: Yoga now limits request bodies to 25,000,000 bytes by default.
Enforcing this limit streams the body through a byte counter, making POST body parsing
asynchronous even for an in-memory body. As a result,
yoga.fetch()can return a Promise where it previously returned a synchronous Response, even when all resolvers and plugins are synchronous.
Migration
- If you’re on Node 18/20, upgrade to Node 22 or later before upgrading this package.
- If you’re on graphql 14/15, upgrade to graphql 16 or 17 first.
- Await
yoga.fetch()and response body parsing instead of relying on synchronous results. SetmaxRequestBodySize: falseincreateYogato disable the body-size limit and preserve synchronous parsing for in-memory bodies, but only if you enforce an appropriate request-body limit elsewhere.
Minor Changes
-
#4575
862447aThanks @egoodwinx! - Use@graphql-hive/loggerand add correlated, per-request logging (closes #4048)Every request now gets its own logger, available as
context.log(andserverContext.login plugin hooks), tagged with arequestId. Everything logged while handling a request can be correlated by that id.The request id is taken from the host integration if it already assigned one (e.g. Fastify’s
request.id), otherwise from the incomingx-request-idheader, otherwise generated. It is also sent back in thex-request-idresponse header. Configure it with the newrequestIdoption:createYoga({ requestId: { // don't trust the incoming header, recommended when clients can reach the server directly trustHeader: false, headerName: 'x-correlation-id', generateRequestId: () => myId() } })Pass
requestId: falseto disable it.At the
infolevel, a single “Request processed” line is logged per request with the method, path, operation name and type, response status, error count and duration. At thedebuglevel, more details about request processing are logged.Masked errors are now logged with the request’s logger, so they can be traced back to the request that caused them. Custom
maskErrorfunctions receive the request’s context as an optional fourth argument.The
@envelop/newrelic,@envelop/auth0,@envelop/resource-limitations,@envelop/statsd,@envelop/graphql-jit,@envelop/response-cacheand@envelop/response-cache-cloudflare-kvplugins accept a newlogoption for their own messages, instead of always writing to the console.@envelop/response-cache’sshouldCacheResultnow also receives the GraphQLcontext.Breaking Changes
- The
@graphql-yoga/loggerpackage has been removed.graphql-yogare-exportsLogger,MemoryLogWriterandLogLevelfrom@graphql-hive/loggerinstead. createLoggerand theYogaLoggertype are no longer exported. Usenew Logger(options)instead.- The
loggingoption now takesboolean | Logger | LogLevel, whereLoggeris the one from@graphql-hive/logger. yoga.loggerhas been renamed toyoga.log.- The
loggeroption ofuseGraphiQLanduseHealthCheckhas been removed. They now log through the request’s logger. @graphql-yoga/nestjsnow logs through Nest’sLoggerby default instead of not logging at all. Passlogging: falseto keep the previous behaviour.logging: trueon Fastify no longer logs through Fastify’s logger, pass it explicitly instead (see below).@envelop/apollo-federation,@envelop/auth0,@envelop/graphql-jit,@envelop/newrelic,@envelop/resource-limitations,@envelop/response-cache,@envelop/response-cache-cloudflare-kvand@envelop/statsdnow have a peer dependency on@graphql-hive/loggerthat you must install.@envelop/apollo-federation’sloggeroption now expects aLoggerfrom@graphql-hive/loggerand defaults tonew Logger()instead ofconsole.
Migration
Create loggers with
Logger:- import { createLogger } from 'graphql-yoga'; + import { Logger } from 'graphql-yoga'; createYoga({ - logging: createLogger('debug'), + logging: new Logger({ level: 'debug' }), });Use
loginstead ofloggeron the Yoga instance:const plugin = { onYogaInit({ yoga }) { - yoga.logger.info('ready'); + yoga.log.info('ready'); }, };Prefer the request-scoped logger inside resolvers and plugin hooks so the logs carry the request id:
const resolvers = { Query: { hello: (_, __, context) => { context.log.debug('resolving hello') return 'world' } } }If you use any of the
@envelop/*plugins listed above, install the logger:npm i @graphql-hive/loggerIf you depended on
@graphql-yoga/loggerdirectly, switch to@graphql-hive/logger:- import { Logger } from '@graphql-yoga/logger'; + import { Logger } from '@graphql-hive/logger';To keep logging through Fastify’s logger in
@graphql-yoga/nestjs:import { Logger } from 'graphql-yoga' import { PinoLogWriter } from '@graphql-hive/logger/writers/pino' // in your yoga driver options logging: new Logger({ writers: [new PinoLogWriter(app.log)] }) - The
5.2.2
Patch Changes
- #4577
7bff35cThanks @egoodwinx! - Add homepage and bugs.url to package.json files
5.2.1
Patch Changes
- #2486
914f9edThanks @EmrysMyrddin! - Fix the name of the new envelop instrumentation API
5.2.0
Minor Changes
-
#2430
a107c89Thanks @EmrysMyrddin! - ## NewInstrumentsAPIIntroducation of a new API allowing to instrument the graphql pipeline.
This new API differs from already existing Hooks by not having access to intup/output of phases. The goal of
Instrumentsis to run allow running code before, after or araound the whole process of a phase, incuding plugins hooks executions.The main use case of this new API is observability (monitoring, tracing, etc…).
Basic usage
import { envelop } from '@envelop/core' import Sentry from '@sentry/node' const getEnveloped = envelop({ plugins: [ { instruments: { execute: ({ context }, wrapped) => Sentry.startSpan({ name: 'Graphql Operation' }, async () => { try { await wrapped() } catch (err) { Sentry.captureException(err) } }) } } ] })Mutliple instruments plugins
It is possilbe to have multiple instruments plugins (Prometheus and Sentry for example), they will be automatically composed by envelop in the same order than the plugin array (first is outtermost, last is inner most).
import { useOpentelemetry } from '@envelop/opentelemetry' import { useSentry } from '@envelop/sentry' const getEnveloped = envelop({ plugins: [useSentry(), useOpentelemetry()] })Custom instruments ordering
If the default composition ordering doesn’t suite your need, you can mannually compose instruments. This allows to have a different execution order of hooks and instruments.
import { useOpentelemetry } from '@envelop/opentelemetry' import { composeInstruments, useSentry } from '@envelop/sentry' const { instruments: sentryInstruments, ...sentryPlugin } = useSentry() const { instruments: otelInstruments, ...otelPlugin } = useOpentelemetry() const instruments = composeInstruments([otelInstruments, sentryInstruments]) const getEnveloped = envelop({ plugins: [{ instruments }, sentryPlugin, otelPlugin] })
5.1.1
Patch Changes
- #2455
5b6a166Thanks @ardatan! - dependencies updates:- Added dependency
@whatwg-node/promise-helpers@^1.0.0↗︎ (todependencies)
- Added dependency
5.1.0
Minor Changes
- #2438
9bd1b20Thanks @ardatan! - Addcontextfield toonExecuteandonSubscribehooks payloads. This harmonize all the hooks invovled in the handling of a graphql operation.
5.0.0
Major Changes
- #1986
68e7a2a5Thanks @EmrysMyrddin! - Breaking Change: Support of Node 16 is dropped.
4.0.1
Patch Changes
- #1896
834e1e39Thanks @EmrysMyrddin! - add support for @defer and @stream
4.0.0
Major Changes
3.0.2
Patch Changes
- #1725
c1eb2c09Thanks @n1ru4l! - dependencies updates:- Updated dependency
tslib@^2.5.0↗︎ (from^2.4.0, independencies)
- Updated dependency
3.0.1
Patch Changes
- #1587
e2ff77edThanks @enisdenjo! - Don’t useIdTypeScript generic utility that can cause a circular constraint error
2.4.0
Minor Changes
-
#1499
1f7af02bThanks @viniciuspalma! - Adding tslib to package dependenciesProjects that currently are using yarn Berry with PnP or any strict dependency resolver, that requires that all dependencies are specified on package.json otherwise it would endue in an error if not treated correct
Since https://www.typescriptlang.org/tsconfig#importHelpers is currently being used, tslib should be exported as a dependency to external runners get the proper import.
Change on each package:
// package.json { "dependencies": { "tslib": "^2.4.0" } }
2.3.1
Patch Changes
- 071f946: Fix CommonJS TypeScript resolution with
moduleResolutionnode16ornodenext
2.3.0
Minor Changes
- 8bb2738: Support TypeScript module resolution.
2.2.1
Patch Changes
- fbf6155: update package.json repository links to point to the new home
2.2.0
Minor Changes
-
af23408: Pass context to registerContextErrorHandler
export const useMyHook = (): Plugin => { return { onPluginInit(context) { context.registerContextErrorHandler(({ context }) => { console.error( 'Error occurred during context creation but at least I have the context so far', context ) }) } } }
2.1.0
Minor Changes
- d5115b4: add
setResulttoAfterValidateEventPayloadfor altering the validation errors.
2.0.0
Major Changes
-
aac65ef: Move
onResolverCalledfrom withinOnExecuteHookResultandOnSubscribeHookResultto thePlugintype.import type { Plugin } from "@envelop/core"; const plugin: Plugin = { onExecute() { - return { - onResolverCalled() {} - } - } + }, + onResolverCalled() {}, }We highly recommend avoiding to use any plugins that use
onResolverCalledwithin your production environment as it has severe impact on the performance of the individual resolver functions within your schema.The schema resolver functions are now ONLY wrapped if any plugin in your envelop setup uses the
onResolverCalledhook.If you need any shared state between
onExecuteandonResolverCalledyou can share it by extending the context object.import type { Plugin } from '@envelop/core' const sharedStateSymbol = Symbol('sharedState') const plugin: Plugin = { onExecute({ extendContext }) { extendContext({ [sharedStateSymbol]: { value: 1 } }) }, onResolverCalled({ context }) { const sharedState = context[sharedStateSymbol] // logs 1 console.log(sharedState.value) } }
Minor Changes
-
4106e08: Add new option
breakContextBuildingtoOnContextBuildingEventPayload.This allows short-circuiting the context building phase. Please use this with care as careless usage of it can result in severe errors during the execution phase, as the context might not include all the fields your schema resolvers need.
1.5.1
Patch Changes
-
b1a0331: Properly list
@envelop/coreas apeerDependencyin plugins.This resolves issues where the bundled envelop plugins published to npm had logic inlined from the
@envelop/corepackage, causinginstanceofcheck ofEnvelopErrorto fail.
1.5.0
Minor Changes
- 090cae4: GraphQL v16 support
1.4.0
Minor Changes
- 04120de: add support for GraphQL.js 16
1.3.0
Minor Changes
- 365a982: Allow async OnExecuteDone hook
1.2.0
Minor Changes
- d65e35d: add enableIf utility to enable plugins conditionally
- 26475c9: useErrorHandler: Pass in the execution arguments to the error handler callbacks.
1.1.0
Minor Changes
-
7704fc3: Add API for registering a context creation error handler.
export const useMyHook = (): Plugin => { return { onPluginInit(context) { context.registerContextErrorHandler(({ error, setError }) => { console.error('Error occurred during context creation.', error) setError(new Error('Something went wrong :(')) }) } } }
1.0.2
Patch Changes
- 94db02d: Added new helper
handleStreamOrSingleExecutionResult - 94db02d: Update usage of plugins to use the correct
isAsyncIterableand new helperhandleStreamOrSingleExecutionResult
1.0.1
Patch Changes
- c24a8fd: re-use graphql “execute” & “subscribe” types
- adca399: add jsdoc comments for hook types
1.0.0
Major Changes
- 40bc444: v1 major release for envelop packages
Minor Changes
- dbb241d: allow hooking into published subscribe values
0.4.2
Patch Changes
- a7321e1: Fix issues with compiled d.ts
0.4.1
Patch Changes
- 932f6a8: Added better type-safety for contextValue in OnExecute hook
0.4.0
Minor Changes
- 50dffaa: Added new hook for onEnveloped
Patch Changes
- 778c207: Better type safety for OnEnveloped hook
0.3.0
Minor Changes
- 2113527: Extend Envelop plugin API with the ability to access and replace resolver function
Patch Changes
- 28ad742: Improve TypeScript types
0.2.1
Patch Changes
- 7f4901d: Fix issues with contextFactory and missing context coming from GraphQL pipeline orchestrator
0.2.0
Minor Changes
- a5bee94: * Allow access to context in all phases
- Improve usage of
getEnvelopedfunction and allow to pass initial context there
- Improve usage of
- eb6f53b: ESM Support for all plugins and envelop core
0.1.4
Patch Changes
- ced704e: Allow plugins to stop execution and return errors
0.1.3
Patch Changes
- 5fc65a4: Improve type safety for plugins context
0.1.2
Patch Changes
- f5177eb: Added
setResultto the result of onResolverCalled
0.1.1
Patch Changes
- 925a1ea: Extend
onSchemaChangeand allow to override schema. Make sure to avoid infinite loops.
0.1.0
Minor Changes
- 2fba0b4: Initial version bump
0.0.2
Patch Changes
- b1333b0: Initial packages release
0.0.1
Patch Changes
- c499ae8: First bump as envelop
- 2cfc726: Fixes