# Confused: can you use upsert block in Dgraph Cloud?

**URL:** <https://discuss.dgraph.io/t/confused-can-you-use-upsert-block-in-dgraph-cloud/15658>\
**Category:** Dgraph\
**Created:** [September 25, 2021, 9:36am UTC](https://discuss.dgraph.io/t/confused-can-you-use-upsert-block-in-dgraph-cloud/15658 "2021-09-25T09:36:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Raiva](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/michael_raiva/32/7648_2.png) [@Michael\_Raiva](https://discuss.dgraph.io/u/Michael_Raiva)\
**Post date:** [September 25, 2021, 9:36am UTC](https://discuss.dgraph.io/t/confused-can-you-use-upsert-block-in-dgraph-cloud/15658/1 "2021-09-25T09:36:50Z")

</div>

I am looking for an example of how to implement upsert blocks in Dgraph Cloud. Is that even possible?

I am using:

type Query {

queryUpdateLikes(id: String!): [PetSummary] @custom(dql:"""

upsert {  
query q($id: string){  
var(func: uid($id) ) {  
old: A as var.val  
new: B as math(A+1)  
}  
}

mutation {  
# we copy the values from the old predicate  
set {  
uid(v) val(a) .  
}

}  
}  
“”")  
}

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![MichelDiz](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/micheldiz/32/11873_2.png) [@MichelDiz](https://discuss.dgraph.io/u/MichelDiz)\
**Post date:** [September 25, 2021, 3:37pm UTC](https://discuss.dgraph.io/t/confused-can-you-use-upsert-block-in-dgraph-cloud/15658/2 "2021-09-25T15:37:21Z")

</div>

As far as I know, it is not possible to do mutations/upsert block in GraphQL(not just the cloud). You may have to do a lambda query.

---

<div class="post-metadata">

**Author:** ![jdgamble555](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/jdgamble555/32/7503_2.png) [@jdgamble555](https://discuss.dgraph.io/u/jdgamble555)\
**Post date:** [September 25, 2021, 7:31pm UTC](https://discuss.dgraph.io/t/confused-can-you-use-upsert-block-in-dgraph-cloud/15658/3 "2021-09-25T19:31:03Z")

</div>

You can do an **upsert** as far as getting the **ID** (but not @id type) of a node and **updating** it based on that id. See [here](https://dgraph.io/docs/graphql/mutations/upsert/#blog).

However, it looks like you’re trying to change the nodes based on their current values, which cannot be done in GraphQL, as you do need to save the **var** somewhere.

Either do it on the client side, or use a [lambda mutation](https://dgraph.io/docs/graphql/lambda/mutation/) or a [lambda webhook](https://dgraph.io/docs/graphql/lambda/webhook/) with **dql** , as those are currently your only two options.

J

---

<div class="post-metadata">

**Author:** ![Michael\_Raiva](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/michael_raiva/32/7648_2.png) [@Michael\_Raiva](https://discuss.dgraph.io/u/Michael_Raiva)\
**Post date:** [September 26, 2021, 2:27am UTC](https://discuss.dgraph.io/t/confused-can-you-use-upsert-block-in-dgraph-cloud/15658/4 "2021-09-26T02:27:40Z")

</div>

Thank you. I am trying to implement a Like counter on a Post and worry that doing it on the client side might not result in accurate count if multiple users are liking the post.

I will look into lambda option in the hope that I can get ACID transactions from that.

Thank you.

---

<div class="post-metadata">

**Author:** ![jdgamble555](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/jdgamble555/32/7503_2.png) [@jdgamble555](https://discuss.dgraph.io/u/jdgamble555)\
**Post date:** [September 26, 2021, 2:53am UTC](https://discuss.dgraph.io/t/confused-can-you-use-upsert-block-in-dgraph-cloud/15658/5 "2021-09-26T02:53:57Z")

</div>

Ok, there are currently no **before** triggers, so you have to create a [custom lambda mutation](https://dgraph.io/docs/graphql/lambda/mutation/) for that.

Basically block your normal graphql **likes** node with something like [DENIED](https://dgraph.io/docs/graphql/lambda/mutation/), then use **dql** within the lambda to update the count based on the userId.

J
