Created
August 15, 2015 22:34
-
-
Save fson/d7ddffdc8a8c559d8d06 to your computer and use it in GitHub Desktop.
Update GraphQL schema file
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
#!/usr/bin/env babel-node --optional es7.asyncFunctions | |
import fs from 'fs'; | |
import path from 'path'; | |
import fetch from 'isomorphic-fetch'; | |
import { introspectionQuery } from 'graphql/utilities'; | |
const url = 'http://localhost:5000'; | |
async function updateSchema() { | |
const response = await fetch(url + '/graphql', { | |
body: JSON.stringify({ | |
query: introspectionQuery, | |
}), | |
headers: { | |
'Content-Type': 'application/json', | |
}, | |
method: 'POST', | |
}); | |
const result = await response.json(); | |
if (response.status < 200 || response.status >= 300) { | |
throw new Error( | |
`Fetching the schema from '${url}' failed. ${result.error || ''}` | |
); | |
} | |
fs.writeFileSync( | |
path.join(__dirname, '../data/schema.json'), | |
JSON.stringify(result, null, 2) | |
); | |
} | |
updateSchema().catch((error) => { | |
console.error(error.toString()); | |
process.exit(1); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment