Skip to content

Commit

Permalink
Add E2E test
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed Jan 8, 2025
1 parent 66c8c6d commit 0d9f638
Show file tree
Hide file tree
Showing 7 changed files with 172 additions and 3 deletions.
12 changes: 12 additions & 0 deletions e2e/polling/gateway.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import fs from 'fs';
import { defineConfig } from '@graphql-hive/gateway';

const SUPERGRAPH_PATH = process.env['SUPERGRAPH_PATH'] || 'supergraph.graphql';

export const gatewayConfig = defineConfig({
supergraph: async (): Promise<string> => {
console.log(`[${new Date().toISOString()}]`, 'Reading ' + SUPERGRAPH_PATH);
return fs.promises.readFile(SUPERGRAPH_PATH, 'utf8');
},
pollingInterval: 5_000,
});
22 changes: 22 additions & 0 deletions e2e/polling/mesh.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {
defineConfig,
loadGraphQLHTTPSubgraph,
} from '@graphql-mesh/compose-cli';
import { Opts } from '@internal/testing';

const opts = Opts(process.argv);
const SERVICE_PORT = opts.getServicePort('Graph');

export const composeConfig = defineConfig({
subgraphs: [
{
sourceHandler: loadGraphQLHTTPSubgraph('Graph', {
endpoint: `http://localhost:${SERVICE_PORT}/graphql`,
source: './services/Graph.graphql',
operationHeaders: {
Authorization: "{context.headers['authorization']}",
},
}),
},
],
});
9 changes: 9 additions & 0 deletions e2e/polling/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "@e2e/polling",
"private": true,
"dependencies": {
"@graphql-mesh/compose-cli": "^1.2.13",
"express-graphql": "^0.12.0",
"graphql": "^16.10.0"
}
}
29 changes: 29 additions & 0 deletions e2e/polling/polling.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { createTenv } from "@internal/e2e";
import { describe, expect, it } from "vitest";


describe("Polling", async () => {
const { service, gateway } = createTenv(__dirname);
const gw = await gateway({
supergraph: {
with: 'mesh',
services: [
await service('Graph')
]
}
})
it('should not break the long running query while polling and schema remaining the same', async () => {
const res = await gw.execute({
query: /* GraphQL */ `
query {
hello
}
`
});
expect(res).toMatchObject({
data: {
hello: 'Hello world!'
}
});
}, 30_000);
})
3 changes: 3 additions & 0 deletions e2e/polling/services/Graph.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
type Query {
hello: String
}
36 changes: 36 additions & 0 deletions e2e/polling/services/Graph.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import fs from 'fs';
import path from 'path';
import express from 'express';
import { graphqlHTTP } from 'express-graphql';
import { buildSchema } from 'graphql';
import { Opts } from '@internal/testing';

const app = express();
const opts = Opts(process.argv);
const port = opts.getServicePort('Graph');

const schemaPath = path.join(__dirname, 'Graph.graphql');
const schemaContent = fs.readFileSync(schemaPath, 'utf8');

const root = {
hello: () => {
return new Promise((resolve) => {
setTimeout(() => {
resolve('Hello world!');
}, 20_000);
});
},
};

app.use(
'/graphql',
graphqlHTTP({
schema: buildSchema(schemaContent),
rootValue: root,
graphiql: true,
}),
);

