UNPKG

graphql-export

Version:
57 lines (56 loc) 1.94 kB
#!/usr/bin/env node "use strict"; exports.__esModule = true; var exporters_1 = require("./exporters"); var chalk = require('chalk'); var clear = require('clear'); var figlet = require('figlet'); var yargs = require('yargs'); console.log(chalk.green(figlet.textSync('graphql-export', { horizontalLayout: 'full' }))); var argv = yargs .option('url', { description: 'the graphql server root url', alias: 'u', type: 'string' }) .option('format', { description: 'The export format', alias: 'f', type: 'string', choices: ['insomnia', 'postman'] }) .option('query-name', { description: 'the name of your root query field', alias: 'q', type: 'string' }) .option('mutation-name', { description: 'the name of your root mutation field', alias: 'm', type: 'string' }) .option('custom-headers', { description: 'Custom headers to pass with the request to the graphql server, should be passed in form "header-name:header-value"', alias: 'H', type: "array", "default": [] }) .demandOption(['url', 'format'], 'Please provide both url and format arguments to work with this tool') .help() .alias('help', 'h') .argv; if (argv['query-name'] == null) { var defaultValue = "RootQueryType"; console.info(chalk.cyan('Argument' + chalk.italic(' query-name ') + 'was not supplied. Using default value: ' + chalk.italic.bgCyan.black(" " + defaultValue + " "))); argv['query-name'] = defaultValue; } if (argv['mutation-name'] == null) { var defaultValue = "RootMutationType"; console.info(chalk.cyan('Argument' + chalk.italic(' mutation-name ') + 'was not supplied. Using default value: ' + chalk.italic.bgCyan.black(" " + defaultValue + " "))); argv['mutation-name'] = defaultValue; } exporters_1.convert(argv['url'], argv['format'], argv['query-name'], argv['mutation-name'], argv['custom-headers']);