Specify identifying columns on nested mutation upserts#2426
Specify identifying columns on nested mutation upserts#2426spawnia merged 37 commits intonuwave:masterfrom
Conversation
spawnia
left a comment
There was a problem hiding this comment.
Implementation and test make sense so far, after some tweaks I am fine with adding this.
|
Thanks for the review @spawnia. Sorry I've been a bit quiet on this, recently had our first child so haven't had any free time 🙃 I've been giving the solution a bit more thought, I think supporting nested relationship upsert logic is a must, so I'll try and tackle that when I come to making the suggest changes. I've also been considering my own use case again, where more complex upsert logic was required, and I think a cleaner solution to this might be to permit the specifying of a custom query class that would receive the input params in place of the package's query logic. I may have a go at this in a new fork later. |
…tive # Conflicts: # CHANGELOG.md # src/Execution/Arguments/UpsertModel.php
There was a problem hiding this comment.
Pull request overview
This PR extends Lighthouse’s @upsert / @upsertMany directives with an optional identifyingColumns argument and tightens nested upsert behavior by scoping lookups to the parent relation (preventing updates to unrelated models during nested mutations).
Changes:
- Add
identifyingColumnsto@upsertand@upsertManyand plumb it intoUpsertModellookup logic. - Scope nested upsert lookups to the parent relation and error when attempting to upsert a model that exists but is not related to the parent.
- Add/adjust integration tests, update docs, and update the changelog.
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Schema/Directives/UpsertDirective.php | Adds identifyingColumns directive arg; validates it isn’t an empty list; passes it into UpsertModel. |
| src/Schema/Directives/UpsertManyDirective.php | Same as @upsert, but for multi-upsert. |
| src/Execution/Arguments/UpsertModel.php | Implements identifying-columns lookup; scopes nested lookups via parentRelation; introduces explicit GraphQL error messages. |
| src/Execution/Arguments/NestedOneToOne.php | Passes relation into UpsertModel to enforce scoped nested lookups. |
| src/Execution/Arguments/NestedOneToMany.php | Same scoping change for one-to-many nested upserts. |
| src/Execution/Arguments/NestedManyToMany.php | Same scoping change for many-to-many nested upserts. |
| src/Execution/Arguments/NestedBelongsTo.php | Same scoping change for belongs-to nested upserts. |
| tests/Integration/Schema/Directives/UpsertDirectiveTest.php | Adds coverage for identifyingColumns, empty-list validation, and unrelated nested upsert protection. |
| tests/Integration/Schema/Directives/UpsertManyDirectiveTest.php | Adds coverage for identifyingColumns for @upsertMany, including validation and nested protections. |
| tests/Integration/Execution/MutationExecutor/*Test.php | Expands coverage across relation types to ensure nested upserts cannot modify unrelated models. |
| docs/master/eloquent/getting-started.md | Documents identifyingColumns usage for @upsert. |
| docs/master/api-reference/directives.md | Documents identifyingColumns for both @upsert and @upsertMany, including lookup precedence. |
| CHANGELOG.md | Adds entries for identifying columns and scoped nested upsert lookups. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This reverts commit 0b8eb5a8c767040e3d99b7d7dd3df0490a7d2769.
This reverts commit 6e6aa17.
…overage"" This reverts commit 7e1d342afb107f3d490c6f56c8d142e993e75915.
This reverts commit 879f638805c467214ccb077466e470a1cdb9c58e.
tests/Integration/Schema/Directives/UpsertManyDirectiveTest.php
Outdated
Show resolved
Hide resolved
Removed the 'Changed' section from the CHANGELOG.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@copilot open a new pull request to apply changes based on the comments in this thread |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 431f6ef770
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Released with https://github.com/nuwave/lighthouse/releases/tag/v6.65.0, please consider sponsoring. |
Resolves #2214
Changes
Adds optional identifyingColumns arg to upsert directive
Breaking changes
None