Skip to content

Specify identifying columns on nested mutation upserts#2426

Merged
spawnia merged 37 commits intonuwave:masterfrom
GavG:upsert_fields_directive
Feb 14, 2026
Merged

Specify identifying columns on nested mutation upserts#2426
spawnia merged 37 commits intonuwave:masterfrom
GavG:upsert_fields_directive

Conversation

@GavG
Copy link
Contributor

@GavG GavG commented Jul 28, 2023

Resolves #2214

  • Added or updated tests
  • Documented user facing changes
  • Updated CHANGELOG.md

Changes

Adds optional identifyingColumns arg to upsert directive

Breaking changes

None

@spawnia spawnia changed the title Upsert fields directive Specify identifying columns on nested mutation upserts Aug 8, 2023
Copy link
Collaborator

@spawnia spawnia left a comment

Choose a reason for hiding this comment

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

Implementation and test make sense so far, after some tweaks I am fine with adding this.

@spawnia spawnia added the enhancement A feature or improvement label Aug 8, 2023
@GavG
Copy link
Contributor Author

GavG commented Aug 26, 2023

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.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 identifyingColumns to @upsert and @upsertMany and plumb it into UpsertModel lookup 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.

spawnia and others added 7 commits February 11, 2026 15:34
This reverts commit 0b8eb5a8c767040e3d99b7d7dd3df0490a7d2769.
…overage""

This reverts commit 7e1d342afb107f3d490c6f56c8d142e993e75915.
This reverts commit 879f638805c467214ccb077466e470a1cdb9c58e.
…rt_fields_directive

# Conflicts:
#	tests/Integration/Schema/Directives/UpsertDirectiveTest.php
#	tests/Integration/Schema/Directives/UpsertManyDirectiveTest.php
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

@spawnia
Copy link
Collaborator

spawnia commented Feb 11, 2026

@copilot open a new pull request to apply changes based on the comments in this thread

@spawnia spawnia marked this pull request as ready for review February 11, 2026 17:31
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 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".

@spawnia spawnia merged commit 96dc24a into nuwave:master Feb 14, 2026
62 checks passed
@spawnia
Copy link
Collaborator

spawnia commented Feb 14, 2026

Released with https://github.com/nuwave/lighthouse/releases/tag/v6.65.0, please consider sponsoring.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement A feature or improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

updateOrCreate functionality

3 participants

Comments