Update using GrahpQL

Hello everyone,

I’ve got several questions regarding “update” mutation. I have a setup, where most of the transactions will be “update mutation” & simple queries. First step is to add some nodes & relationships, second one is to update & query them very frequently, but I’ve found several issues regarding the update:

  1. I’ve found out that dGraph doesn’t support update of multiple nodes at once (Cannot update multiple nodes at once). I would like to update nodes 30-50 times per second. Some of the nodes will get 5 updates & some of them will get 1 update. If there is a way to achieve this, I would like to know how (whether it is DQL or GraphQL).
  2. I’ve tested Subscriptions directive, it works fine, but the update mutation doesn’t trigger the query subscription (addType & deleteType trigger the query normally). Here is the code, I’ve used:

Schema:

type Sensor @withSubscription {
    id: ID!
    xid: String! @id @search
    value: Int @search
    timestamp: DateTime
    unit: String
}

Subscription code:

from python_graphql_client import GraphqlClient

client = GraphqlClient(endpoint="ws://localhost:8080/graphql", verify=False)

query = """subscription testSubscription {
  querySensor {
    xid
  }
}

"""

# Asynchronous request
import asyncio

asyncio.run(client.subscribe(query=query, handle=print))

Add/update/delete code:

from python_graphql_client import GraphqlClient

client = GraphqlClient(endpoint="http://localhost:8080/graphql")

addSensor= """mutation MyMutation {
  addSensor(input: {xid: "customSensor", value: 10, timestamp: "2023-02-22T09:49:57Z", unit: "C", type: "temperature"}) {numUids}
}"""

updateSensor = """mutation MyMutation {
  updateSensor(input: {filter: {xid: {allofterms: "customSensor"}}, set: {value: 10}}) {numUids}
}"""

deetelSensor = """mutation MyMutation {
  deleteSensor(filter: {xid: {allofterms: "customSensor"}}) {
    numUids
  }
}
"""

data = client.execute(query=updateSensor)

Thanks in advance!

With regard to the subscription on update issue:

  1. the query result block needs to include values that are part of the mutation.

    subscription testSubscription {
        querySensor {
            xid
            value # this!!!
        }
    }
    

    this is useful for monitoring only some predicates that are changed.

  2. the update will need to effect some change in order for a subscription query to fire. For instance, updating the sensor value with 10 if the existing value is 10 will not trigger the subscription query.

With regard to the “multiple node update” issue (BTW, best to separate issues into their own posts), none of the proposed changes in the post you referred to were implemented. In cases where GraphQL is lacking, it usually means it’s time to dust off that DQL manual.