UNPKG

@giraphql/converter

Version:

A converter for generating GiraphQL SchemaBuilder code from GraphQL SDL

30 lines (29 loc) 1.14 kB
import fs from 'fs'; import path from 'path'; import { buildSchema } from 'graphql'; import yargs from 'yargs'; import GiraphQLConverter from './index.js'; export default yargs.command("convert <path>", "convert SDL to GiraphQL", (args) => { args.option("out", { type: "string", description: "path to write output to" }); args.alias("o", "out"); args.option("types", { type: "array", description: "list of types to output" }); args.alias("t", "types"); args.positional("path", { description: "path to SDL file", type: "string" }); }, (argv) => { const inputPath = path.resolve(process.cwd(), argv.path); if (!fs.existsSync(inputPath)) { throw new Error(`Schema not found ${inputPath}`); } const schemaText = fs.readFileSync(inputPath, "utf8"); const converter = new GiraphQLConverter(buildSchema(schemaText), { types: argv.types || null, }); const output = converter.toString(); if (argv.out) { fs.writeFileSync(path.resolve((process.cwd(), argv.out)), output); } else { process.stdout.write(output); } }).argv; //# sourceMappingURL=cli.js.map