From 79ed916c60814fcaf5dfda0859f6c64dda4a0eb2 Mon Sep 17 00:00:00 2001 From: enisdenjo Date: Wed, 16 Oct 2024 19:32:34 +0200 Subject: [PATCH] fix types --- internal/testing/package.json | 3 ++- internal/testing/src/createDisposableServer.ts | 18 ++++++++++++++---- .../runtime/tests/upstreamCancellation.spec.ts | 2 +- yarn.lock | 3 ++- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/internal/testing/package.json b/internal/testing/package.json index a2e449250..20e11b569 100644 --- a/internal/testing/package.json +++ b/internal/testing/package.json @@ -3,6 +3,7 @@ "private": true, "devDependencies": { "@types/node": "^22.7.5", - "@whatwg-node/disposablestack": "^0.0.5" + "@whatwg-node/disposablestack": "^0.0.5", + "@whatwg-node/server": "^0.9.49" } } diff --git a/internal/testing/src/createDisposableServer.ts b/internal/testing/src/createDisposableServer.ts index d749a3271..307d595fb 100644 --- a/internal/testing/src/createDisposableServer.ts +++ b/internal/testing/src/createDisposableServer.ts @@ -1,7 +1,11 @@ +import type { Server } from 'node:http'; import { createServer } from 'node:http'; -import type { RequestListener, Server } from 'node:http'; import type { AddressInfo, Socket } from 'node:net'; import { DisposableSymbols } from '@whatwg-node/disposablestack'; +import type { + ServerAdapter, + ServerAdapterBaseObject, +} from '@whatwg-node/server'; export interface DisposableServerOpts { port?: number; @@ -13,11 +17,17 @@ export interface DisposableServer { server: Server; } -export async function createDisposableServer( - requestListener?: RequestListener, +export async function createDisposableServer< + TServerContext, + TBaseObject extends ServerAdapterBaseObject, +>( + adapter: ServerAdapter, opts?: DisposableServerOpts, ): Promise { - const server = createServer(requestListener); + const server = createServer( + // @ts-expect-error TODO: type 'IncomingMessage' is not assignable to type 'NodeRequest' when using exactOptionalPropertyTypes + adapter, + ); const port = opts?.port || 0; await new Promise((resolve, reject) => { server.once('error', (err) => reject(err)); diff --git a/packages/runtime/tests/upstreamCancellation.spec.ts b/packages/runtime/tests/upstreamCancellation.spec.ts index a540ab39a..f55dc59e6 100644 --- a/packages/runtime/tests/upstreamCancellation.spec.ts +++ b/packages/runtime/tests/upstreamCancellation.spec.ts @@ -24,7 +24,7 @@ describe('Upstream Cancellation', () => { await createDisposableServer(dataSourceAdapter); const upstreamGraphQL = createYoga({ logging: false, - schema: createSchema({ + schema: createSchema<{}>({ typeDefs: /* GraphQL */ ` type Query { hello: String diff --git a/yarn.lock b/yarn.lock index e901c2d45..38ef105b0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1895,6 +1895,7 @@ __metadata: dependencies: "@types/node": "npm:^22.7.5" "@whatwg-node/disposablestack": "npm:^0.0.5" + "@whatwg-node/server": "npm:^0.9.49" languageName: unknown linkType: soft @@ -4311,7 +4312,7 @@ __metadata: languageName: node linkType: hard -"@whatwg-node/server@npm:^0.9.44, @whatwg-node/server@npm:^0.9.46": +"@whatwg-node/server@npm:^0.9.44, @whatwg-node/server@npm:^0.9.46, @whatwg-node/server@npm:^0.9.49": version: 0.9.49 resolution: "@whatwg-node/server@npm:0.9.49" dependencies: