Skip to content

Instantly share code, notes, and snippets.

@rigobertocontreras
Created September 12, 2018 21:02
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 rigobertocontreras/f77719bee1497016bb4db5c9a5b75b67 to your computer and use it in GitHub Desktop.
Save rigobertocontreras/f77719bee1497016bb4db5c9a5b75b67 to your computer and use it in GitHub Desktop.
// Save JSON of full schema introspection
import {graphql, introspectionQuery, printSchema} from "graphql";
import {writeFileSync} from "fs";
import {join} from "path";
import schema from "./index";
function generate() {
(async () => {
const result = await (graphql(schema, introspectionQuery));
if (result.errors) {
console.error(
'ERROR introspecting schema: ',
JSON.stringify(result.errors, null, 2)
)
} else {
writeFileSync(
join(__dirname, './schema.json'),
JSON.stringify(result, null, 2)
)
}
})();
// Save user readable type system shorthand of schema
writeFileSync(
join(__dirname, './schema.graphql'),
printSchema(schema)
);
}
export default generate()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment