diff --git a/e2e/reproduction-136/mesh.config.ts b/e2e/reproduction-136/mesh.config.ts new file mode 100644 index 00000000..06d7d375 --- /dev/null +++ b/e2e/reproduction-136/mesh.config.ts @@ -0,0 +1,21 @@ +import { createPrefixTransform, defineConfig, loadGraphQLHTTPSubgraph } from '@graphql-mesh/compose-cli'; +import { Opts } from '@internal/testing'; + +const opts = Opts(process.argv); + +export const composeConfig = defineConfig({ + subgraphs: [ + { + sourceHandler: loadGraphQLHTTPSubgraph('my-subgraph', { + endpoint: `http://localhost:${opts.getServicePort('my-subgraph')}/graphql`, + source: './services/my-subgraph/schema.graphql', + }), + transforms: [ + createPrefixTransform({ + value: 'test_', + includeRootOperations: true, + }), + ], + }, + ], +}); diff --git a/e2e/reproduction-136/package.json b/e2e/reproduction-136/package.json new file mode 100644 index 00000000..96c1dbfb --- /dev/null +++ b/e2e/reproduction-136/package.json @@ -0,0 +1,10 @@ +{ + "name": "@e2e/reproduction-136", + "private": true, + "dependencies": { + "@graphql-mesh/compose-cli": "^1.2.0", + "graphql": "16.9.0", + "graphql-yoga": "^5.10.4", + "tslib": "^2.8.0" + } +} diff --git a/e2e/reproduction-136/reproduction-136.e2e.ts b/e2e/reproduction-136/reproduction-136.e2e.ts new file mode 100644 index 00000000..70f512c6 --- /dev/null +++ b/e2e/reproduction-136/reproduction-136.e2e.ts @@ -0,0 +1,64 @@ +import { createTenv } from '@internal/e2e'; +import { getLocalhost } from '@internal/testing'; +import { expect, it } from 'vitest'; +import { fetch} from '@whatwg-node/fetch'; +import { ExecutionResult } from 'graphql'; + +const { gateway, service } = createTenv(__dirname); + +it('reproduction-136', async () => { + const { port } = await gateway({ + supergraph: { + with: 'mesh', + services: [ + await service('my-subgraph') + ] + }, + }); + const hostname = await getLocalhost(port); + const res = await fetch(`${hostname}:${port}/graphql`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + query: ` + subscription { + test_countdown(from: 3) + } + `, + }), + }) + const results: string[] = []; + for await (const result of res.body) { + results.push(Buffer.from(result).toString('utf-8').trim()); + } + expect(results).toMatchInlineSnapshot(` + [ + ":", + ":", + ":", + ":", + "event: next + data: {"data":{"test_countdown":3}}", + ":", + ":", + ":", + "event: next + data: {"data":{"test_countdown":2}}", + ":", + ":", + ":", + "event: next + data: {"data":{"test_countdown":1}}", + ":", + ":", + ":", + ":", + "event: next + data: {"data":{"test_countdown":0}}", + "event: complete + data:", + ] + `); +}); diff --git a/e2e/reproduction-136/services/my-subgraph/index.ts b/e2e/reproduction-136/services/my-subgraph/index.ts new file mode 100644 index 00000000..d8e77b4a --- /dev/null +++ b/e2e/reproduction-136/services/my-subgraph/index.ts @@ -0,0 +1,38 @@ +import { createServer } from 'node:http'; +import { setTimeout as setTimeout$ } from 'node:timers/promises'; + +import { createSchema, createYoga } from 'graphql-yoga'; +import { Opts } from '@internal/testing'; +import { readFileSync } from 'node:fs'; +import { join } from 'node:path'; + +// Provide your schema +const yoga = createYoga({ + schema: createSchema({ + typeDefs: readFileSync(join(__dirname, './schema.graphql'), 'utf-8'), + resolvers: { + Query: { + hello: () => 'world', + }, + Subscription: { + countdown: { + // This will return the value on every 1 sec until it reaches 0 + async *subscribe(_, { from }) { + for (let i = from; i >= 0; i--) { + await setTimeout$(1000); + yield { countdown: i }; + } + }, + }, + }, + }, + }), +}); + +const server = createServer(yoga); +const opts = Opts(process.argv); +const port = opts.getServicePort('my-subgraph'); +server.listen( + port, () => { + console.info(`Server is running on http://localhost:${port}/graphql`); +}); diff --git a/e2e/reproduction-136/services/my-subgraph/schema.graphql b/e2e/reproduction-136/services/my-subgraph/schema.graphql new file mode 100644 index 00000000..d8b7e74e --- /dev/null +++ b/e2e/reproduction-136/services/my-subgraph/schema.graphql @@ -0,0 +1,7 @@ +type Query { + hello: String +} + +type Subscription { + countdown(from: Int!): Int! +} diff --git a/yarn.lock b/yarn.lock index fa76ea92..a99962aa 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2705,6 +2705,17 @@ __metadata: languageName: unknown linkType: soft +"@e2e/reproduction-136@workspace:e2e/reproduction-136": + version: 0.0.0-use.local + resolution: "@e2e/reproduction-136@workspace:e2e/reproduction-136" + dependencies: + "@graphql-mesh/compose-cli": "npm:^1.2.0" + graphql: "npm:16.9.0" + graphql-yoga: "npm:^5.10.4" + tslib: "npm:^2.8.0" + languageName: unknown + linkType: soft + "@e2e/subscriptions-cancellation@workspace:e2e/subscriptions-cancellation": version: 0.0.0-use.local resolution: "@e2e/subscriptions-cancellation@workspace:e2e/subscriptions-cancellation"