@graphql-codegen/plugin-helpers
Version:
GraphQL Code Generator common utils and types
17 lines (16 loc) • 559 B
JavaScript
import { visit } from 'graphql';
export function oldVisit(root, { enter: enterVisitors, leave: leaveVisitors, ...newVisitor }) {
if (typeof enterVisitors === 'object') {
for (const key in enterVisitors) {
newVisitor[key] ||= {};
newVisitor[key].enter = enterVisitors[key];
}
}
if (typeof leaveVisitors === 'object') {
for (const key in leaveVisitors) {
newVisitor[key] ||= {};
newVisitor[key].leave = leaveVisitors[key];
}
}
return visit(root, newVisitor);
}