Created
March 7, 2018 19:40
-
-
Save jsjaspreet/9cbe9b8dd629c0d1b8c05ddd00b80c63 to your computer and use it in GitHub Desktop.
Generate GraphQL Schema and Docs programmatically (adopted from Relay github)
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
import fs from 'fs'; | |
import path from 'path'; | |
import { graphql } from 'graphql'; | |
import { introspectionQuery } from 'graphql/utilities'; | |
import schema from './src/schema/index'; | |
(async () => { | |
const result = await graphql(schema, introspectionQuery); | |
if (result.errors) { | |
console.error( | |
'ERROR introspecting schema: ', | |
JSON.stringify(result.errors, null, 2) | |
); | |
} else { | |
fs.writeFileSync( | |
path.join(__dirname, './schema.json'), | |
JSON.stringify(result, null, 2) | |
); | |
} | |
})(); |
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
{ | |
"scripts": { | |
"generate-schema": "babel-node ./generateSchema.js", | |
"generate-schema-doc": "npm run clean && npm run generate-schema && graphdoc -s ./schema.json -o ./doc" | |
}, | |
"dependencies": { | |
"graphql": "~0.11.7" | |
}, | |
"devDependencies": { | |
"@2fd/graphdoc": "^2.4.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment