Confused: can you use upsert block in Dgraph Cloud?

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.

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.

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.

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 or a lambda webhook with dql, as those are currently your only two options.

J

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.

Ok, there are currently no before triggers, so you have to create a custom lambda mutation for that.

Basically block your normal graphql likes node with something like DENIED, then use dql within the lambda to update the count based on the userId.

J