copykitku/scripts/download-gql-schema.ts
2020-08-05 23:33:36 +02:00

37 lines
1 KiB
TypeScript

import { getIntrospectionQuery } from 'graphql';
import got, { Options as GotOptions } from 'got';
import { createWriteStream } from 'fs';
import path from 'path';
import { pipeline as pipelineUnpromised } from 'stream';
import { promisify } from 'util';
const pipeline = promisify(pipelineUnpromised);
const introspection = {
method: 'POST' as 'POST',
body: JSON.stringify({ query: getIntrospectionQuery() }),
headers: {
'Content-Type': 'application/json',
},
};
const schemas: [
string, // vendor
'graphql' | 'json', // filetype
[string | URL, GotOptions & { isStream?: true | undefined }],
][] = [
['github', 'graphql', ['https://docs.github.com/public/schema.docs.graphql', {}]],
['gitlab', 'json', ['https://gitlab.com/api/graphql', introspection]],
];
Promise.all(
schemas.map(([vendor, filetype, downloadConfig]) =>
pipeline(
got.stream(...downloadConfig),
createWriteStream(
path.resolve(__dirname, '..', 'src', 'vendor', vendor, `schema.${filetype}`),
),
),
),
).then(() => console.log('done!'));