Skip to content

feat(@graphql-yoga/plugin-jwt): add generics to JWTExtendContextFields #3529

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions packages/plugins/jwt/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ import '@whatwg-node/server-plugin-cookies';
import { GraphQLError } from 'graphql';
import { badRequestError, unauthorizedError } from './utils.js';

export type JWTExtendContextFields = {
payload: JwtPayload;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
type ExtendableJwtPayload<T extends Record<string, any> = Record<string, never>> = JwtPayload & T;
Copy link
Member

@ardatan ardatan Jan 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
type ExtendableJwtPayload<T extends Record<string, any> = Record<string, never>> = JwtPayload & T;
type ExtendableJwtPayload<T extends Record<string, any> = Record<string, any>> = JwtPayload & T;

https://github.com/dotansimha/graphql-yoga/pull/3529/files#r1875898366


// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type JWTExtendContextFields<T extends Record<string, any> = Record<string, never>> = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't making this Record<string, never> a breaking change?
Because users from previous versions would get an error with regular objects, no?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes exactly. This should be Record<string, any>.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export type JWTExtendContextFields<T extends Record<string, any> = Record<string, never>> = {
export type JWTExtendContextFields<T extends Record<string, any> = Record<string, any>> = {

https://github.com/dotansimha/graphql-yoga/pull/3529/files#r1875898366

payload: ExtendableJwtPayload<T>;
token: {
value: string;
prefix?: string;
Expand Down
Loading