Skip to content

feat: Add virtual relationships for multi-hop path traversal [INFP-313]#8627

Closed
minitriga wants to merge 4 commits intodevelopfrom
infp-313-virtual-relationships
Closed

feat: Add virtual relationships for multi-hop path traversal [INFP-313]#8627
minitriga wants to merge 4 commits intodevelopfrom
infp-313-virtual-relationships

Conversation

@minitriga
Copy link
Copy Markdown
Contributor

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

nodes:
  - name: Device
    namespace: Infra
    virtual_relationships:
      - name: all_interfaces
        label: "All Interfaces"
        path: bays__line_cards__modules__interfaces
      - name: affected_services
        path: interfaces__circuits__containers__services

Key Changes

Backend (Python)

  • Schema layer: VirtualRelationshipSchema model with path validation (segment count, circular refs, name conflicts, generic inheritance resolution)
  • Query layer: Cypher multi-hop traversal queries with branch-aware filtering, deduplication, pagination
  • GraphQL layer: Virtual relationship fields generated as NestedPaginated{Kind} types with dedicated resolver supporting filtering via NodeManager.query
  • API: OpenAPI schema regenerated with virtual_relationships on node/generic schemas

Frontend (TypeScript/React)

  • Virtual relationship tabs on node detail pages with count badges
  • Read-only (no "Add relationship" button)
  • Reuses existing RelationshipTable and useGetRelationshipCount infrastructure

Tests

  • 15 unit tests: schema parsing, path validation, name conflicts, peer derivation, label generation
  • 10 functional tests: basic query, empty results, pagination, filtering, branch-aware resolution, deduplication, cross-domain traversal (4 node kinds), schema validation rejection

Architecture Decisions

  • Query-time resolution (not materialized) — ensures consistency, avoids cache invalidation complexity
  • Path notation uses __ separator, consistent with existing Infrahub filter conventions
  • Generic inheritance resolution — when peer kind is a Generic, validation checks concrete implementations for available relationships
  • Read-only in initial release; write support deferred

Files Changed (26 files, +2133/-17)

Area Files Purpose
Schema model virtual_relationship_schema.py, definitions/internal.py, generated/ VirtualRelationshipSchema definition + generation
Schema integration __init__.py, basenode_schema.py, schema_branch.py Loading, validation, processing, extensions
Query core/query/virtual_relationship.py Cypher traversal + count queries
GraphQL graphql/manager.py, resolvers/virtual_relationship.py Field generation + resolver
Frontend object-details-tabs.tsx, object-tabs.tsx, object-relationships-manager.tsx Tab rendering + read-only handling
Tests test_virtual_relationship_schema.py, test_virtual_relationship.py Unit + functional tests
Docs virtual-relationships.mdx, changelog fragment User documentation

Test plan

  • Unit tests pass (15/15)
  • Functional tests pass (10/10) — requires Neo4j
  • Manual testing with infrahub-bundle-dc schemas (all_services, connected_devices)
  • Schema validation rejects invalid paths
  • Branch-aware resolution verified
  • Cross-domain traversal (4 node kinds) verified
  • Deduplication verified
  • Filtering verified
  • E2E test (Playwright) — written, needs CI environment
  • Permission filtering — deferred to integration tests
  • Branch merge behavior — deferred to integration_docker tests

🤖 Generated with Claude Code

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>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 17, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 453e9550-59b2-4585-9295-1ec9febcaa5f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Coding Plan
  • Generate coding plan for human review comments

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added type/documentation Improvements or additions to documentation group/backend Issue related to the backend (API Server, Git Agent) group/frontend Issue related to the frontend (React) labels Mar 17, 2026
minitriga and others added 3 commits March 17, 2026 15:00
- 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>
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Mar 17, 2026

Merging this PR will improve performance by 38.1%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 12 improved benchmarks

Performance Changes

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)

Open in CodSpeed

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 2, 2026

This PR has been inactive for 2 weeks and has been marked as stale.

If you're still working on this, please:

  • Push new commits, or
  • Leave a comment to indicate this PR is still active

The stale label will be removed automatically when there's new activity.

@github-actions github-actions Bot added the stale Marks stale issues and pull requests label Apr 2, 2026
@minitriga minitriga closed this Apr 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

group/backend Issue related to the backend (API Server, Git Agent) group/frontend Issue related to the frontend (React) stale Marks stale issues and pull requests type/documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant