Skip to content

Commit 81a736b

Browse files
Bump whatwg-node and improve types (#3384)
* Bump whatwg-node and improve types * chore(dependencies): updated changesets for modified dependencies --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent ff9c21b commit 81a736b

File tree

8 files changed

+205
-361
lines changed

8 files changed

+205
-361
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
'graphql-yoga': patch
3+
---
4+
dependencies updates:
5+
- Updated dependency [`@envelop/core@^5.0.1`
6+
↗︎](https://www.npmjs.com/package/@envelop/core/v/5.0.1) (from `^5.0.0`, in `dependencies`)
7+
- Updated dependency [`@graphql-tools/executor@^1.3.0`
8+
↗︎](https://www.npmjs.com/package/@graphql-tools/executor/v/1.3.0) (from `^1.2.5`, in
9+
`dependencies`)
10+
- Updated dependency [`@graphql-tools/schema@^10.0.4`
11+
↗︎](https://www.npmjs.com/package/@graphql-tools/schema/v/10.0.4) (from `^10.0.0`, in
12+
`dependencies`)
13+
- Updated dependency [`@graphql-tools/utils@^10.3.2`
14+
↗︎](https://www.npmjs.com/package/@graphql-tools/utils/v/10.3.2) (from `^10.1.0`, in
15+
`dependencies`)
16+
- Updated dependency [`@whatwg-node/fetch@^0.9.18`
17+
↗︎](https://www.npmjs.com/package/@whatwg-node/fetch/v/0.9.18) (from `^0.9.17`, in
18+
`dependencies`)
19+
- Updated dependency [`@whatwg-node/server@^0.9.40`
20+
↗︎](https://www.npmjs.com/package/@whatwg-node/server/v/0.9.40) (from `^0.9.36`, in
21+
`dependencies`)

packages/graphql-yoga/__tests__/error-masking.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ describe('error masking', () => {
749749
],
750750
});
751751
// in the future this might change as we decide to within our graphql-tools/executor error handler treat DOMException similar to a normal Error
752-
expect(error.mock.calls).toMatchObject([[{ message: 'Unexpected error value: {}' }]]);
752+
expect(error.mock.calls).toMatchObject([[{ message: 'This operation was aborted' }]]);
753753
expect(debug.mock.calls).toEqual([
754754
['Parsing request to extract GraphQL parameters'],
755755
['Processing GraphQL Parameters'],

packages/graphql-yoga/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@
4949
"graphql": "^15.2.0 || ^16.0.0"
5050
},
5151
"dependencies": {
52-
"@envelop/core": "^5.0.0",
53-
"@graphql-tools/executor": "^1.2.5",
54-
"@graphql-tools/schema": "^10.0.0",
55-
"@graphql-tools/utils": "^10.1.0",
52+
"@envelop/core": "^5.0.1",
53+
"@graphql-tools/executor": "^1.3.0",
54+
"@graphql-tools/schema": "^10.0.4",
55+
"@graphql-tools/utils": "^10.3.2",
5656
"@graphql-yoga/logger": "workspace:^",
5757
"@graphql-yoga/subscription": "workspace:^",
58-
"@whatwg-node/fetch": "^0.9.17",
59-
"@whatwg-node/server": "^0.9.36",
58+
"@whatwg-node/fetch": "^0.9.18",
59+
"@whatwg-node/server": "^0.9.40",
6060
"dset": "^3.1.1",
6161
"lru-cache": "^10.0.0",
6262
"tslib": "^2.5.2"

packages/graphql-yoga/src/plugins/types.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
PromiseOrValue,
77
} from '@envelop/core';
88
import { ExecutionResult } from '@graphql-tools/utils';
9-
import { ServerAdapterPlugin } from '@whatwg-node/server';
9+
import { ServerAdapterInitialContext, ServerAdapterPlugin } from '@whatwg-node/server';
1010
import { YogaServer } from '../server.js';
1111
import {
1212
FetchAPI,
@@ -71,7 +71,7 @@ export type OnRequestHook<TServerContext> = (
7171

7272
export interface OnRequestEventPayload<TServerContext> {
7373
request: Request;
74-
serverContext: TServerContext | undefined;
74+
serverContext: TServerContext & ServerAdapterInitialContext;
7575
fetchAPI: FetchAPI;
7676
endResponse(response: Response): void;
7777
url: URL;
@@ -89,7 +89,7 @@ export interface OnRequestParseEventPayload<TServerContext> {
8989
request: Request;
9090
url: URL;
9191
requestParser: RequestParser | undefined;
92-
serverContext: TServerContext;
92+
serverContext: TServerContext & ServerAdapterInitialContext;
9393
setRequestParser: (parser: RequestParser) => void;
9494
}
9595

@@ -143,13 +143,3 @@ export interface OnResultProcessEventPayload {
143143
acceptableMediaTypes: string[];
144144
setResultProcessor(resultProcessor: ResultProcessor, acceptedMediaType: string): void;
145145
}
146-
147-
export type OnResponseHook<TServerContext> = (
148-
payload: OnResponseEventPayload<TServerContext>,
149-
) => PromiseOrValue<void>;
150-
151-
export interface OnResponseEventPayload<TServerContext> {
152-
request: Request;
153-
serverContext: TServerContext | undefined;
154-
response: Response;
155-
}

packages/graphql-yoga/src/server.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
createServerAdapter,
1818
ServerAdapter,
1919
ServerAdapterBaseObject,
20+
ServerAdapterInitialContext,
2021
ServerAdapterRequestHandler,
2122
useCORS,
2223
useErrorHandling,
@@ -454,10 +455,7 @@ export class YogaServer<
454455
request: Request;
455456
batched: boolean;
456457
},
457-
// eslint-disable-next-line @typescript-eslint/ban-types
458-
...args: {} extends TServerContext
459-
? [serverContext?: TServerContext | undefined]
460-
: [serverContext: TServerContext]
458+
serverContext: TServerContext,
461459
) {
462460
try {
463461
let result: ExecutionResult | AsyncIterable<ExecutionResult> | undefined;
@@ -478,7 +476,7 @@ export class YogaServer<
478476

479477
if (result == null) {
480478
const additionalContext =
481-
args[0]?.request === request
479+
serverContext.request === request
482480
? {
483481
params,
484482
}
@@ -487,9 +485,10 @@ export class YogaServer<
487485
params,
488486
};
489487

490-
const initialContext = args[0]
491-
? Object.assign(batched ? Object.create(args[0]) : args[0], additionalContext)
492-
: additionalContext;
488+
const initialContext = Object.assign(
489+
batched ? Object.create(serverContext) : serverContext,
490+
additionalContext,
491+
);
493492

494493
const enveloped = this.getEnveloped(initialContext);
495494

@@ -537,7 +536,7 @@ export class YogaServer<
537536

538537
handle: ServerAdapterRequestHandler<TServerContext> = async (
539538
request: Request,
540-
serverContext: TServerContext,
539+
serverContext: TServerContext & ServerAdapterInitialContext,
541540
) => {
542541
let url = new Proxy({} as URL, {
543542
get: (_target, prop, _receiver) => {
@@ -623,11 +622,12 @@ export type YogaServerInstance<
623622
export function createYoga<
624623
TServerContext extends Record<string, any> = {},
625624
TUserContext extends Record<string, any> = {},
626-
>(options: YogaServerOptions<TServerContext, TUserContext>) {
625+
>(
626+
options: YogaServerOptions<TServerContext, TUserContext>,
627+
): YogaServerInstance<TServerContext, TUserContext> {
627628
const server = new YogaServer<TServerContext, TUserContext>(options);
628629
return createServerAdapter<TServerContext, YogaServer<TServerContext, TUserContext>>(server, {
629630
fetchAPI: server.fetchAPI,
630631
plugins: server['plugins'],
631-
}) as unknown as YogaServerInstance<TServerContext, TUserContext>;
632-
// TODO: Fix in @whatwg-node/server later
632+
});
633633
}

packages/nestjs/src/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ export abstract class AbstractYogaDriver<
135135
: options.logging,
136136
});
137137

138-
this.yoga = yoga as YogaDriverServerInstance<Platform>;
138+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
139+
// @ts-ignore - TODO: fix types
140+
this.yoga = yoga;
139141

140142
app.use(yoga.graphqlEndpoint, (req, res) => yoga(req, res, { req, res }));
141143
}
@@ -159,7 +161,9 @@ export abstract class AbstractYogaDriver<
159161
logging: options.logging == null ? false : options.logging ? app.log : options.logging,
160162
});
161163

162-
this.yoga = yoga as YogaDriverServerInstance<Platform>;
164+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
165+
// @ts-ignore - TODO: fix types
166+
this.yoga = yoga;
163167

164168
app.all(yoga.graphqlEndpoint, async (req, reply) => {
165169
const response = await yoga.handleNodeRequestAndResponse(req, reply, {

packages/plugins/jwt/src/__tests__/jwt.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ describe('jwt plugin', () => {
498498
singingKeyProviders: [createInlineSigningKeyProvider(secret)],
499499
tokenLookupLocations: [extractFromCookie({ name: 'auth' })],
500500
},
501-
[useCookies()],
501+
[useCookies<any>()],
502502
);
503503
const token = buildJWT({ sub: '123' }, { key: secret }, '');
504504
const response = await test.queryWithCookieAuth(token);
@@ -550,7 +550,7 @@ describe('jwt plugin', () => {
550550
}),
551551
],
552552
},
553-
[useCookies()],
553+
[useCookies<any>()],
554554
);
555555
const token = buildJWT({ sub: '123' }, { key: secret }, '');
556556

@@ -571,7 +571,7 @@ describe('jwt plugin', () => {
571571
const createTestServer = (options: JwtPluginOptions, initPlugins: Plugin[] = []) => {
572572
const yoga = createYoga({
573573
schema,
574-
logging: console,
574+
logging: !!process.env.DEBUG,
575575
plugins: [...initPlugins, useJWT(options)],
576576
});
577577

0 commit comments

Comments
 (0)