Skip to content

Instantly share code, notes, and snippets.

@tanduong
Created November 5, 2018 04:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tanduong/7b908a1bdf5b5d5807b994a0e059903f to your computer and use it in GitHub Desktop.
Save tanduong/7b908a1bdf5b5d5807b994a0e059903f to your computer and use it in GitHub Desktop.
Get & write out graphql schema
const fs = require('fs');
require('isomorphic-fetch');
const {introspectionQuery, buildClientSchema, printSchema} = require('graphql');
function introspectionProvider(introspectionQuery) {
console.log(JSON.stringify({query: introspectionQuery}));
return fetch('https://marketplace-api.qa.kamereo.vn/graphql', {
method: 'post',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({query: introspectionQuery}),
})
.then(function(response) {
return response.text();
})
.then(function(responseBody) {
const introspectionSchemaResult = JSON.parse(responseBody).data;
const graphqlSchemaObj = buildClientSchema(introspectionSchemaResult);
const sdlString = printSchema(graphqlSchemaObj);
fs.writeFile('schema.graphql', sdlString, () => null);
});
}
introspectionProvider(introspectionQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment