copykitku/scripts/download-gql-schema.ts
Laura Liberda 20cfde5ea3 Revert "[gitlab] simplify gql schema download"
This reverts commit 40ced41cce.

GitLab removed the SDL files from the docs: baedeb4ee8
2021-02-20 04:11:47 +01:00

45 lines
1.4 KiB
TypeScript

/*
* Copycat. Copyright (C) 2020 selfisekai <laura@selfisekai.rocks> and other contributors.
*
* This is free software, and you are welcome to redistribute it
* under the GNU General Public License 3.0 or later; see the LICENSE file for details,
* or, if the file is unavailable, visit <https://www.gnu.org/licenses/gpl-3.0-standalone.html>.
*/
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!'));