MCPcopy Create free account
hub / github.com/codemix/graph / #extractLabel

Method #extractLabel

packages/graph/src/Steps.ts:4814–4845  ·  view source on GitHub ↗
(item: unknown)

Source from the content-addressed store, hash-verified

4812 }
4813
4814 #extractLabel(item: unknown): string | string[] | null | "skip" {
4815 // Handle arrays from SelectStep (first element is the path)
4816 if (Array.isArray(item)) {
4817 const first = item[0];
4818 // null values from OPTIONAL MATCH should yield null
4819 if (first === null) {
4820 return null;
4821 }
4822 if (first !== undefined) {
4823 return this.#extractLabel(first);
4824 }
4825 return "skip";
4826 }
4827
4828 // Handle null values (from OPTIONAL MATCH with no matches)
4829 if (item === null) {
4830 return null;
4831 }
4832
4833 // Handle TraversalPaths
4834 if (item instanceof TraversalPath) {
4835 return this.#extractLabel(item.value);
4836 }
4837
4838 // Handle direct elements
4839 if (item instanceof Vertex || item instanceof Edge) {
4840 // type() returns a single string, labels() returns an array
4841 return this.config.returnAsString ? item.label : [item.label];
4842 }
4843
4844 return "skip";
4845 }
4846
4847 public override clone(partial?: Partial<LabelsStepConfig>) {
4848 return new LabelsStep({

Callers 1

traverseMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected