Hi,
is it currently possible to do atomic operations (e.g. atomic increment/decrement) on fields through GraphQL API? If so, how?
Hi,
is it currently possible to do atomic operations (e.g. atomic increment/decrement) on fields through GraphQL API? If so, how?
Not at the moment. Do you want me to convert this into a feature request? Could you explain some uses for it?
I converted this over to a feature request, I can give some use cases for this.
A voting system that needs to add one transactionally without record of who casts the vote
A simplistic social media use case where a post can have likes but liking users are not tracked, really just a deviant of the above.
A counter for IoT tool that tracks persons/things in and out. There are door greeters at stores counting heads in and out and an application in that manner would need to always be accurate between multiple doors. This is probably the most real use case atm.
References to support request:
In a single MySQL query, you can increment a value with
UPDATE store_counts
SET heads = heads + 1
WHERE store_id = ?
In MySQL it isn’t an atomic field operation. If there are two queries run at the same time, it may be trampled over
Normally, you do not need to lock tables, because all single
UPDATE
statements are atomic; no other session can interfere with any other currently executing SQL statement. However, there are a few cases when locking tables may provide an advantage…
You can avoid using
LOCK TABLES
in many cases by using relative updates (UPDATE customer SET value
=value
+new_value
) or theLAST_INSERT_ID()
function.
^ Maybe I am missing something here because I am sleep deprived.
Ah must be something new that I wasn’t aware of in MySQL (more of a Postgres guy when it comes to RDBMS)
Normally such thing would be handled by an intermediate API layer. Which is easy to do and perfectly fine.
But my impression is that Dgraph GraphQL’s goal is to get rid of intermediate layers and expose the generated API directly to clients. Therefore, features like atomic operations or maybe a generic lock ability, would be very helpful in case multiple workers are accessing the database.