Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 68d164d

Browse files
committedApr 17, 2024
compose supergraph once
1 parent 21354de commit 68d164d

File tree

1 file changed

+13
-21
lines changed

1 file changed

+13
-21
lines changed
 

‎e2e/federation-example/federation-example.test.ts

+13-21
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ import { createTenv, Service } from '@e2e/tenv';
44
const { fs, spawn, service, serve } = createTenv(__dirname);
55

66
let services!: Service[];
7-
const supergraphConfig = { subgraphs: {} };
7+
let supergraph!: string;
88
beforeAll(async () => {
99
services = [
1010
await service('accounts'),
1111
await service('inventory'),
1212
await service('products'),
1313
await service('reviews'),
1414
];
15+
16+
const supergraphConfig = { subgraphs: {} };
1517
for (const service of services) {
1618
supergraphConfig.subgraphs[service.name] = {
1719
routing_url: `http://0.0.0.0:${service.port}/graphql`,
@@ -20,11 +22,7 @@ beforeAll(async () => {
2022
},
2123
};
2224
}
23-
});
2425

25-
async function composeSupergraph(
26-
maskServicePorts?: boolean,
27-
): Promise<[result: string, path: string]> {
2826
const supergraphConfigFile = await fs.tempfile('supergraph.json');
2927
await fs.write(supergraphConfigFile, JSON.stringify(supergraphConfig));
3028

@@ -33,22 +31,15 @@ async function composeSupergraph(
3331
);
3432
await waitForExit;
3533

36-
let result = proc.getStd('out');
37-
if (maskServicePorts) {
38-
for (const service of services) {
39-
result = result.replaceAll(service.port.toString(), `<${service.name}>`);
40-
}
41-
}
42-
43-
const supergraphFile = await fs.tempfile('supergraph.graphql');
44-
await fs.write(supergraphFile, result);
45-
46-
return [result, supergraphFile];
47-
}
34+
supergraph = proc.getStd('out');
35+
});
4836

4937
it('should compose supergraph with rover', async () => {
50-
const [result] = await composeSupergraph(true);
51-
expect(result).toMatchSnapshot();
38+
let maskedSupergraph = supergraph;
39+
for (const service of services) {
40+
maskedSupergraph = maskedSupergraph.replaceAll(service.port.toString(), `<${service.name}>`);
41+
}
42+
expect(maskedSupergraph).toMatchSnapshot();
5243
});
5344

5445
it.concurrent.each([
@@ -116,7 +107,8 @@ it.concurrent.each([
116107
`,
117108
},
118109
])('should execute $name', async ({ query }) => {
119-
const [, supergraph] = await composeSupergraph();
120-
const { execute } = await serve({ supergraph });
110+
const supergraphFile = await fs.tempfile('supergraph.graphql');
111+
await fs.write(supergraphFile, supergraph);
112+
const { execute } = await serve({ supergraph: supergraphFile });
121113
await expect(execute({ query })).resolves.toMatchSnapshot();
122114
});

0 commit comments

Comments
 (0)
Please sign in to comment.