UNPKG

@toptal/davinci-graphql-codegen-extensions

Version:
34 lines (28 loc) 857 B
const { parse, visit, buildASTSchema } = require('graphql') const { readFileSync } = require('fs') const annotationDirective = 'tt_earlySupportHidden' module.exports = function (schemaString) { const schemaContent = readFileSync(schemaString, { encoding: 'utf-8', }).toString() const ast = parse(schemaContent) const newAst = visit(ast, { leave(node) { if ( node.kind === 'EnumValueDefinition' && node.directives .map(directive => directive.name.value) .includes(annotationDirective) ) { return null } // @return // undefined: no action // false: no action // visitor.BREAK: stop visiting altogether // null: delete this node // any value: replace this node with the returned value }, }) return buildASTSchema(newAst) }