feat: Add virtual relationships for multi-hop path traversal [INFP-313]#8627
feat: Add virtual relationships for multi-hop path traversal [INFP-313]#8627
Conversation
Implement schema-level virtual relationships that traverse multi-hop relationship paths to collect target nodes. Users define a path (e.g., bays__line_cards__modules__interfaces) on a node kind, and the system resolves it at query time via Cypher traversal. Backend: - VirtualRelationshipSchema model (generated + wrapper) - Schema validation: path segments, segment count, circular refs, name conflicts - Generic inheritance resolution for path validation - Cypher multi-hop traversal queries (peers + count) - GraphQL resolver with filtering, pagination, dedup, branch-awareness - GraphQL field generation on NestedPaginated types Frontend: - Virtual relationship tabs on node detail pages - Count badges, read-only (no Add button) - OpenAPI types regenerated Tests: - 15 unit tests for schema validation - 10 functional tests: query, empty, pagination, filtering, branch-aware, dedup, cross-domain, schema validation Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
- Fix ruff formatting (multi-line function args) - Update betterer results for TypeScript changes - Regenerate validator-migration.mdx with VirtualRelationship schema Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add feature spec, plan, research, data model, contracts, tasks, and quickstart - Regenerate node.mdx and generic.mdx with virtual_relationships field - Add validator-migration docs (committed in prior fix) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Merging this PR will improve performance by 38.1%
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ⚡ | test_schemabranch_process |
1,040.9 ms | 802.3 ms | +29.73% |
| ⚡ | test_query_rel_many |
693.3 ms | 523.8 ms | +32.35% |
| ⚡ | test_base_schema_duplicate_CoreProposedChange |
2.1 ms | 1.7 ms | +22.73% |
| ⚡ | test_graphql_generate_schema |
516 ms | 373.6 ms | +38.1% |
| ⚡ | test_schemabranch_duplicate |
7.2 ms | 5.5 ms | +31.38% |
| ⚡ | test_query_rel_one |
663.2 ms | 501.7 ms | +32.17% |
| ⚡ | test_nodemanager_querypeers |
1.5 ms | 1.3 ms | +21.6% |
| ⚡ | test_relationshipmanager_getpeer |
160.5 µs | 134.2 µs | +19.57% |
| ⚡ | test_load_node_to_db_node_schema |
67 ms | 52.5 ms | +27.58% |
| ⚡ | test_get_menu |
245.5 ms | 188.7 ms | +30.14% |
| ⚡ | test_query_one_model |
464.9 ms | 354 ms | +31.32% |
| ⚡ | test_get_schema |
328 ms | 253 ms | +29.68% |
Comparing infp-313-virtual-relationships (081bd1e) with develop (34ce17e)
|
This PR has been inactive for 2 weeks and has been marked as stale. If you're still working on this, please:
The stale label will be removed automatically when there's new activity. |
Why
Problem: Users modeling complex infrastructure (e.g., chassis with bays, line cards, modules, interfaces) are forced to choose between schema correctness and query simplicity. To answer "give me all interfaces on this device," they must traverse multiple relationship hops manually — via complex GraphQL queries, custom Python code, or tedious UI navigation.
Impact: This forces a trade-off: model data correctly (many hops) or duplicate relationships for convenience (risking inconsistency). AI/MCP use cases are particularly affected — LLMs need simplified access without full schema context.
What
Implements virtual relationships — schema-level computed relationship definitions that traverse multi-hop paths to collect target nodes at query time, without data duplication.
Schema Definition
Key Changes
Backend (Python)
VirtualRelationshipSchemamodel with path validation (segment count, circular refs, name conflicts, generic inheritance resolution)NestedPaginated{Kind}types with dedicated resolver supporting filtering viaNodeManager.queryvirtual_relationshipson node/generic schemasFrontend (TypeScript/React)
RelationshipTableanduseGetRelationshipCountinfrastructureTests
Architecture Decisions
__separator, consistent with existing Infrahub filter conventionsFiles Changed (26 files, +2133/-17)
virtual_relationship_schema.py,definitions/internal.py,generated/__init__.py,basenode_schema.py,schema_branch.pycore/query/virtual_relationship.pygraphql/manager.py,resolvers/virtual_relationship.pyobject-details-tabs.tsx,object-tabs.tsx,object-relationships-manager.tsxtest_virtual_relationship_schema.py,test_virtual_relationship.pyvirtual-relationships.mdx, changelog fragmentTest plan
🤖 Generated with Claude Code