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

Function extractBoundVariables

packages/graph/src/astToSteps.ts:2470–2532  ·  view source on GitHub ↗

* Extract all bound variables from a query's MATCH, WITH, and UNWIND clauses.

(query: Query)

Source from the content-addressed store, hash-verified

2468 * Extract all bound variables from a query's MATCH, WITH, and UNWIND clauses.
2469 */
2470function extractBoundVariables(query: Query): string[] {
2471 const variables: string[] = [];
2472
2473 // Extract variables from MATCH clauses
2474 for (const match of query.matches) {
2475 const pattern = match.pattern;
2476
2477 if (pattern.type === "ShortestPathPattern") {
2478 const sp = pattern as ShortestPathPattern;
2479 if (sp.variable) variables.push(sp.variable);
2480 if (sp.source.variable) variables.push(sp.source.variable);
2481 if (sp.target.variable) variables.push(sp.target.variable);
2482 if (sp.edge.variable) variables.push(sp.edge.variable);
2483 } else if (pattern.type === "MultiPattern") {
2484 // Handle comma-separated patterns
2485 const mp = pattern as MultiPattern;
2486 for (const p of mp.patterns) {
2487 for (const element of p.elements) {
2488 if (element.type === "NodePattern") {
2489 const node = element as NodePattern;
2490 if (node.variable) variables.push(node.variable);
2491 } else if (element.type === "EdgePattern") {
2492 const edge = element as EdgePattern;
2493 if (edge.variable) variables.push(edge.variable);
2494 }
2495 }
2496 }
2497 } else {
2498 const p = pattern as Pattern;
2499 for (const element of p.elements) {
2500 if (element.type === "NodePattern") {
2501 const node = element as NodePattern;
2502 if (node.variable) variables.push(node.variable);
2503 } else if (element.type === "EdgePattern") {
2504 const edge = element as EdgePattern;
2505 if (edge.variable) variables.push(edge.variable);
2506 }
2507 }
2508 }
2509 }
2510
2511 // Extract aliases from WITH clauses
2512 if (query.with) {
2513 for (const withClause of query.with) {
2514 for (const item of withClause.items) {
2515 if (item.alias) {
2516 variables.push(item.alias);
2517 }
2518 }
2519 }
2520 }
2521
2522 // Extract aliases from UNWIND clauses
2523 if (query.unwind) {
2524 for (const unwindClause of query.unwind) {
2525 if (unwindClause.alias) {
2526 variables.push(unwindClause.alias);
2527 }

Callers 1

convertReturnClauseFunction · 0.85

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected