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

Method traverse

packages/graph/src/Steps.ts:5813–5965  ·  view source on GitHub ↗
(
    source: GraphSource<any>,
    input: Iterable<TraversalPath<any, any, any>>,
    context?: QueryContext,
  )

Source from the content-addressed store, hash-verified

5811 }
5812
5813 public *traverse(
5814 source: GraphSource<any>,
5815 input: Iterable<TraversalPath<any, any, any>>,
5816 context?: QueryContext,
5817 ): IterableIterator<TraversalPath<any, any, any>> {
5818 const { assignments } = this.config;
5819
5820 for (const path of input) {
5821 this.traversed++;
5822
5823 // Apply each assignment
5824 for (const assignment of assignments) {
5825 // Check if this is a map-based assignment (setAllProperties or setAddProperties)
5826 if ("type" in assignment) {
5827 const { variable, properties } = assignment;
5828
5829 // Find the element bound to this variable in the path
5830 const elementPath = path.get(variable);
5831 if (!elementPath) {
5832 throw new Error(
5833 `SET: Variable '${variable}' not found in path. Available variables: ${Array.from(path.labels).join(", ") || "none"}`,
5834 );
5835 }
5836
5837 let element = elementPath.value;
5838 // Handle FOREACH element wrappers
5839 if (element && typeof element === "object" && element.label === "ForeachElement") {
5840 element = element.value;
5841 }
5842 if (!(element instanceof Vertex || element instanceof Edge)) {
5843 throw new Error(
5844 `SET: Variable '${variable}' is not a vertex or edge (got ${typeof element})`,
5845 );
5846 }
5847
5848 // Resolve the property map
5849 let resolvedProps: Record<string, unknown>;
5850 if (
5851 typeof properties === "object" &&
5852 properties !== null &&
5853 "type" in properties &&
5854 properties.type === "parameter"
5855 ) {
5856 // Parameter reference
5857 const params = context?.params ?? getQueryParams();
5858 const paramName = (properties as { type: "parameter"; name: string }).name;
5859 resolvedProps = params[paramName] as Record<string, unknown>;
5860 if (
5861 resolvedProps === undefined ||
5862 resolvedProps === null ||
5863 typeof resolvedProps !== "object"
5864 ) {
5865 throw new Error(`SET: Parameter '${paramName}' must be an object/map`);
5866 }
5867 } else {
5868 // Direct property map
5869 resolvedProps = properties as Record<string, unknown>;
5870 }

Callers

nothing calls this directly

Calls 2

getQueryParamsFunction · 0.85
getMethod · 0.65

Tested by

no test coverage detected