joarwilk / gql2flow

Convert a GraphQL Schema to a flow definition
97 stars 24 forks source link

make it accept a url of graphQL endpoint as well as a file #10

Closed capaj closed 7 years ago

capaj commented 7 years ago

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 7 years ago

@capaj try using apollo-codegen for this, you can combine it with this package and you'll get what you want :)

joarwilk commented 7 years ago

I really like this idea, I'll see what I can do!

petrbela commented 7 years ago

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 7 years ago

Any chance of this getting added to the core?

joarwilk commented 7 years ago

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.