Created
November 5, 2018 04:53
-
-
Save tanduong/7b908a1bdf5b5d5807b994a0e059903f to your computer and use it in GitHub Desktop.
Get & write out 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
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