Skip to content
This repository has been archived by the owner on Sep 2, 2022. It is now read-only.

Improve upsertNode function by allowing arithmetic modifications in the update part #2101

Closed
mfts opened this issue Mar 16, 2018 · 2 comments

Comments

@mfts
Copy link

mfts commented Mar 16, 2018

Feature Request

What feature are you missing?

I would love a feature similar to what Graph.cool used to have with addTo function. Basically, when I run the function upsertNode and the node already exists, I don't want the update function to overwrite my node variables but have the option to add, subtract, multiply, or divide in case of floats and ints.

Why do I want this? Well if I already call upsertNode and my intention is to add two values, I don't want to know the value of existing node, I just care about adding my new value to it.

How could this feature look like in detail? Tradeoffs?

Consider this data model:

type User {
  id: ID! @unique
  name: String!
  numberOfLives: Int!
}

Suggestion

Add special parameters such as add, subtract, multiply, and divide as allowed update input

mutation {
  upsertUser(
    where: {
      id: "my-id"
    }
    create: {
      name: "some name"
      numberOfLives: 2
    }
    update: {
       add: { 
          numberOfLives: 2
       }
    }
  )
}
@schickling
Copy link
Member

This should be covered by #1349 (Atomic operations). @sorenbs can you confirm this will also work for upsert mutations?

@sorenbs
Copy link
Member

sorenbs commented Mar 17, 2018

That's correct. The update part of upsert mutations have the same capabilities as normal update mutations, so when this feature lands it will also work for upserts.

@sorenbs sorenbs closed this as completed Mar 17, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants