From 19b7a879bbe35ffc0b087003d8638b3c5269b1a2 Mon Sep 17 00:00:00 2001 From: enisdenjo Date: Mon, 23 Dec 2024 19:27:29 +0100 Subject: [PATCH] failing test --- .../apollo-link/tests/apollo-link.spec.ts | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/packages/executors/apollo-link/tests/apollo-link.spec.ts b/packages/executors/apollo-link/tests/apollo-link.spec.ts index 9cf46389a97..e14f2af1f6f 100644 --- a/packages/executors/apollo-link/tests/apollo-link.spec.ts +++ b/packages/executors/apollo-link/tests/apollo-link.spec.ts @@ -1,12 +1,14 @@ import { setTimeout } from 'timers/promises'; import { parse } from 'graphql'; -import { createSchema, createYoga } from 'graphql-yoga'; +import { createSchema, createYoga, Repeater } from 'graphql-yoga'; import { ApolloClient, FetchResult, InMemoryCache } from '@apollo/client/core'; import { buildHTTPExecutor } from '@graphql-tools/executor-http'; +import { createDeferred } from '@graphql-tools/utils'; import { testIf } from '../../../testing/utils.js'; import { ExecutorLink } from '../src/index.js'; describe('Apollo Link', () => { + const { promise: waitForPingStop, resolve: pingStop } = createDeferred(); const yoga = createYoga({ logging: false, maskedErrors: false, @@ -21,6 +23,7 @@ describe('Apollo Link', () => { } type Subscription { time: String + ping: String } `, resolvers: { @@ -40,6 +43,13 @@ describe('Apollo Link', () => { }, resolve: str => str, }, + ping: { + subscribe: () => + new Repeater(async (_pull, stop) => { + await stop; + pingStop(); + }), + }, }, }, }), @@ -121,4 +131,20 @@ describe('Apollo Link', () => { readFile: 'Hello World', }); }); + it('should complete subscription even while waiting for events', async () => { + const observable = client.subscribe({ + query: parse(/* GraphQL */ ` + subscription Ping { + ping + } + `), + }); + const sub = observable.subscribe({ + next: () => { + // noop + }, + }); + globalThis.setTimeout(() => sub.unsubscribe(), 0); + await waitForPingStop; + }); });