Skip to content

feat: Entity Panel templating - BED 9017 - #3095

Open
brandonshearin wants to merge 9 commits into
mainfrom
BED-9017
Open

feat: Entity Panel templating - BED 9017#3095
brandonshearin wants to merge 9 commits into
mainfrom
BED-9017

Conversation

@brandonshearin

@brandonshearin brandonshearin commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Description

  • add the sprig library for fancy templating
  • add templating logic in graphdb/services, following new onion arch
  • wire templating into existing api/v2/nodes/{node_id} and api/v2/relationships/{relationship_id}
  • These APIs, when template execution fails, return the unexecuted template string and a template_error field, such as:
{
  "markdown": {
    "content": "the unexecuted string",
    "template_errors":  "Reason as to why template execution failed"
  }
}

Motivation and Context

Resolves BED-9017

We want users to be able to define "dynamic" entity panels. For example, a node entity panel should be able to render dynamic information about that node, and the same is true for a relationship.

We can achieve dynamic entity panels through "templating". This PR uses the sprig library to implement templating on entity panels.

How Has This Been Tested?

  • Automated unit/integration tests
  • To manually test this functionality you need to provide a valid template string for an entity panel in your opengraph extension upload. Pick a node or an edge, and add an info object like this:
"info": {
        "overview": {
          "title": "Area Overview",
          "position": 0,
          "markdown": {
            "content": "**Object ID:** `{{ .Properties.objectid }}`"
          }
        },
      }

Screenshots (optional):

The original ticket provided an example template for a node panel and an edge panel. Here are those dynamic templates rendered in the application:

for a node:
Screenshot 2026-08-03 at 4 43 52 PM

for an edge:
Screenshot 2026-08-03 at 4 44 30 PM

