MCPcopy Create free account
hub / github.com/codemix/graph / convertForeachClause

Function convertForeachClause

packages/graph/src/astToSteps.ts:1066–1114  ·  view source on GitHub ↗

* Convert a FOREACH clause into a ForeachStep.

(foreachClause: ForeachClause)

Source from the content-addressed store, hash-verified

1064 * Convert a FOREACH clause into a ForeachStep.
1065 */
1066function convertForeachClause(foreachClause: ForeachClause): ForeachStep<Step<any>[]> {
1067 const { variable, listExpression, operations } = foreachClause;
1068
1069 // Convert the list expression
1070 const stepListExpression = convertListExpression(listExpression);
1071
1072 // Convert the operations to inner steps
1073 const innerSteps: Step<any>[] = [];
1074 for (const operation of operations) {
1075 if (operation.type === "SetOperation") {
1076 const setOp = operation as ASTSetOperation;
1077 const setStep = convertSetOperationToStep(setOp);
1078 innerSteps.push(setStep);
1079 } else if (operation.type === "DeleteOperation") {
1080 // Convert DELETE/DETACH DELETE operations inside FOREACH
1081 const deleteOp = operation as ASTDeleteOperation;
1082 const deleteStep = new DeleteStep({
1083 variables: deleteOp.variables,
1084 detach: deleteOp.detach,
1085 });
1086 innerSteps.push(deleteStep);
1087 } else if (operation.type === "MatchClause") {
1088 // Convert MATCH operations inside FOREACH
1089 const matchClause = operation as MatchClause;
1090 const matchPattern = matchClause.pattern;
1091
1092 if (matchPattern.type === "ShortestPathPattern") {
1093 // Convert shortestPath pattern to steps
1094 const shortestPathSteps = convertShortestPathPattern(
1095 matchPattern as ShortestPathPattern,
1096 matchClause.where,
1097 );
1098 innerSteps.push(...shortestPathSteps);
1099 } else {
1100 // Regular pattern - convert to steps
1101 const matchSteps = convertPattern(matchPattern as Pattern, matchClause.where);
1102 innerSteps.push(...matchSteps);
1103 }
1104 }
1105 }
1106
1107 return new ForeachStep(
1108 {
1109 variable,
1110 listExpression: stepListExpression,
1111 },
1112 innerSteps,
1113 );
1114}
1115
1116/**
1117 * Convert a ListExpression AST node to a ForeachListExpression.

Callers 2

processQuerySegmentsFunction · 0.85
processLegacyQueryFunction · 0.85

Calls 5

convertListExpressionFunction · 0.85
convertPatternFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected