Created
January 22, 2019 06:33
-
-
Save arjun-kava/0bd38e0c8feec360284677b1ee31728a to your computer and use it in GitHub Desktop.
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
import { print, isSpecifiedScalarType, isSpecifiedDirective } from 'graphql'; | |
export function printSchemaWithDirectives(schema) { | |
const str = Object | |
.keys(schema.getTypeMap()) | |
.filter(k => !k.match(/^__/)) | |
.reduce((accum, name) => { | |
const type = schema.getType(name); | |
return !isSpecifiedScalarType(type) | |
? accum += `${print(type.astNode)}\n` | |
: accum; | |
}, ''); | |
return schema | |
.getDirectives() | |
.reduce((accum, d) => { | |
return !isSpecifiedDirective(d) | |
? accum += `${print(d.astNode)}\n` | |
: accum; | |
}, str + `${print(schema.astNode)}\n`); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment