make it accept a url of graphQL endpoint as well as a file
Closed this issue ยท 5 comments
capaj commented
now I have to make the IntrospectionQuery
myself, save the file as json and then run gql2flow command.
It would be really convenient if I could just do something like:
gql2flow https://graphql-explorer.githubapp.com/graphql/proxy
kitze commented
@capaj try using apollo-codegen for this, you can combine it with this package and you'll get what you want :)
joarwilk commented
I really like this idea, I'll see what I can do!
petrbela commented
If it's of any help, here's a script I'm currently using (I think I just copied it from Relay):
const fetch = require('node-fetch')
const fs = require('fs')
const {
buildClientSchema,
introspectionQuery,
printSchema,
} = require('graphql/utilities')
const path = require('path')
const schemaPath = path.join(__dirname, '..', 'schema')
const SERVER = 'http://localhost:3000/graphql'
fetch(`${SERVER}`, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({'query': introspectionQuery}),
}).then(res => res.json()).then(schemaJSON => {
fs.writeFileSync(
`${schemaPath}.json`,
JSON.stringify(schemaJSON, null, 2)
)
// Save user readable type system shorthand of schema
const graphQLSchema = buildClientSchema(schemaJSON.data)
fs.writeFileSync(
`${schemaPath}.graphql`,
printSchema(graphQLSchema)
)
})
And then run from npm/yarn:
"update-schema": "babel-node ./scripts/updateSchema.js && gql2flow -o schema.flow.js schema.json"
gajus commented
Any chance of this getting added to the core?
joarwilk commented
Added this in the latest version (0.4.x), please do try it out. No support for auth headers right now but can add if there is need.