From 856379fc446882f2fbff79f632c15f34229f856c Mon Sep 17 00:00:00 2001 From: Jason Kuhrt Date: Wed, 11 Dec 2024 08:46:47 -0500 Subject: [PATCH 1/5] chore: fastify example standard fetch --- .../__integration-tests__/fastify.spec.ts | 13 +++++------ examples/fastify/package.json | 1 - pnpm-lock.yaml | 22 +++++++++++++++---- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/examples/fastify/__integration-tests__/fastify.spec.ts b/examples/fastify/__integration-tests__/fastify.spec.ts index 1a0ac1a738..a6438f325a 100644 --- a/examples/fastify/__integration-tests__/fastify.spec.ts +++ b/examples/fastify/__integration-tests__/fastify.spec.ts @@ -1,6 +1,5 @@ import request from 'supertest'; import { createDeferred } from '@graphql-tools/utils'; -import { fetch } from '@whatwg-node/fetch'; import { eventStream } from '../../../packages/graphql-yoga/__tests__/utilities.js'; import { buildApp } from '../src/app.js'; @@ -300,9 +299,9 @@ data" await slowFieldResolverInvoked.promise; abortController.abort(); - await expect(response$).rejects.toMatchInlineSnapshot( - `[AbortError: The operation was aborted]`, - ); + const result = (await response$.catch(e => e)) as DOMException; + expect(result.message).toMatchInlineSnapshot(`"This operation was aborted"`); + expect(result instanceof DOMException).toBe(true); await slowFieldResolverCanceled.promise; } finally { app.log.info = info; @@ -349,9 +348,9 @@ data" const next = await iterator.next(); expect(next.value).toEqual({ data: { countdown: 10 } }); abortController.abort(); - await expect(iterator.next()).rejects.toMatchInlineSnapshot( - `[AbortError: The operation was aborted]`, - ); + const result = (await iterator.next().catch(e => e)) as DOMException; + expect(result.message).toMatchInlineSnapshot(`"This operation was aborted"`); + expect(result instanceof DOMException).toBe(true); await cancelationIsLoggedPromise.promise; } finally { app.log.info = info; diff --git a/examples/fastify/package.json b/examples/fastify/package.json index 837766a893..c3e1ace152 100644 --- a/examples/fastify/package.json +++ b/examples/fastify/package.json @@ -7,7 +7,6 @@ "start": "ts-node src/index.ts" }, "dependencies": { - "@whatwg-node/fetch": "^0.10.1", "fastify": "5.1.0", "graphql-yoga": "workspace:*", "pino-pretty": "13.0.0" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3c24acfdbf..1dd60df6c9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -494,9 +494,6 @@ importers: examples/fastify: dependencies: - '@whatwg-node/fetch': - specifier: ^0.10.1 - version: 0.10.1 fastify: specifier: 5.1.0 version: 5.1.0 @@ -24201,6 +24198,23 @@ snapshots: '@swc/core-win32-x64-msvc@1.10.1': optional: true + '@swc/core@1.10.1': + dependencies: + '@swc/counter': 0.1.3 + '@swc/types': 0.1.17 + optionalDependencies: + '@swc/core-darwin-arm64': 1.10.1 + '@swc/core-darwin-x64': 1.10.1 + '@swc/core-linux-arm-gnueabihf': 1.10.1 + '@swc/core-linux-arm64-gnu': 1.10.1 + '@swc/core-linux-arm64-musl': 1.10.1 + '@swc/core-linux-x64-gnu': 1.10.1 + '@swc/core-linux-x64-musl': 1.10.1 + '@swc/core-win32-arm64-msvc': 1.10.1 + '@swc/core-win32-ia32-msvc': 1.10.1 + '@swc/core-win32-x64-msvc': 1.10.1 + optional: true + '@swc/core@1.10.1(@swc/helpers@0.5.15)': dependencies: '@swc/counter': 0.1.3 @@ -35366,7 +35380,7 @@ snapshots: v8-compile-cache-lib: 3.0.1 yn: 3.1.1 optionalDependencies: - '@swc/core': 1.10.1(@swc/helpers@0.5.15) + '@swc/core': 1.10.1 ts-node@10.9.2(@swc/core@1.10.1)(@types/node@22.10.1)(typescript@5.7.2): dependencies: From e01e46e552babb10e97320e95c917e6cf6970074 Mon Sep 17 00:00:00 2001 From: Jason Kuhrt Date: Wed, 11 Dec 2024 09:36:43 -0500 Subject: [PATCH 2/5] no success ambiguity --- .../fastify/__integration-tests__/fastify.spec.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/fastify/__integration-tests__/fastify.spec.ts b/examples/fastify/__integration-tests__/fastify.spec.ts index a6438f325a..caa2c571da 100644 --- a/examples/fastify/__integration-tests__/fastify.spec.ts +++ b/examples/fastify/__integration-tests__/fastify.spec.ts @@ -299,9 +299,9 @@ data" await slowFieldResolverInvoked.promise; abortController.abort(); - const result = (await response$.catch(e => e)) as DOMException; - expect(result.message).toMatchInlineSnapshot(`"This operation was aborted"`); - expect(result instanceof DOMException).toBe(true); + const { _: error } = (await response$.catch(_ => ({ _ }))) as { _: DOMException }; + expect(error.message).toMatchInlineSnapshot(`"This operation was aborted"`); + expect(error instanceof DOMException).toBe(true); await slowFieldResolverCanceled.promise; } finally { app.log.info = info; @@ -348,9 +348,9 @@ data" const next = await iterator.next(); expect(next.value).toEqual({ data: { countdown: 10 } }); abortController.abort(); - const result = (await iterator.next().catch(e => e)) as DOMException; - expect(result.message).toMatchInlineSnapshot(`"This operation was aborted"`); - expect(result instanceof DOMException).toBe(true); + const { _: error } = (await iterator.next().catch(_ => ({ _ }))) as { _: DOMException }; + expect(error.message).toMatchInlineSnapshot(`"This operation was aborted"`); + expect(error instanceof DOMException).toBe(true); await cancelationIsLoggedPromise.promise; } finally { app.log.info = info; From 55f0f1ba3971f9fd25f4e07606d4b908f9120fa6 Mon Sep 17 00:00:00 2001 From: Jason Kuhrt Date: Wed, 11 Dec 2024 09:51:09 -0500 Subject: [PATCH 3/5] refactor --- examples/fastify/__integration-tests__/fastify.spec.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/fastify/__integration-tests__/fastify.spec.ts b/examples/fastify/__integration-tests__/fastify.spec.ts index caa2c571da..81b2ce6d40 100644 --- a/examples/fastify/__integration-tests__/fastify.spec.ts +++ b/examples/fastify/__integration-tests__/fastify.spec.ts @@ -299,9 +299,9 @@ data" await slowFieldResolverInvoked.promise; abortController.abort(); - const { _: error } = (await response$.catch(_ => ({ _ }))) as { _: DOMException }; + await expect(response$).rejects.toMatchInlineSnapshot(`DOMException {}`); + const error = (await response$.catch(e => e)) as DOMException; expect(error.message).toMatchInlineSnapshot(`"This operation was aborted"`); - expect(error instanceof DOMException).toBe(true); await slowFieldResolverCanceled.promise; } finally { app.log.info = info; @@ -348,9 +348,10 @@ data" const next = await iterator.next(); expect(next.value).toEqual({ data: { countdown: 10 } }); abortController.abort(); - const { _: error } = (await iterator.next().catch(_ => ({ _ }))) as { _: DOMException }; + const promisedResult = iterator.next(); + await expect(promisedResult).rejects.toMatchInlineSnapshot(`DOMException {}`); + const error = (await promisedResult.catch(e => e)) as DOMException; expect(error.message).toMatchInlineSnapshot(`"This operation was aborted"`); - expect(error instanceof DOMException).toBe(true); await cancelationIsLoggedPromise.promise; } finally { app.log.info = info; From 91233388873b9b3d9efe1fec9e26aeadbf9ab4fb Mon Sep 17 00:00:00 2001 From: Jason Kuhrt Date: Wed, 11 Dec 2024 09:55:01 -0500 Subject: [PATCH 4/5] feedback --- .../fastify/__integration-tests__/fastify.spec.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/fastify/__integration-tests__/fastify.spec.ts b/examples/fastify/__integration-tests__/fastify.spec.ts index 81b2ce6d40..b644d8d8b3 100644 --- a/examples/fastify/__integration-tests__/fastify.spec.ts +++ b/examples/fastify/__integration-tests__/fastify.spec.ts @@ -299,9 +299,9 @@ data" await slowFieldResolverInvoked.promise; abortController.abort(); - await expect(response$).rejects.toMatchInlineSnapshot(`DOMException {}`); - const error = (await response$.catch(e => e)) as DOMException; - expect(error.message).toMatchInlineSnapshot(`"This operation was aborted"`); + await expect(response$).rejects.toMatchObject({ + message: 'This operation was aborted', + }); await slowFieldResolverCanceled.promise; } finally { app.log.info = info; @@ -349,9 +349,9 @@ data" expect(next.value).toEqual({ data: { countdown: 10 } }); abortController.abort(); const promisedResult = iterator.next(); - await expect(promisedResult).rejects.toMatchInlineSnapshot(`DOMException {}`); - const error = (await promisedResult.catch(e => e)) as DOMException; - expect(error.message).toMatchInlineSnapshot(`"This operation was aborted"`); + await expect(promisedResult).rejects.toMatchObject({ + message: 'This operation was aborted', + }); await cancelationIsLoggedPromise.promise; } finally { app.log.info = info; From c99037f485420aaa3894622a7c0cab6a537e52ae Mon Sep 17 00:00:00 2001 From: Jason Kuhrt Date: Wed, 11 Dec 2024 09:57:33 -0500 Subject: [PATCH 5/5] final --- .../fastify/__integration-tests__/fastify.spec.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/examples/fastify/__integration-tests__/fastify.spec.ts b/examples/fastify/__integration-tests__/fastify.spec.ts index b644d8d8b3..19f18df480 100644 --- a/examples/fastify/__integration-tests__/fastify.spec.ts +++ b/examples/fastify/__integration-tests__/fastify.spec.ts @@ -280,7 +280,7 @@ data" try { const abortController = new AbortController(); - const response$ = fetch(`${address}/graphql`, { + const response = fetch(`${address}/graphql`, { method: 'POST', headers: { 'content-type': 'application/json', @@ -299,7 +299,7 @@ data" await slowFieldResolverInvoked.promise; abortController.abort(); - await expect(response$).rejects.toMatchObject({ + await expect(response).rejects.toMatchObject({ message: 'This operation was aborted', }); await slowFieldResolverCanceled.promise; @@ -344,12 +344,11 @@ data" signal: abortController.signal, }); - const iterator = eventStream(response.body!); - const next = await iterator.next(); - expect(next.value).toEqual({ data: { countdown: 10 } }); + const bodyIterator = eventStream(response.body!); + const bodyIteratorNext = await bodyIterator.next(); + expect(bodyIteratorNext.value).toEqual({ data: { countdown: 10 } }); abortController.abort(); - const promisedResult = iterator.next(); - await expect(promisedResult).rejects.toMatchObject({ + await expect(bodyIterator.next()).rejects.toMatchObject({ message: 'This operation was aborted', }); await cancelationIsLoggedPromise.promise;