@giraphql/converter
Version:
A converter for generating GiraphQL SchemaBuilder code from GraphQL SDL
34 lines • 1.5 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const graphql_1 = require("graphql");
const yargs_1 = __importDefault(require("yargs"));
const _1 = __importDefault(require("."));
exports.default = yargs_1.default.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_1.default.resolve(process.cwd(), argv.path);
if (!fs_1.default.existsSync(inputPath)) {
throw new Error(`Schema not found ${inputPath}`);
}
const schemaText = fs_1.default.readFileSync(inputPath, 'utf8');
const converter = new _1.default((0, graphql_1.buildSchema)(schemaText), {
types: argv.types || null,
});
const output = converter.toString();
if (argv.out) {
fs_1.default.writeFileSync(path_1.default.resolve((process.cwd(), argv.out)), output);
}
else {
process.stdout.write(output);
}
}).argv;
//# sourceMappingURL=cli.js.map