Skip to content

Instantly share code, notes, and snippets.

@ronal2do
Last active August 31, 2017 13:29
Show Gist options
  • Save ronal2do/8c9fdd3982b7da3cf668072cf32df76d to your computer and use it in GitHub Desktop.
Save ronal2do/8c9fdd3982b7da3cf668072cf32df76d to your computer and use it in GitHub Desktop.
getSchema.js
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