Skip to content

Instantly share code, notes, and snippets.

@arjun-kava
Created January 22, 2019 06:33
Show Gist options
  • Save arjun-kava/0bd38e0c8feec360284677b1ee31728a to your computer and use it in GitHub Desktop.
Save arjun-kava/0bd38e0c8feec360284677b1ee31728a to your computer and use it in GitHub Desktop.
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