You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(graphql): check required fields on new nested nodes without XID - #9892
A deep set update (or add) can create a new nested node that has no XID and no ID. Such a node was written without checking !-typed fields, because EnsureNonNulls ran only on the branch that creates a new node from an XID. The ...Ref input types make every field optional, so the schema did not catch it either, and a node missing a required field was stored.
This change calls EnsureNonNulls on the new-node path too, excluding the @hasInverse field set from the parent, the same way the XID branch does. The top-level update case still returns earlier and is not affected.
Added a rewriting test in update_mutation_test.yaml: updateAuthor with set: {posts: [{text: ...}]} now fails with type Post requires a value for field title, but no value present.
Checked with go test ./graphql/resolve ./graphql/schema. Without the fix, the new test fails (Expected value not to be nil); with it, both packages pass.
Checklist
The PR title follows the Conventional Commits syntax, leading
with fix:, feat:, chore:, ci:, etc.
Tests added for new functionality, or regression tests for bug fixes added as applicable
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.
Summary by CodeRabbit
Bug Fixes
Updates now report an error when a newly added nested post is missing its required title, rather than proceeding with the incomplete post.
No actionable comments were generated in the recent review.
Walkthrough
The mutation rewriter now checks required fields when it creates a nested reference-input node. A new update-mutation test checks that rewriting fails when a nested Post does not include its required title.
Changes: Nested update validation
Layer / File(s)
Summary
Validate required fields before creating nested nodes graphql/resolve/mutation_rewriter.go, graphql/resolve/update_mutation_test.yaml
The rewriter excludes the inverse field from required-field validation and returns an error when validation fails. The test checks a nested Post without a title.
Deep set updates that create nested nodes without an ID or XID now fail when required fields are missing, instead of storing incomplete records. Valid inputs are unaffected, and a regression test covers the case. No merge-blocking risk was found.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title names the main change: adding required-field validation (EnsureNonNulls) on nested nodes created without an XID or ID. The raw summary and objectives confirm this matches the mutation_rewrit…
Linked Issues check
Issue #8781 requires that a deep update creating a nested object fail when required field values are missing from the input. The whole-PR diff (merge base to head) confirms the change in graphql/resol…
Out of Scope Changes check
The whole-PR diff contains two hunks. The first is an 11-line addition in graphql/resolve/mutation_rewriter.go that adds the EnsureNonNulls check on the new-node path of rewriteObject, which implement…
Full details: Title check
Explanation
The title names the main change: adding required-field validation (EnsureNonNulls) on nested nodes created without an XID or ID. The raw summary and objectives confirm this matches the mutation_rewriter.go change and the new YAML regression test. The title follows the conventional fix(scope) form and is specific enough for a reviewer scanning history.
Full details: Linked Issues check
Explanation
Issue #8781 requires that a deep update creating a nested object fail when required field values are missing from the input. The whole-PR diff (merge base to head) confirms the change in graphql/resolve/mutation_rewriter.go, rewriteObject, on the new-node path (the branch after the XID lookup, before newObj["dgraph.type"] is set). The code computes exclude from srcField.Inverse() when srcField is non-nil, calls typ.EnsureNonNulls(obj, exclude), and on error appends the error and returns without creating the node. This addresses the issue example: a nested Member without id or XID, missing the required nickname, now fails. The whole-PR diff of graphql/resolve/update_mutation_test.yaml adds a regression case: updateAuthor with set: {posts: [{text: ...}]} expects the error 'type Post requires a value for field title, but no value present'. The top-level update path returns earlier and is unchanged, as the PR description states. The PR description reports the test fails without the fix; the test was not executed in this review. The AI-generated summary says no check runs when srcField is nil. The diff shows the check runs in that case with an empty exclude. This review uses the diff, so the summary is not relied on for this point. Automated tests in the PR cover the change.
Full details: Out of Scope Changes check
Explanation
The whole-PR diff contains two hunks. The first is an 11-line addition in graphql/resolve/mutation_rewriter.go that adds the EnsureNonNulls check on the new-node path of rewriteObject, which implements the #8781 objective. The second is a 22-line YAML regression test in graphql/resolve/update_mutation_test.yaml that exercises that path. No unrelated refactoring, documentation, or API changes appear in the reviewed diffs. The check also applies to top-level calls where srcField is nil. It only rejects inputs that omit required fields, which matches the issue intent, so it does not appear to be an unrelated behavior change. Evidence limit: the surrounding code and other callers of rewriteObject were not inspected, so the effect on other mutation paths is not fully verified.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
File: No configuration file from this repository applied
Commit: Unavailable
Layers: defaults
Review profile: CHILL
Plan: Advanced
Run ID: 78c7db12-ce37-47b8-83e3-7797fd941555
Commits
Reviewing files that changed from the base of the PR and between bd09f1b and 4379969.
Files selected for processing: 1
graphql/resolve/update_mutation_test.yaml
Files skipped from review as they are similar to previous changes: 1
graphql/resolve/update_mutation_test.yaml
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #8781.
A deep
setupdate (or add) can create a new nested node that has no XID and no ID. Such a node was written without checking!-typed fields, becauseEnsureNonNullsran only on the branch that creates a new node from an XID. The...Refinput types make every field optional, so the schema did not catch it either, and a node missing a required field was stored.This change calls
EnsureNonNullson the new-node path too, excluding the@hasInversefield set from the parent, the same way the XID branch does. The top-level update case still returns earlier and is not affected.Added a rewriting test in
update_mutation_test.yaml:updateAuthorwithset: {posts: [{text: ...}]}now fails withtype Post requires a value for field title, but no value present.Checked with
go test ./graphql/resolve ./graphql/schema. Without the fix, the new test fails (Expected value not to be nil); with it, both packages pass.Checklist
Conventional Commits syntax, leading
with
fix:,feat:,chore:,ci:, etc.Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.Summary by CodeRabbit