UNPKG

graphene-codegen

Version:

Generate Graphene Python boilerplate from a GraphQL schema.

30 lines (29 loc) 1.16 kB
#!/usr/bin/env node "use strict"; 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 commander_1 = __importDefault(require("commander")); const generatePythonStr_1 = __importDefault(require("./generatePythonStr")); commander_1.default .option("-s, --schema <path>", "the path to your schema file") .option("-o, --out <path>", "the path to generated python code [gen.py]") .parse(process.argv); if (!commander_1.default.schema) { throw new Error("No schema file specified."); } const schemaDocument = fs_1.default.readFileSync(commander_1.default.schema); const schemaString = schemaDocument.toString(); const outStr = generatePythonStr_1.default(schemaString); let outFilePath = "./gen.py"; if (typeof commander_1.default.out === "string") { outFilePath = commander_1.default.out; } fs_1.default.writeFile(outFilePath, outStr, err => { if (err) throw err; else console.log(`Wrote file at ${outFilePath}`); });