Skip to content

feat: migrate to new embedded Dgraph client and add validation support#7

Merged
matthewmcneely merged 7 commits intomainfrom
matthewmcneely/use-new-dgraph-embedded
Feb 13, 2026
Merged

feat: migrate to new embedded Dgraph client and add validation support#7
matthewmcneely merged 7 commits intomainfrom
matthewmcneely/use-new-dgraph-embedded

Conversation

@matthewmcneely
Copy link
Copy Markdown
Owner

@matthewmcneely matthewmcneely commented Feb 3, 2026

Description

Major refactoring to replace the old embedded server implementation with the new
Dgraph v25 embedded client architecture, providing better performance and
stability for in-process deployments.

Breaking Changes:

  • Replaced buf_server.go with new embedded_client.go implementation
  • Updated all import paths from github.com/hypermodeinc/dgraph to github.com/dgraph-io/dgraph
  • Client initialization now uses the new embedded client architecture

New Features:

  • Add comprehensive validation support using github.com/go-playground/validator/v10
  • New WithValidator() client option for custom validation rules
  • Validation integrated into Insert, Update, and Upsert operations
  • Support for custom validation functions and struct tags

Enhanced Test Coverage:

  • Added validate_test.go with comprehensive validation test suite
  • Enhanced update_test.go and upsert_test.go with more test cases
  • Improved error handling and edge case testing
  • Added tests for custom validation rules and partial validation failures

Dependency Updates:

  • Updated Dgraph dependencies to v25 stable release
  • Upgraded Go modules to latest stable versions
  • Updated gRPC to v1.78.0 for better performance
  • Refreshed all indirect dependencies for security and stability

Performance Improvements:

  • Optimized embedded client connection handling
  • Improved mutation performance with better error handling
  • Enhanced query execution with the new embedded client

Bug Fixes:

  • Fixed import paths for Dgraph v25 compatibility
  • Resolved connection issues in embedded mode
  • Improved error messages for validation failures
  • Fixed test cases that were assuming order in assertions

Documentation:

  • Updated README.md with new embedded client usage examples
  • Clarified connection string formats for file vs Dgraph URIs
  • Added validation examples and best practices

This migration provides a more stable foundation for embedded deployments
while maintaining full backward compatibility for remote Dgraph connections.

Checklist

  • Code compiles correctly and linting passes locally
  • For all code changes, an entry added to the CHANGELOG.md file describing and linking to
    this PR
  • Tests added for new functionality, or regression tests for bug fixes added as applicable

Summary by cubic

Migrates embedded mode to the Dgraph v25 embedded client for faster, more stable in-process use, and adds entity validation via WithValidator across insert, update, and upsert. Updates to the latest Dgraph v25 build and refreshes README docs.

  • New Features

    • Embedded client for file:// URIs; seamless with remote clients.
    • Validation using go-playground/validator; custom rules and tags; enforced on insert/update/upsert.
    • Clearer unique constraint errors mapped to UniqueError.
  • Migration

    • Imports switched to github.com/dgraph-io/dgraph; removed bufconn-based server.
    • file:// now auto-uses the embedded client; remote Dgraph connections are unchanged.
    • Bumped Dgraph v25 dependency and updated README links and WithValidator example.

Written for commit 20b9f97. Summary will update on new commits.

Major refactoring to replace the old embedded server implementation with the new
Dgraph v25 embedded client architecture, providing better performance and
stability for in-process deployments.

**Breaking Changes:**
- Replaced `buf_server.go` with new `embedded_client.go` implementation
- Updated all import paths from `github.com/hypermodeinc/dgraph` to `github.com/dgraph-io/dgraph`
- Client initialization now uses the new embedded client architecture

**New Features:**
- Add comprehensive validation support using `github.com/go-playground/validator/v10`
- New `WithValidator()` client option for custom validation rules
- Validation integrated into Insert, Update, and Upsert operations
- Support for custom validation functions and struct tags

**Enhanced Test Coverage:**
- Added `validate_test.go` with comprehensive validation test suite
- Enhanced `update_test.go` and `upsert_test.go` with more test cases
- Improved error handling and edge case testing
- Added tests for custom validation rules and partial validation failures

**Dependency Updates:**
- Updated Dgraph dependencies to v25 stable release
- Upgraded Go modules to latest stable versions
- Updated gRPC to v1.78.0 for better performance
- Refreshed all indirect dependencies for security and stability

**Performance Improvements:**
- Optimized embedded client connection handling
- Improved mutation performance with better error handling
- Enhanced query execution with the new embedded client

**Bug Fixes:**
- Fixed import paths for Dgraph v25 compatibility
- Resolved connection issues in embedded mode
- Improved error messages for validation failures
- Fixed test cases that were assuming order in assertions

**Documentation:**
- Updated README.md with new embedded client usage examples
- Clarified connection string formats for file vs Dgraph URIs
- Added validation examples and best practices

This migration provides a more stable foundation for embedded deployments
while maintaining full backward compatibility for remote Dgraph connections.
Copy link
Copy Markdown

@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.

3 issues found across 34 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="engine.go">

<violation number="1" location="engine.go:553">
P2: The `commitOrAbort` function always uses `engine.db0` (default namespace) instead of the namespace associated with the transaction. When `embeddedDgraphClient.CommitOrAbort` calls this method, the client's namespace (`c.ns`) is ignored, which could cause commits to target the wrong namespace in multi-namespace scenarios.</violation>
</file>

<file name="README.md">

<violation number="1" location="README.md:165">
P3: The heading lists `WithValidator(Validator)`, but the API expects a `StructValidator` (or *validator.Validate implementing it). This mismatch can mislead users about the correct type. Rename the heading to match the actual interface.</violation>
</file>

<file name="client.go">

<violation number="1" location="client.go:276">
P2: Ignoring errors from `engine.GetNamespace` can leave `ns` nil, which will panic when the embedded client calls `c.ns.ID()` for an invalid/unknown namespace. Return the namespace lookup error instead of discarding it.</violation>
</file>

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

Copy link
Copy Markdown

@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 6 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:444">
P3: The test only asserts when err != nil, so invalid namespaces can pass silently if NewClient returns nil. Always assert an error (after handling the singleton skip) to avoid false negatives.</violation>
</file>

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

@matthewmcneely matthewmcneely merged commit 3d642db into main Feb 13, 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