···
+
import { getVisitFn, visitInParallel, BREAK } from 'graphql/language/visitor';
+
export { getVisitFn, visitInParallel, BREAK };
+
export function visit(node, visitor) {
+
function callback(node, key, parent, isLeaving) {
+
const visitFn = getVisitFn(visitor, node.kind, isLeaving)
+
const result = visitFn.call(visitor, node, key, parent, path, ancestors)
+
if (result === BREAK) throw BREAK
+
function traverse(node, key, parent) {
+
result = callback(node, key, parent, false);
+
if (result === false) {
+
} else if (result && typeof result.kind === 'string') {
+
for (const nodeKey in node) {
+
const value = node[nodeKey];
+
if (Array.isArray(value)) {
+
newValue = value.slice();
+
for (let index = 0; index < value.length; index++) {
+
if (value[index] != null && typeof value[index].kind === 'string') {
+
result = traverse(value[index], index, node);
+
if (result !== undefined) {
+
newValue[index] = result;
+
} else if (value != null && typeof value.kind === 'string') {
+
result = traverse(value, nodeKey, node);
+
if (result !== undefined) {
+
copy[nodeKey] = hasEdited ? newValue : value;
+
if (hasEdited) node = copy;
+
return callback(node, key, parent, true);
+
const result = traverse(node);
+
return result !== undefined ? result : node;
+
if (error !== BREAK) throw error;