app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}/graphql`);
});
64 changes: 61 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2612,6 +2612,16 @@ __metadata:
languageName: unknown
linkType: soft

"@e2e/polling@workspace:e2e/polling":
version: 0.0.0-use.local
resolution: "@e2e/polling@workspace:e2e/polling"
dependencies:
"@graphql-mesh/compose-cli": "npm:^1.2.13"
express-graphql: "npm:^0.12.0"
graphql: "npm:^16.10.0"
languageName: unknown
linkType: soft

"@e2e/programmatic-batching-example@workspace:e2e/programmatic-batching":
version: 0.0.0-use.local
resolution: "@e2e/programmatic-batching-example@workspace:e2e/programmatic-batching"
Expand Down Expand Up @@ -7622,7 +7632,7 @@ __metadata:
languageName: node
linkType: hard

"accepts@npm:~1.3.8":
"accepts@npm:^1.3.7, accepts@npm:~1.3.8":
version: 1.3.8
resolution: "accepts@npm:1.3.8"
dependencies:
Expand Down Expand Up @@ -8952,7 +8962,7 @@ __metadata:
languageName: node
linkType: hard

"content-type@npm:~1.0.4, content-type@npm:~1.0.5":
"content-type@npm:^1.0.4, content-type@npm:~1.0.4, content-type@npm:~1.0.5":
version: 1.0.5
resolution: "content-type@npm:1.0.5"
checksum: 10c0/b76ebed15c000aee4678c3707e0860cb6abd4e680a598c0a26e17f0bfae723ec9cc2802f0ff1bc6e4d80603719010431d2231018373d4dde10f9ccff9dadf5af
Expand Down Expand Up @@ -9315,6 +9325,13 @@ __metadata:
languageName: node
linkType: hard

"depd@npm:~1.1.2":
version: 1.1.2
resolution: "depd@npm:1.1.2"
checksum: 10c0/acb24aaf936ef9a227b6be6d495f0d2eb20108a9a6ad40585c5bda1a897031512fef6484e4fdbb80bd249fdaa82841fa1039f416ece03188e677ba11bcfda249
languageName: node
linkType: hard

"dependency-graph@npm:1.0.0":
version: 1.0.0
resolution: "dependency-graph@npm:1.0.0"
Expand Down Expand Up @@ -10213,6 +10230,20 @@ __metadata:
languageName: node
linkType: hard

"express-graphql@npm:^0.12.0":
version: 0.12.0
resolution: "express-graphql@npm:0.12.0"
dependencies:
accepts: "npm:^1.3.7"
content-type: "npm:^1.0.4"
http-errors: "npm:1.8.0"
raw-body: "npm:^2.4.1"
peerDependencies:
graphql: ^14.7.0 || ^15.3.0
checksum: 10c0/5211cc46e8a34776611bcbb40abd445e8e40d6b415099cb0be22107b8fdc501a2d101f2e8b5316c43c6e2538f2858c98e59b17ca57f1253004ee96d40f55eefd
languageName: node
linkType: hard

"express@npm:^4.21.1":
version: 4.21.2
resolution: "express@npm:4.21.2"
Expand Down Expand Up @@ -11385,6 +11416,19 @@ __metadata:
languageName: node
linkType: hard

"http-errors@npm:1.8.0":
version: 1.8.0
resolution: "http-errors@npm:1.8.0"
dependencies:
depd: "npm:~1.1.2"
inherits: "npm:2.0.4"
setprototypeof: "npm:1.2.0"
statuses: "npm:>= 1.5.0 < 2"
toidentifier: "npm:1.0.0"
checksum: 10c0/2deb37be07a858370a5c9f150de0e8a14e10410a46aeed2614e9e96ecc5f88e6d79b2b278b6a968635ff0d01142e84131db2afb07504adb73a3e9340acdbd70c
languageName: node
linkType: hard

"http-errors@npm:2.0.0":
version: 2.0.0
resolution: "http-errors@npm:2.0.0"
Expand Down Expand Up @@ -14942,7 +14986,7 @@ __metadata:
languageName: node
linkType: hard

"raw-body@npm:2.5.2":
"raw-body@npm:2.5.2, raw-body@npm:^2.4.1":
version: 2.5.2
resolution: "raw-body@npm:2.5.2"
dependencies:
Expand Down Expand Up @@ -16043,6 +16087,13 @@ __metadata:
languageName: node
linkType: hard

"statuses@npm:>= 1.5.0 < 2":
version: 1.5.0
resolution: "statuses@npm:1.5.0"
checksum: 10c0/e433900956357b3efd79b1c547da4d291799ac836960c016d10a98f6a810b1b5c0dcc13b5a7aa609a58239b5190e1ea176ad9221c2157d2fd1c747393e6b2940
languageName: node
linkType: hard

"std-env@npm:^3.8.0":
version: 3.8.0
resolution: "std-env@npm:3.8.0"
Expand Down Expand Up @@ -16529,6 +16580,13 @@ __metadata:
languageName: node
linkType: hard

"toidentifier@npm:1.0.0":
version: 1.0.0
resolution: "toidentifier@npm:1.0.0"
checksum: 10c0/27a37b8b21126e7216d40c02f410065b1de35b0f844368d0ccaabba7987595703006d45e5c094b086220cbbc5864d4b99766b460110e4bc15b9db574c5c58be2
languageName: node
linkType: hard

"toidentifier@npm:1.0.1":
version: 1.0.1
resolution: "toidentifier@npm:1.0.1"
Expand Down

0 comments on commit 0d9f638

Please sign in to comment.