Created
September 12, 2018 21:02
-
-
Save rigobertocontreras/f77719bee1497016bb4db5c9a5b75b67 to your computer and use it in GitHub Desktop.
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
// 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