Types of changes

  • Chore (a change that does not modify the application functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Database Migrations

Checklist:

Summary by CodeRabbit

  • New Features

    • Added Markdown template rendering for node and relationship information.
    • Templates can use node, relationship, kind, and property data.
    • Failed rendering preserves the original template and reports an error without blocking other results.
  • Documentation

    • Updated API documentation to describe rendered Markdown and template error responses.
  • Bug Fixes

    • Improved handling of node and relationship details when individual Markdown templates fail.

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 8deee505-ccc2-4362-beba-23d9dba667ac

📥 Commits

Reviewing files that changed from the base of the PR and between 9551a0e and 99c09cd.

📒 Files selected for processing (1)
  • server/graphdb/internal/services/template.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • server/graphdb/internal/services/template.go

📝 Walkthrough

Walkthrough

Kind-info Markdown now renders in graph services for nodes and relationships. Responses expose rendered content and per-entry template errors. Failed rendering preserves the original template. Handlers no longer parse Markdown or aggregate rendering errors.

Changes

Kind-info Markdown rendering

Layer / File(s) Summary
Template contexts and rendering
go.mod, server/graphdb/internal/services/services.go, server/graphdb/internal/services/template.go, server/graphdb/internal/services/template_test.go
Added restricted Sprig-backed template rendering, node and relationship contexts, fallback content, and per-entry template errors.
Node rendering integration
server/graphdb/internal/services/node.go, server/graphdb/internal/services/node_test.go
GetNode renders node kind information and tests successful output, fallback behavior, template errors, and empty content.
Relationship rendering integration
server/graphdb/internal/services/relationship.go, server/graphdb/internal/services/relationship_test.go
GetRelationship resolves endpoint nodes and renders relationship kind information with source, target, kind, and relationship properties.
API response and handler wiring
server/graphdb/internal/handlers/node.go, server/graphdb/internal/handlers/relationship.go, server/graphdb/internal/handlers/*_test.go, packages/go/openapi/src/..., packages/go/openapi/doc/openapi.json
Handlers copy rendered Markdown and template errors into responses. OpenAPI schemas document fallback content and template_error.

Estimated code review effort: 3 (Moderate) | ~30 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant GetNodeByID
  participant GetNode
  participant renderNodeKindInfos
  participant renderMarkdown
  Client->>GetNodeByID: request node details
  GetNodeByID->>GetNode: load node with kind information
  GetNode->>renderNodeKindInfos: render node kind-info records
  renderNodeKindInfos->>renderMarkdown: execute Markdown template
  renderMarkdown-->>renderNodeKindInfos: rendered content or fallback with error
  renderNodeKindInfos-->>GetNode: updated kind-info records
  GetNode-->>GetNodeByID: node view data
  GetNodeByID-->>Client: Markdown content and template_error
Loading
sequenceDiagram
  participant Client
  participant GetRelationship
  participant EndpointNodeLookup
  participant renderRelationshipKindInfos
  participant renderMarkdown
  Client->>GetRelationship: request relationship details
  GetRelationship->>EndpointNodeLookup: load source and target nodes
  EndpointNodeLookup-->>GetRelationship: endpoint node contexts
  GetRelationship->>renderRelationshipKindInfos: render relationship kind-info records
  renderRelationshipKindInfos->>renderMarkdown: execute Markdown template
  renderMarkdown-->>renderRelationshipKindInfos: rendered content or fallback with error
  renderRelationshipKindInfos-->>GetRelationship: updated kind-info records
  GetRelationship-->>Client: relationship Markdown and template_error
Loading

Possibly related PRs

Suggested labels: documentation, enhancement, api, dependencies, go

Suggested reviewers: urangel

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 5.56% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the addition of entity panel templating and includes the associated ticket.
Description check ✅ Passed The description covers the change, motivation, testing, manual verification, and affected APIs, but leaves checklist items unchecked and uses template_errors inconsistently.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch BED-9017

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

@coderabbitai coderabbitai Bot added api A pull request containing changes affecting the API code. dependencies Pull requests that update a dependency file documentation Improvements or additions to documentation enhancement New feature or request go Pull requests that update go code labels Aug 3, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
server/graphdb/internal/handlers/relationship_test.go (1)

63-70: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add response coverage for template_error.

The fixture verifies rendered content but does not verify TemplateError. Add a case with one failed relationship template and assert that the response preserves its fallback content and template_error.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@server/graphdb/internal/handlers/relationship_test.go` around lines 63 - 70,
Add response coverage in the relationship fixture around the existing
RenderedMarkdown case by including a relationship with a failed template, its
fallback content, and the expected TemplateError value. Assert that the handler
response preserves both the fallback rendered content and template_error for
that relationship while retaining the existing successful-template coverage.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@server/graphdb/internal/services/template.go`:
- Around line 171-174: Update both WarnContext calls in the relationship-kind
markdown rendering flow to pass structured slog.String and slog.Any attributes
instead of alternating key-value arguments, preserving the existing info_key and
error values.
- Around line 68-97: Update the unsupportedFns list to use Sprig’s exact randInt
identifier instead of randint, and add a regression test verifying that parsing
a template containing {{ randInt 1 2 }} fails.

---

Nitpick comments:
In `@server/graphdb/internal/handlers/relationship_test.go`:
- Around line 63-70: Add response coverage in the relationship fixture around
the existing RenderedMarkdown case by including a relationship with a failed
template, its fallback content, and the expected TemplateError value. Assert
that the handler response preserves both the fallback rendered content and
template_error for that relationship while retaining the existing
successful-template coverage.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 4f1d0075-6f30-4b0a-9a4d-24ea061533e5

📥 Commits

Reviewing files that changed from the base of the PR and between 1fc1979 and 9551a0e.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (15)
  • go.mod
  • packages/go/openapi/doc/openapi.json
  • packages/go/openapi/src/paths/graph.nodes.id.yaml
  • packages/go/openapi/src/schemas/model.kind-info-markdown.yaml
  • server/graphdb/internal/handlers/node.go
  • server/graphdb/internal/handlers/node_test.go
  • server/graphdb/internal/handlers/relationship.go
  • server/graphdb/internal/handlers/relationship_test.go
  • server/graphdb/internal/services/node.go
  • server/graphdb/internal/services/node_test.go
  • server/graphdb/internal/services/relationship.go
  • server/graphdb/internal/services/relationship_test.go
  • server/graphdb/internal/services/services.go
  • server/graphdb/internal/services/template.go
  • server/graphdb/internal/services/template_test.go

Comment thread server/graphdb/internal/services/template.go
Comment thread server/graphdb/internal/services/template.go

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we include ETAC authorization checks on the source and target nodes associated with the relationship, since the markdown templating can access properties of those nodes?

if len(relationship.KindInfos) > 0 {
source, sourceErr := s.GetNode(ctx, relationship.SourceNodeID, false)
if sourceErr != nil {
return Relationship{}, fmt.Errorf("fetching relationship source node: %w", sourceErr)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since these nodes are only needed for rendering KindInfo, maybe this shouldn't return a hard error? Otherwise if you fetched a relationship with nodes that had been deleted or something, it would fail now with no rel data returned, vs just returning unrendered markdown content with a warning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api A pull request containing changes affecting the API code. dependencies Pull requests that update a dependency file documentation Improvements or additions to documentation enhancement New feature or request go Pull requests that update go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants