Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add @upsert directive and nested mutation operations to create or update a model regardless whether it exists #1005

Merged
merged 32 commits into from Oct 15, 2019
Merged

Add @upsert directive and nested mutation operations to create or update a model regardless whether it exists #1005

merged 32 commits into from Oct 15, 2019

Conversation

joskfg
Copy link
Collaborator

@joskfg joskfg commented Oct 11, 2019

  • Added or updated tests
  • Added Docs for all relevant versions
  • Updated the changelog

Resolves #995

Changes

Upsert

Use the @upsert directive to update a model with
a given id or create it if it does not exist.

type Mutation {
  upsertUser(id: ID!, name: String!, email: String): User @upsert
}

Since upsert can create or update your data you must have all the minimum fields for a creation as required.
The id is always required and must be marked as fillable in the model.

mutation {
  upsertUser(id: "123" name: "Hillary"){
    id
    name
    email
  }
}
{
  "data": {
    "upsertUser": {
      "id": "123",
      "name": "Hillary",
      "email": null
    }
  }
}

Nested mutations

You can now expose a nested operation upsert in all nested mutations that support the update operation.

Breaking changes

-

@joskfg joskfg changed the title [WIP] Partial upsert implementation with BelongToMany test [WIP] Upsert implementation for nested mutations Oct 11, 2019
CHANGELOG.md Show resolved Hide resolved
joskfg and others added 2 commits October 12, 2019 20:49
Co-Authored-By: Benedikt Franke <benedikt@franke.tech>
@joskfg joskfg changed the title [WIP] Upsert implementation for nested mutations Upsert implementation for nested mutations Oct 12, 2019
@spawnia
Copy link
Collaborator

spawnia commented Oct 13, 2019

I am really impressed with how quickly you were able to dig into this and added a solid implementation with comprehensive tests, while sticking to the existing codestyle.

Apart from the doc entry in the directives reference, there is also https://lighthouse-php.com/master/eloquent/getting-started.html#update and https://lighthouse-php.com/master/eloquent/nested-mutations.html

@joskfg
Copy link
Collaborator Author

joskfg commented Oct 13, 2019

Lets reframe this so we won't have to keep updating the number

I am really impressed with how quickly you were able to dig into this and added a solid implementation with comprehensive tests, while sticking to the existing codestyle.

Apart from the doc entry in the directives reference, there is also https://lighthouse-php.com/master/eloquent/getting-started.html#update and https://lighthouse-php.com/master/eloquent/nested-mutations.html

Thanks! Added missing documentation.


$executeMutation = function () use ($model, $args): Model {
return $this->executeMutation($model, new Collection($args))->refresh();
return $this
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I prefer this indentation

@spawnia spawnia added the enhancement A feature or improvement label Oct 15, 2019
@spawnia
Copy link
Collaborator

spawnia commented Oct 15, 2019

Massive effort and great job on this cool new feature, @joskfg

Thank you!

@spawnia spawnia changed the title Upsert implementation for nested mutations Add @upsert directive and nested mutation operations to create or update a model regardless whether it exists Oct 15, 2019
@spawnia spawnia merged commit 8124bcd into nuwave:master Oct 15, 2019
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.

@upsert directive and nested mutations
2 participants