Skip to content

Commit

Permalink
Reproduction #136
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed Dec 3, 2024
1 parent 1d6fa42 commit b98f2a8
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 0 deletions.
21 changes: 21 additions & 0 deletions e2e/reproduction-136/mesh.config.ts
Original file line number Diff line number Diff line change
@@ -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,
}),
],
},
],
});
10 changes: 10 additions & 0 deletions e2e/reproduction-136/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
64 changes: 64 additions & 0 deletions e2e/reproduction-136/reproduction-136.e2e.ts
Original file line number Diff line number Diff line change
@@ -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:",
]
`);
});
38 changes: 38 additions & 0 deletions e2e/reproduction-136/services/my-subgraph/index.ts
Original file line number Diff line number Diff line change
@@ -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`);
});
7 changes: 7 additions & 0 deletions e2e/reproduction-136/services/my-subgraph/schema.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type Query {
hello: String
}

type Subscription {
countdown(from: Int!): Int!
}
11 changes: 11 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit b98f2a8

Please sign in to comment.