Skip to content

Instantly share code, notes, and snippets.

@ssomnoremac
Created December 8, 2017 03:10
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ssomnoremac/bec8933ac891b54bb5b9decb5a7fb697 to your computer and use it in GitHub Desktop.
Save ssomnoremac/bec8933ac891b54bb5b9decb5a7fb697 to your computer and use it in GitHub Desktop.
get your graphql schema
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