Skip to content

feat: add managed reverse edge and validator support#6

Merged
matthewmcneely merged 7 commits intomainfrom
matthewmcneely/support-validator-and-managed-reverse-edges
Jan 24, 2026
Merged

feat: add managed reverse edge and validator support#6
matthewmcneely merged 7 commits intomainfrom
matthewmcneely/support-validator-and-managed-reverse-edges

Conversation

@matthewmcneely
Copy link
Owner

@matthewmcneely matthewmcneely commented Jan 24, 2026

Description

This PR adds "managed reverse edges" which allows for more natural treatment of reverse edges in go structs when using modusgraph. It also adds support for automatic struct validation when mutating the graph.

Checklist

  • Code compiles correctly and linting passes locally
  • Tests added for new functionality, or regression tests for bug fixes added as applicable

Summary by cubic

Adds managed reverse edges and optional struct validation. This makes reverse relationships easier to model in Go structs and blocks invalid data during mutations.

  • New Features

    • Managed reverse edges: use "~predicate" fields in parent structs; the client writes the correct forward edges. Works with nested structs and slices.
    • Validator integration: new StructValidator, WithValidator, and NewValidator. Validation runs before Insert, InsertRaw, Upsert, and Update. Compatible with go-playground/validator. Documentation added in VALIDATOR.md.
    • Tests cover multi-level reverse edges and validation for file and Dgraph clients.
  • Dependencies

    • Added github.com/go-playground/validator/v10.
    • Updated github.com/dolan-in/dgman/v2 to v2.2.0-preview1.
    • Bumped Go to 1.25.6 and refreshed several golang.org/x packages.

Written for commit 8ce0f40. Summary will update on new commits.

@matthewmcneely matthewmcneely changed the title Add managed reverse edge and validator support feat: add managed reverse edge and validator support Jan 24, 2026
Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

4 issues found across 9 files

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="query_test.go">

<violation number="1" location="query_test.go:429">
P3: These assertions assume a deterministic ordering of reverse-edge results, which Dgraph does not guarantee without an explicit order clause. This can make the test flaky. Consider asserting the set of names instead of positional order (or add an orderasc clause to the query).</violation>
</file>

<file name="client.go">

<violation number="1" location="client.go:316">
P2: validateStruct can panic on nil input because it calls Elem() on a nil pointer. Guard against nil pointers and return a validation error instead of panicking.</violation>

<violation number="2" location="client.go:323">
P2: validateStruct can panic when a slice contains a nil pointer element. Add a nil check before calling Elem() on slice elements.</violation>
</file>

<file name="client_test.go">

<violation number="1" location="client_test.go:342">
P2: TestUser is missing the required DType field (`dgraph.type`), so inserts/updates can create untyped nodes or fail type-based expectations. Add DType to match the required node structure.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 3 files (changes from recent commits).

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="client_test.go">

<violation number="1" location="client_test.go:347">
P2: `DType` is now marked as `validate:"required"`, but the test’s “valid user” never sets `DType`. Because validation runs before Insert, this makes the supposed valid insert fail. Set `DType` on the test data (and any other inserts/updates) or relax the validator tag.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@matthewmcneely matthewmcneely merged commit 898caaa into main Jan 24, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant