Prisma1: Improve upsertNode function by allowing arithmetic modifications in the update part

Created on 16 Mar 2018  路  2Comments  路  Source: prisma/prisma1

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
       }
    }
  )
}

Most helpful comment

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.

All 2 comments

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

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hoodsy picture hoodsy  路  3Comments

nikolasburk picture nikolasburk  路  3Comments

schickling picture schickling  路  3Comments

sorenbs picture sorenbs  路  3Comments

akoenig picture akoenig  路  3Comments