Created
January 22, 2019 06:33
-
-
Save arjun-kava/0bd38e0c8feec360284677b1ee31728a to your computer and use it in GitHub Desktop.
Revisions
-
arjun-kava created this gist
Jan 22, 2019 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ 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`); }