-
-
Notifications
You must be signed in to change notification settings - Fork 827
/
Copy pathfetch-federation-tests.ts
46 lines (43 loc) · 1.57 KB
/
fetch-federation-tests.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { exists, existsSync, mkdirSync, rmdirSync, writeFileSync } from 'fs';
import { join } from 'path';
const baseUrl = 'http://localhost:4200';
const fixturesPath = join(
__dirname,
'..',
'packages',
'federation',
'test',
'fixtures',
'federation-compatibility',
);
async function main() {
if (existsSync(fixturesPath)) {
rmdirSync(fixturesPath, { recursive: true });
}
const supergraphPathListRes = await fetch(`${baseUrl}/supergraphs`).catch(err => {
console.error(err);
throw new Error(`Make sure the federation compatibility server is up and running`);
});
const supergraphPathList = await supergraphPathListRes.json();
for (const supergraphPath of supergraphPathList) {
if (supergraphPath) {
const supergraphRes = await fetch(supergraphPath);
const supergraphPathParts = supergraphPath.split('/');
const supergraphName = supergraphPathParts[supergraphPathParts.length - 2];
const supergraphSdl = await supergraphRes.text();
const supergraphFixturesDir = join(fixturesPath, supergraphName);
mkdirSync(supergraphFixturesDir, { recursive: true });
writeFileSync(join(supergraphFixturesDir, 'supergraph.graphql'), supergraphSdl);
const testsPath = supergraphPath.replace('/supergraph', '/tests');
const testsRes = await fetch(testsPath);
const testsContent = await testsRes.json();
writeFileSync(
join(supergraphFixturesDir, 'tests.json'),
JSON.stringify(testsContent, null, 2),
);
}
}
}
main()
.then(() => console.log('Done!'))
.catch(err => console.error(err));