Skip to content

fix: Fix neo4j driver.FetchKinds() not returning edge kinds - BED-8058#64

Merged
wes-mil merged 1 commit intomainfrom
BED-8058
Apr 17, 2026
Merged

fix: Fix neo4j driver.FetchKinds() not returning edge kinds - BED-8058#64
wes-mil merged 1 commit intomainfrom
BED-8058

Conversation

@wes-mil
Copy link
Copy Markdown
Contributor

@wes-mil wes-mil commented Apr 17, 2026

Description

Fixes neo4j driver.FetchKinds() not returning edge kinds

Resolves: BED-8058

Type of Change

  • Chore (a change that does not modify the application functionality)
  • Bug fix (a change that fixes an issue)
  • New feature / enhancement (a change that adds new functionality)
  • Refactor (no behaviour change)
  • Test coverage
  • Build / CI / tooling
  • Documentation

Testing

  • Unit tests added / updated
  • Integration tests added / updated
  • Manual integration tests run (go test -tags manual_integration ./integration/...)

Screenshots (if appropriate):

FetchKinds now returns edge kinds as well!

image

Driver Impact

  • PostgreSQL driver (drivers/pg)
  • Neo4j driver (drivers/neo4j)

Checklist

  • Code is formatted
  • All existing tests pass
  • go.mod / go.sum are up to date if dependencies changed

Summary by CodeRabbit

  • New Features
    • Neo4j driver now retrieves and includes relationship types alongside labels when fetching available kinds from the database, providing a more complete view of your graph structure.

@wes-mil wes-mil self-assigned this Apr 17, 2026
@wes-mil wes-mil added the bug Something isn't working label Apr 17, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 17, 2026

Walkthrough

The FetchKinds function in the Neo4j driver now augments its retrieved kinds set by additionally executing CALL db.relationshipTypes() to include relationship types alongside the existing label retrieval via CALL db.labels(), both within the same transaction.

Changes

Cohort / File(s) Summary
Neo4j Driver Enhancement
drivers/neo4j/driver.go
Augmented FetchKinds to retrieve and include relationship types alongside labels by adding a CALL db.relationshipTypes() query within the existing read transaction.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 The kinds set grows wider, relationships in sight,
Labels AND their connections, batched in a single flight,
Through Neo4j's transaction they dance and align,
A rabbit's delight—now the graph speaks divine! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically identifies the bug fix: the neo4j driver's FetchKinds() function not returning edge kinds, with the ticket reference BED-8058.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed The pull request description follows the required template with all critical sections completed: description, issue resolution, type of change, testing, driver impact, and checklist items.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch BED-8058

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.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
drivers/neo4j/driver.go (1)

152-178: Reduce duplication and add result hygiene; verify behavior change for callers.

The db.relationshipTypes() block duplicates db.labels() verbatim. Consider extracting a helper to scan a single-column string result into kinds. Additionally, unlike Run() at line 143, neither result is explicitly Close()d; while result.Next() drains the stream, matching the pattern elsewhere in this file would be more consistent.

♻️ Suggested refactor
 func (s *driver) FetchKinds(ctx context.Context) (graph.Kinds, error) {
 	var kinds graph.Kinds
 
+	scanKinds := func(tx graph.Transaction, query string) error {
+		result := tx.Raw(query, nil)
+		defer result.Close()
+
+		if err := result.Error(); err != nil {
+			return err
+		}
+
+		for result.Next() {
+			var kind string
+			if err := result.Scan(&kind); err != nil {
+				return err
+			}
+			kinds = append(kinds, graph.StringKind(kind))
+		}
+
+		return result.Error()
+	}
+
 	if err := s.ReadTransaction(ctx, func(tx graph.Transaction) error {
-		if result := tx.Raw("CALL db.labels()", nil); result.Error() != nil {
-			...
-		}
-
-		if result := tx.Raw("CALL db.relationshipTypes()", nil); result.Error() != nil {
-			...
-		}
-
-		return nil
+		if err := scanKinds(tx, "CALL db.labels()"); err != nil {
+			return err
+		}
+		return scanKinds(tx, "CALL db.relationshipTypes()")
 	}); err != nil {
 		return nil, err
 	}
 
 	return kinds, nil
 }

Important: This PR changes FetchKinds() to return both node labels and relationship types in a single flat Kinds set, where graph.StringKind produces an undifferentiated stringKind type. Verify that all callers of FetchKinds() can handle this merged result without relying on the previous labels-only semantics (e.g., for seeding node-kind registries separately from relationship-kind registries).

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@drivers/neo4j/driver.go` around lines 152 - 178, The two blocks in FetchKinds
(inside s.ReadTransaction) duplicate logic for scanning single-column string
results from "CALL db.labels()" and "CALL db.relationshipTypes()"; extract a
helper (e.g., scanSingleColumnStrings(tx graph.Transaction, cypher string)
([]graph.Kind, error) or a helper that returns []string) used by FetchKinds to
run the query, iterate result.Next(), Scan into a string, append
graph.StringKind(kind) to kinds, and ensure you call result.Close() (or the
result's Close-like cleanup) after consuming or on error to match the existing
Run() pattern; after changing FetchKinds to return both labels and relationship
types flattened into kinds, run a quick audit of all callers of FetchKinds to
ensure they accept merged stringKind results and update any caller logic that
previously assumed labels-only semantics.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@drivers/neo4j/driver.go`:
- Around line 152-178: The two blocks in FetchKinds (inside s.ReadTransaction)
duplicate logic for scanning single-column string results from "CALL
db.labels()" and "CALL db.relationshipTypes()"; extract a helper (e.g.,
scanSingleColumnStrings(tx graph.Transaction, cypher string) ([]graph.Kind,
error) or a helper that returns []string) used by FetchKinds to run the query,
iterate result.Next(), Scan into a string, append graph.StringKind(kind) to
kinds, and ensure you call result.Close() (or the result's Close-like cleanup)
after consuming or on error to match the existing Run() pattern; after changing
FetchKinds to return both labels and relationship types flattened into kinds,
run a quick audit of all callers of FetchKinds to ensure they accept merged
stringKind results and update any caller logic that previously assumed
labels-only semantics.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: aec65ccd-a6cd-4b94-b6d3-123f508988e3

📥 Commits

Reviewing files that changed from the base of the PR and between 83df582 and 2904805.

📒 Files selected for processing (1)
  • drivers/neo4j/driver.go

Copy link
Copy Markdown
Contributor

@zinic zinic left a comment

Choose a reason for hiding this comment

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

lgtm

@wes-mil wes-mil merged commit dbdd47f into main Apr 17, 2026
4 checks passed
@wes-mil wes-mil deleted the BED-8058 branch April 17, 2026 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants