Comparing version 0.4.1 to 0.4.2
35
index.js
#!/usr/bin/env node | ||
'use strict'; | ||
const isUrl = require('is-url'); | ||
const program = require('commander'); | ||
@@ -14,2 +16,5 @@ | ||
// Fetch utils | ||
const fetchUtils = require('./util/fetcher'); | ||
program | ||
@@ -42,10 +47,30 @@ .version('0.3.0') | ||
) | ||
.action((fileName, options) => { | ||
let schema = fileIO.readFile(fileName); | ||
.action((path, options) => { | ||
const getSchema = new Promise((resolve, reject) => { | ||
if (isUrl(path)) { | ||
fetchUtils.fetchWithIntrospection(path, (err, schema) => { | ||
if (err) { | ||
reject(err); | ||
} else if (!schema.data) { | ||
reject( | ||
new Error('Server replied with an invalid introspection schema') | ||
); | ||
} else { | ||
resolve(schema); | ||
} | ||
}); | ||
} else { | ||
resolve(fileIO.readFile(path)); | ||
} | ||
}); | ||
let interfaces = interfaceUtils.generateTypes(schema, options); | ||
getSchema | ||
.then(schema => { | ||
let interfaces = interfaceUtils.generateTypes(schema, options); | ||
let module = moduleUtils.generateModule(options.moduleName, interfaces); | ||
let module = moduleUtils.generateModule(options.moduleName, interfaces); | ||
moduleUtils.writeModuleToFile(options.outputFile, module); | ||
moduleUtils.writeModuleToFile(options.outputFile, module); | ||
}) | ||
.catch(err => console.error(err.message)); | ||
}) | ||
@@ -52,0 +77,0 @@ .parse(process.argv); |
{ | ||
"name": "gql2flow", | ||
"version": "0.4.1", | ||
"version": "0.4.2", | ||
"description": "Convert a GraphQL Schema to a Flowtype definition", | ||
"main": "index.js", | ||
"dependencies": { | ||
"commander": "^2.9.0" | ||
"commander": "^2.9.0", | ||
"is-url": "^1.2.2", | ||
"node-fetch": "^1.6.3" | ||
}, | ||
@@ -13,3 +15,3 @@ "devDependencies": { | ||
"chai": "^3.5.0", | ||
"graphql": "^0.7.2", | ||
"graphql": "^0.9.6", | ||
"mocha": "^2.4.5" | ||
@@ -16,0 +18,0 @@ }, |
@@ -25,11 +25,10 @@ # GraphQL To Flow Types | ||
#### With Default Options | ||
#### Fetching from a server | ||
```shell | ||
gql2flow schema.json | ||
gql2flow https://api.github.com/graphql | ||
``` | ||
#### With Optional Options | ||
#### From a json schema | ||
```shell | ||
gql2flow -i BadInterface,BadType,BadUnion -o schema.flow.js schema.json | ||
gql2flow schema.json | ||
``` |
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
Network access
Supply chain riskThis module accesses the network.
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
11998
9
312
3
34
2
1
+ Addedis-url@^1.2.2
+ Addednode-fetch@^1.6.3
+ Addedencoding@0.1.13(transitive)
+ Addediconv-lite@0.6.3(transitive)
+ Addedis-stream@1.1.0(transitive)
+ Addedis-url@1.2.4(transitive)
+ Addednode-fetch@1.7.3(transitive)
+ Addedsafer-buffer@2.1.2(transitive)