Sure @anand,
Here is the snippet. Please ignore any syntax errors since this is not the exact same code (we use utilities to wrap core pygraph functions) but the logic is effectively the same.
import pydgraph
client_stub = pydgraph.DgraphClientStub.from_slash_endpoint(f"{slash_url}/graphql", api_key)
client = pydgraph.DgraphClient(client_stub)
obj = [
{
"uid": "_:helloworldarticle",
"Article.title": "Hello World",
"Article.product": {"uid": "0x1234"},
"dgraph.type": "Article",
},
{
"uid": "_:pingpongarticle",
"Article.title": "Ping Pong",
"Article.product": {"uid": "0x1234"},
"dgraph.type": "Article",
},
{
"uid": "0x1234",
"Product.articles": [
{"uid": "_:helloworldarticle"},
{"uid": "_:pingpongarticle"}
]
}
]
txn = client.txn()
try:
response = txn.mutate(set_obj=obj, commit_now=True)
except pydgraph.AbortedError as e:
logger.error(e)
finally:
txn.discard()
Please note that the exact same code/logic works fine when using a dgraph local image.