diff --git a/.changeset/rich-goats-rescue.md b/.changeset/rich-goats-rescue.md deleted file mode 100644 index 511954c08b..0000000000 --- a/.changeset/rich-goats-rescue.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -'@graphql-yoga/plugin-jwt': patch ---- - -- Do not throw when \`request\` is not available in the context, it can be a WebSockets connection -- Export helper `extractFromConnectionParams` to get the token from WebSocket `connectionParams` when GraphQL WS is used like [here](https://the-guild.dev/graphql/yoga-server/docs/features/subscriptions#graphql-over-websocket-protocol-via-graphql-ws) - -```ts -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 ' }) - ] - }) - ] -}) -``` diff --git a/packages/plugins/jwt/CHANGELOG.md b/packages/plugins/jwt/CHANGELOG.md index 2b951ea59c..0afc0b180c 100644 --- a/packages/plugins/jwt/CHANGELOG.md +++ b/packages/plugins/jwt/CHANGELOG.md @@ -1,5 +1,36 @@ # @graphql-yoga/plugin-jwt +## 3.4.9 + +### Patch Changes + +- [#3590](https://github.com/dotansimha/graphql-yoga/pull/3590) + [`840c6ae`](https://github.com/dotansimha/graphql-yoga/commit/840c6ae0b8e52fd8ecdc4cca86e1ee30fa99a8c4) + Thanks [@ardatan](https://github.com/ardatan)! - - Do not throw when \`request\` is not available + in the context, it can be a WebSockets connection + + - Export helper `extractFromConnectionParams` to get the token from WebSocket `connectionParams` + when GraphQL WS is used like + [here](https://the-guild.dev/graphql/yoga-server/docs/features/subscriptions#graphql-over-websocket-protocol-via-graphql-ws) + + ```ts + 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 ' }) + ] + }) + ] + }) + ``` + ## 3.4.8 ### Patch Changes diff --git a/packages/plugins/jwt/package.json b/packages/plugins/jwt/package.json index c1912233e9..398bf0c352 100644 --- a/packages/plugins/jwt/package.json +++ b/packages/plugins/jwt/package.json @@ -1,6 +1,6 @@ { "name": "@graphql-yoga/plugin-jwt", - "version": "3.4.8", + "version": "3.4.9", "type": "module", "description": "jwt plugin for GraphQL Yoga.", "repository": {