Summary
StandardGraph.fromPatterns silently discards node labels when the same identity appears later in the pattern list without labels (a back-reference). The last occurrence wins, so a labelled first declaration is overwritten by an unlabelled back-reference.
Minimal reproduction (TypeScript, v0.4.0)
import { Gram, StandardGraph } from "@relateby/pattern";
import { Effect } from "effect";
const patterns = await Effect.runPromise(Gram.parse(`
(red:Red)-[:GO]->(blue:Blue)
(blue)-[:GO]->(red)
`));
const graph = StandardGraph.fromPatterns(patterns);
for (const [id, node] of graph.nodes()) {
console.log(id, "→", [...node.value.labels]);
}
Output:
Expected:
red → [Red]
blue → [Blue]
Explanation
Pattern 1 establishes red with label Red and blue with label Blue. Pattern 2 uses (blue) and (red) as back-references — identities without labels, referring to the nodes already declared. StandardGraph processes them as new nodes with empty label sets and overwrites the earlier entries.
Expected behaviour
When merging nodes by identity, a later occurrence with no labels should not overwrite labels established by an earlier occurrence. At minimum, non-empty label sets from any occurrence should be preserved. Union semantics (all labels from all occurrences are combined) or first-non-empty-wins semantics would both be correct.
Impact
Any multi-pattern gram file that uses back-references — which is the idiomatic way to author a rule file so that node identities compose into a proper graph — loses all label information on every node except those whose last occurrence carries explicit labels. This makes StandardGraph unusable for rule graph authoring patterns like:
(green:Green)-[:GO]->(red:Red)
(red)-[:GO]->(blue:Blue)
(blue)-[:GO]->(green)
Here all three nodes end up with empty label sets in StandardGraph.
Summary
StandardGraph.fromPatternssilently discards node labels when the same identity appears later in the pattern list without labels (a back-reference). The last occurrence wins, so a labelled first declaration is overwritten by an unlabelled back-reference.Minimal reproduction (TypeScript, v0.4.0)
Output:
Expected:
Explanation
Pattern 1 establishes
redwith labelRedandbluewith labelBlue. Pattern 2 uses(blue)and(red)as back-references — identities without labels, referring to the nodes already declared.StandardGraphprocesses them as new nodes with empty label sets and overwrites the earlier entries.Expected behaviour
When merging nodes by identity, a later occurrence with no labels should not overwrite labels established by an earlier occurrence. At minimum, non-empty label sets from any occurrence should be preserved. Union semantics (all labels from all occurrences are combined) or first-non-empty-wins semantics would both be correct.
Impact
Any multi-pattern gram file that uses back-references — which is the idiomatic way to author a rule file so that node identities compose into a proper graph — loses all label information on every node except those whose last occurrence carries explicit labels. This makes
StandardGraphunusable for rule graph authoring patterns like:Here all three nodes end up with empty label sets in
StandardGraph.