Last active
August 31, 2017 13:29
-
-
Save ronal2do/8c9fdd3982b7da3cf668072cf32df76d to your computer and use it in GitHub Desktop.
getSchema.js
This file contains 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'); | |
fetch('http://localhost:5000/graphql', { | |
method: 'POST', | |
headers: { | |
'Accept': 'application/json', | |
'Content-Type': 'application/json' | |
}, | |
body: JSON.stringify({ 'query': introspectionQuery }), | |
}) | |
.then(res => res.json()) | |
.then(res => { | |
console.log(res); | |
const schemaString = printSchema(buildClientSchema(res.data)); | |
fs.writeFileSync('data/schema.graphql', schemaString); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment