(
source: GraphSource<any>,
input: Iterable<TraversalPath<any, any, any>>,
context?: QueryContext,
)
| 775 | } |
| 776 | |
| 777 | public *traverse( |
| 778 | source: GraphSource<any>, |
| 779 | input: Iterable<TraversalPath<any, any, any>>, |
| 780 | context?: QueryContext, |
| 781 | ): IterableIterator<TraversalPath<any, any, any>> { |
| 782 | const { vertexLabels, condition, stepLabels } = this.config; |
| 783 | |
| 784 | // Fetch matching vertices once for performance |
| 785 | const allVertices = [ |
| 786 | ...(vertexLabels && vertexLabels.length > 0 |
| 787 | ? source.getVertices(...vertexLabels) |
| 788 | : source.getVertices()), |
| 789 | ]; |
| 790 | |
| 791 | // Filter vertices by condition if provided |
| 792 | const matchingVertices = condition |
| 793 | ? allVertices.filter((vertex) => { |
| 794 | // Create a temporary path to evaluate the condition |
| 795 | const tempPath = new TraversalPath(undefined, vertex, stepLabels ?? []); |
| 796 | return evaluateCondition(tempPath, condition, context); |
| 797 | }) |
| 798 | : allVertices; |
| 799 | |
| 800 | // Collect all input paths (we need to iterate multiple times) |
| 801 | const inputPaths = [...input]; |
| 802 | if (inputPaths.length === 0) { |
| 803 | // If no input paths, treat like FetchVerticesStep |
| 804 | for (const vertex of matchingVertices) { |
| 805 | this.traversed++; |
| 806 | this.emitted++; |
| 807 | yield new TraversalPath(undefined, vertex, stepLabels ?? []); |
| 808 | } |
| 809 | return; |
| 810 | } |
| 811 | |
| 812 | // For each input path, combine with each matching vertex (cross-product) |
| 813 | for (const inputPath of inputPaths) { |
| 814 | for (const vertex of matchingVertices) { |
| 815 | this.traversed++; |
| 816 | this.emitted++; |
| 817 | // Chain the new vertex onto the input path |
| 818 | yield inputPath.with(vertex, stepLabels ?? []); |
| 819 | } |
| 820 | } |
| 821 | } |
| 822 | |
| 823 | public override clone(partial?: Partial<CartesianFetchStepConfig>) { |
| 824 | const { config } = this; |
nothing calls this directly
no test coverage detected