Skip to content

Instantly share code, notes, and snippets.

@fson
Created August 15, 2015 22:34
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 fson/d7ddffdc8a8c559d8d06 to your computer and use it in GitHub Desktop.
Save fson/d7ddffdc8a8c559d8d06 to your computer and use it in GitHub Desktop.
Update GraphQL schema file
#!/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