/* * Copycat. Copyright (C) 2020 selfisekai 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 . */ 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!'));