@graphql-yoga/plugin-jwt
Changelog for @graphql-yoga/plugin-jwt: every release with its changes and the pull requests behind them.
4.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
Patch Changes
3.18.6
Patch Changes
- Updated dependencies
[
9294289]:- graphql-yoga@5.24.6
3.18.5
Patch Changes
- Updated dependencies []:
- graphql-yoga@5.24.5
3.18.4
Patch Changes
- Updated dependencies
[
d8b8860]:- graphql-yoga@5.24.4
3.18.3
Patch Changes
- Updated dependencies
[
c6febdc]:- graphql-yoga@5.24.3
3.18.2
Patch Changes
- Updated dependencies
[
c08efde]:- graphql-yoga@5.24.2
3.18.1
Patch Changes
- Updated dependencies
[
c6a9aa4]:- graphql-yoga@5.24.1
3.18.0
Patch Changes
-
#4577
7bff35cThanks @egoodwinx! - Add homepage and bugs.url to package.json files -
Updated dependencies [
7bff35c,3763aca]:- graphql-yoga@5.24.0
3.17.0
Patch Changes
3.16.0
Minor Changes
-
#4545
94ebe5bThanks @egoodwinx! - Update to support graphql-js 17Bump package versions, fix expected typing, and update compatability with subscribe.
Patch Changes
- Updated dependencies
[
94ebe5b]:- graphql-yoga@5.22.0
3.15.3
Patch Changes
- Updated dependencies
[
04014d2]:- graphql-yoga@5.21.3
3.15.2
Patch Changes
- Updated dependencies
[
39b55ba]:- graphql-yoga@5.21.2
3.15.1
Patch Changes
- Updated dependencies
[
4b43efd]:- graphql-yoga@5.21.1
3.15.0
Patch Changes
- Updated dependencies
[
e263f7e]:- graphql-yoga@5.21.0
3.14.0
Patch Changes
- Updated dependencies
[
93f1dc0]:- graphql-yoga@5.20.0
3.13.0
Patch Changes
- Updated dependencies
[
7e0aaf6]:- graphql-yoga@5.19.0
3.12.1
Patch Changes
3.12.0
Patch Changes
- Updated dependencies
[
3eabd17]:- graphql-yoga@5.18.0
3.11.1
Patch Changes
-
#4302
c27f550Thanks @beaumontjonathan! - Bump @whatwg-node/promise-helpers to fix missing export unfakePromise -
Updated dependencies [
c27f550]:- graphql-yoga@5.17.1
3.11.0
Patch Changes
3.10.2
Patch Changes
- Updated dependencies
[
ba38629]:- graphql-yoga@5.16.2
3.10.1
Patch Changes
3.10.0
Patch Changes
3.9.2
Patch Changes
- Updated dependencies
[
e7b8906]:- graphql-yoga@5.15.2
3.9.1
Patch Changes
- Updated dependencies
[
ecd605b]:- graphql-yoga@5.15.1
3.9.0
Patch Changes
3.8.0
Patch Changes
3.7.6
Patch Changes
- Updated dependencies
[
8b41a52]:- graphql-yoga@5.13.5
3.7.5
Patch Changes
- Updated dependencies
[
000c33d]:- graphql-yoga@5.13.4
3.7.4
Patch Changes
3.7.3
Patch Changes
3.7.2
Patch Changes
- Updated dependencies
[
dee7995]:- graphql-yoga@5.13.1
3.7.1
Patch Changes
- #3860
9599d45Thanks @renovate! - dependencies updates:- Added dependency
@whatwg-node/promise-helpers@^1.2.4↗︎ (todependencies)
- Added dependency
3.7.0
Patch Changes
3.6.2
Patch Changes
- Updated dependencies
[
a6b3de9]:- graphql-yoga@5.12.2
3.6.1
Patch Changes
- Updated dependencies
[
fbf328c]:- graphql-yoga@5.12.1
3.6.0
Patch Changes
3.5.0
Patch Changes
3.4.13
Patch Changes
- Updated dependencies
[
1c055f5]:- graphql-yoga@5.10.11
3.4.12
Patch Changes
- #3677
7419797Thanks @ardatan! - Ensure the JWT context has been added before any GraphQL Execution hooks when the plugin is used via Yoga
3.4.11
Patch Changes
- Updated dependencies []:
- graphql-yoga@5.10.10
3.4.10
Patch Changes
3.4.9
Patch Changes
-
#3590
840c6aeThanks @ardatan! - - Do not throw when `request` is not available in the context, it can be a WebSockets connection- Export helper
extractFromConnectionParamsto get the token from WebSocketconnectionParamswhen GraphQL WS is used like here
import { extractFromConnectionParams, extractFromHeader, useJWT } from '@graphql-yoga/plugin-jwt' const yoga = createYoga({ // ... plugins: [ useJWT({ // So it will look for the token in the connectionParams.my-token field in case of a WebSockets connection // It will check WS params and headers, and get the available one lookupLocations: [ extractFromConnectionParams({ name: 'my-token' }), extractFromHeader({ name: 'authorization', prefix: 'Bearer ' }) ] }) ] }) - Export helper
3.4.8
Patch Changes
- Updated dependencies
[
ed344ea]:- graphql-yoga@5.10.8
3.4.7
Patch Changes
3.4.6
Patch Changes
- Updated dependencies
[
121ccba]:- graphql-yoga@5.10.6
3.4.5
Patch Changes
- #3532
57e7701Thanks @ardatan! - dependencies updates:- Updated dependency
graphql@^15.2.0 || ^16.0.0↗︎ (from^16.5.0, inpeerDependencies)
- Updated dependency
- Updated dependencies
[
eca7cd1,05fe345]:- graphql-yoga@5.10.5
3.4.4
Patch Changes
- Updated dependencies
[
944ecd5]:- graphql-yoga@5.10.4
3.4.3
Patch Changes
3.4.2
Patch Changes
3.4.1
Patch Changes
- #3479
20cd9b6Thanks @ardatan! - dependencies updates:- Updated dependency
@whatwg-node/server-plugin-cookies@^1.0.3↗︎ (from1.0.2, independencies)
- Updated dependency
- Updated dependencies
[
20cd9b6]:- graphql-yoga@5.10.1
3.4.0
Patch Changes
- Updated dependencies
[
f81501c]:- graphql-yoga@5.10.0
3.3.0
Patch Changes
-
#3426
076d25cThanks @EmrysMyrddin! - Fix typo of the optionsingingKeyProviders=>signingKeyProviders. -
Updated dependencies [
2523d9f,87ee333]:- graphql-yoga@5.9.0
3.2.0
Patch Changes
3.1.0
Patch Changes
3.0.2
Patch Changes
- Updated dependencies
[
0866c1b]:- graphql-yoga@5.6.3
3.0.1
Patch Changes
3.0.0
Major Changes
-
#3366
057ad06Thanks @dotansimha! - Re-write for the JWT plugin. This plugin can be configured now with multiple providers, lookup locations, token verification, and more.The version has better version coverage, and it provides an improved API for configuring provider and custom behaviors.
Breaking Change: New Plugin Configuration
Signing key providers
❌ The
signingKeyoption has be removed. ❌ ThejwksUri+jwksOptsoptions has been removed. ✅ Multiple signing key providers and support for fallbacks (singingKeyProviders[]). ✅ Improved API for defining signing key configuration. ✅ Better defaults for caching and rate-limiting for remote JWKS providers.Before
useJWT({ signingKey: "...", // or jwksUri: "http://example.com/..." jwksOpts: { // ... } })After
import { createInlineSigningKeyProvider, createRemoteJwksSigningKeyProvider, useJWT } from '@graphql-yoga/plugin-jwt' useJWT({ // Pass one or more providers singingKeyProviders: [ createRemoteJwksSigningKeyProvider({ // ... }) // This one also acts as a fallback in case of a fetching issue with the 1st provider createInlineSigningKeyProvider({ signingKey: "..."}) ] })Improved Token Lookup
❌ Removed
getTokenoption from the root config. ✅ Added support for autmatically extracting the JWT token from cookie or header. ✅ Easier setup for extracting from multiple locations. ✅getTokenis still available for advanced use-cases, you can pass a custom function tolookupLocations.Before
useJWT({ getToken: payload => payload.request.headers.get('...') })After
With built-in extractors:
imoprt { extractFromHeader, extractFromCookie, useJWT } from '@graphql-yoga/plugin-jwt' const yoga = createYoga({ // ... plugins: [ useCookies(), // Required if "extractFromCookie" is used. useJWT({ lookupLocations: [ extractFromHeader({ name: 'authorization', prefix: 'Bearer' }), extractFromHeader({ name: 'x-legacy-auth' }), extractFromHeader({ name: 'x-api-key', prefix: 'API-Access' }), extractFromCookie({ name: 'browserAuth' }) ] }) ] })With a custom
getToken:useJWT({ lookupLocations: [payload => payload.request.headers.get('...')] })Improved Verification Options
❌ Removed root-level config
algorithms+audience+issuerflags. ✅ Easy API for customizing token verifications (based onjsonwebtokenlibrary). ✅ Better defaults for token algorithm verification (before:RS256, after:RS256andHS256)Before
useJWT({ algorithms: ['RS256'], audience: 'my.app', issuer: 'http://my-issuer' })After
useJWT({ tokenVerification: { algorithms: ['RS256', 'HS256'], audience: 'my.app', issuer: 'http://my-issuer' // You can pass more options to `jsonwebtoken.verify("...", options)` here } })Customized Token Rejection
✅ New config flag
reject: { ... }for configuring how to handle a missing or invalid tokens (enbaled by default).useJWT({ reject: { missingToken: true, invalidToken: true } })Flexible Context Injection
❌ Removed root-level config
extendContextFieldflags. ✅ Added root-level configextendContext(boolean/string) ✅ Token and payload are injected now to the context (structure:{ payload: {}, token: { value, prefix }})Before
useJWT({ reject: { extendContextField: true } })After
// Can be a boolean. By default injects to "context.jwt" field useJWT({ reject: { extendContext: true } }) // Or an object to customize the field name useJWT({ reject: { extendContext: 'myJwt' } })
Patch Changes
- #3366
057ad06Thanks @dotansimha! - dependencies updates:- Added dependency
@whatwg-node/server-plugin-cookies@1.0.2↗︎ (todependencies)
- Added dependency
- Updated dependencies
[
4252e3d]:- graphql-yoga@5.6.1
2.6.0
Patch Changes
- Updated dependencies
[
9f3f945]:- graphql-yoga@5.6.0
2.5.0
Patch Changes
- Updated dependencies
[
0208024]:- graphql-yoga@5.5.0
2.4.0
Minor Changes
-
#3182
8663e78Thanks @bgentry! - Add the possibility to customize JwksClient options -
#3275
25886faThanks @EmrysMyrddin! - Update type to allow passing every jsonwebtoken.verify options
Patch Changes
- #3300
fdd902cThanks @EmrysMyrddin! - dependencies updates:- Updated dependency
graphql-yoga@workspace:^↗︎ (from^5.3.1, inpeerDependencies)
- Updated dependency
- Updated dependencies
[
4cd43b9,fdd902c,d5dfe99,7335a82,f9aa1cd]:- graphql-yoga@5.4.0
2.3.1
Patch Changes
2.3.0
Patch Changes
2.2.0
Patch Changes
2.1.2
Patch Changes
- Updated dependencies
[
3ef877a7]:- graphql-yoga@5.1.1
2.1.1
Patch Changes
- #3149
b9d2afccThanks @EmrysMyrddin! - Fix unauthorized error resulting in an response with 500 status or in a server crash (depending on actual HTTP server implementation used).
2.1.0
Patch Changes
- Updated dependencies
[
b1f0e3a2]:- graphql-yoga@5.1.0
2.0.2
Patch Changes
- Updated dependencies
[
77d107fe]:- graphql-yoga@5.0.2
2.0.1
Patch Changes
- Updated dependencies
[
3fea19f2]:- graphql-yoga@5.0.1
2.0.0
Major Changes
- #3063
01430e03Thanks @EmrysMyrddin! - Breaking Change: Drop support of Node.js 16
Patch Changes
1.1.0
Minor Changes
- #3029
2d0cd188Thanks @EmrysMyrddin! - Allow getToken to return a promise.
Patch Changes
- Updated dependencies
[
bf602edf]:- graphql-yoga@4.0.5
1.0.1
Patch Changes
- Updated dependencies
[
5f182006]:- graphql-yoga@4.0.4
1.0.0
Major Changes
Patch Changes
-
#2933
cb47a72cThanks @renovate! - dependencies updates:- Updated dependency
jsonwebtoken@^9.0.0↗︎ (from^8.5.1, independencies)
- Updated dependency
-
#2935
1c89cfd5Thanks @renovate! - dependencies updates:- Updated dependency
jwks-rsa@^3.0.0↗︎ (from^2.1.5, independencies)
- Updated dependency