-
-
Save rodrigooler/6d71f9808c5de67bc4b31e0b524f6761 to your computer and use it in GitHub Desktop.
get your graphql schema
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fetch = require('node-fetch'); | |
var fs = require('fs'); | |
const { | |
buildClientSchema, | |
introspectionQuery, | |
printSchema, | |
} = require('graphql/utilities'); | |
console.log(introspectionQuery); | |
fetch('http://localhost:4000/api', { | |
method: 'POST', | |
headers: { | |
'Accept': 'application/json', | |
'Content-Type': 'application/json' | |
}, | |
body: JSON.stringify({ 'query': introspectionQuery }), | |
}) | |
.then(res => res.json()) | |
.then(res => { | |
const schemaString = printSchema(buildClientSchema(res.data)); | |
console.log("sgdfdg", schemaString); | |
fs.writeFileSync('data/schema.json', JSON.stringify(res, null, 2)); | |
fs.writeFileSync('data/schema.graphql', schemaString); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment