Comparing version 0.0.4 to 0.0.5
18
cli.js
@@ -10,19 +10,25 @@ #! /usr/bin/env node | ||
.usage([ | ||
'<schema.txt> [options]', | ||
'<schema.txt | http://example.com/graphql> [options]', | ||
'', | ||
' Given a file with a GraphQL schema in the schema language or the URL of a GraphQL endpoint, generates the introspected schema and / or the schema AST as JSON files.', | ||
' If a URL of a GraphQL endpoint is provided, generating the remote schema in the schema language is also supported.', | ||
' By default, only the introspected schema is generated.', | ||
' To select which files to generate use the "-i" and "-o" options.' | ||
' To select which files to generate use the "-i", "-a" and "-t" options.' | ||
].join('\n')) | ||
.option('-i --generate-introspected-schema', 'generates the introspected schema') | ||
.option('-a --generate-schema-ast', 'generates the schema AST') | ||
.option('-t --generate-schema-language', 'generates the schema in the schema language from a GraphQL endpoint') | ||
.option('-o --introspected-schema-output-file [outputFile]', 'name for the output file of the introspected schema, defaults to "schema.json"', 'schema.json') | ||
.option('-u --schema-ast-output-file [outputFile]', 'name for the output file of the schema AST, defaults to "schema-ast.json"', 'schema-ast.json') | ||
.action((schemaTextFileName, options) => { | ||
if (options.generateIntrospectedSchema || (!options.generateIntrospectedSchema && !options.generateSchemaAst)) { | ||
gqlTools.generateIntrospectedSchema(schemaTextFileName, options.introspectedSchemaOutputFile); | ||
.option('-v --schema-language-output-file [outputFile]', 'name for the output file of the schema in schema language, defaults to "schema.graphql"', 'schema.graphql') | ||
.action((schemaResource, options) => { | ||
if (options.generateIntrospectedSchema || (!options.generateIntrospectedSchema && !options.generateSchemaAst && !options.generateSchemaLanguage)) { | ||
gqlTools.generateIntrospectedSchema(schemaResource, options.introspectedSchemaOutputFile); | ||
} | ||
if (options.generateSchemaAst) { | ||
gqlTools.generateSchemaAst(schemaTextFileName, options.schemaAstOutputFile); | ||
gqlTools.generateSchemaAst(schemaResource, options.schemaAstOutputFile); | ||
} | ||
if (options.generateSchemaLanguage) { | ||
gqlTools.generateSchemaLanguage(schemaResource, options.schemaLanguageOutputFile); | ||
} | ||
}) | ||
@@ -29,0 +35,0 @@ .parse(process.argv); |
18
index.js
@@ -23,2 +23,16 @@ var fs = require('fs'); | ||
exports.generateSchemaLanguage = function (schemaResource, outputFileName) { | ||
if (!isUrl(schemaResource)) { | ||
throw new Error('Only URLs are supported for schema language generation.'); | ||
} | ||
fetchIntrospectionSchema(schemaResource) | ||
.then(toSchemaLanguage) | ||
.then(createWriter(outputFileName)); | ||
function toSchemaLanguage(introspectionQueryResponse) { | ||
return graphql.printSchema(graphql.buildClientSchema(introspectionQueryResponse.data)); | ||
} | ||
}; | ||
function fetchIntrospectionSchema(endpointUrl) { | ||
@@ -44,4 +58,6 @@ var headers = { | ||
return function (content) { | ||
return fs.writeFileSync(fileName, JSON.stringify(content, null, 2)); | ||
var stringContent = typeof content !== 'string' ? JSON.stringify(content, null, 2) : content; | ||
return fs.writeFileSync(fileName, stringContent); | ||
} | ||
} |
{ | ||
"name": "gql-tools", | ||
"description": "GraphQL Tools for schema handling.", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"author": "Alberto Mijares <almilo@almilo.es>", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
# gql-tools | ||
This package provides several command-line tools to work with GraphQL schemas. For instance, generating the | ||
introspected schema or the schema AST in JSON format. | ||
introspected schema or the schema AST in JSON format. Generation of the schema of a remote GraphQL endpoint | ||
in the schema language is also supported (see CLI options). | ||
@@ -25,4 +26,5 @@ ### Installation | ||
### Usage | ||
* **gqlschema**: generates the introspected schema and the schema AST of a given GraphQL schema either in the schema | ||
language (file) or from a GraphQL endpoint (URL). | ||
* **gqlschema**: generates the introspected schema and the schema AST of a given GraphQL schema either from the schema | ||
language (file must be provided) or from a GraphQL endpoint (URL must be provided). Schema language generation of a | ||
GraphQL endpoint is also supported if a URL is provided (see command options). | ||
* **usage**: *gqlschema <schema.txt | http://example.com/graphql>* |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5682
83
30