Anyone have example of an upsert using python client and js object format?

I’ve been able to add, but I was using JS Object format.

addGame = {
    "uid" : "_:newNode",
    "Game.prize": 100, 
    "dgraph.type": "Game"
  }

txn = client.txn()
res = txn.mutate(set_obj=addState)
txn.commit()
txn.discard()
client_stub.close()

When I try to change things though, is where I run into issues.
(But I think I figured it out based on your example, see below)

One thing I find confusing is the inconsistent use of JS Object format and RDF in the docs. It would be nice if all examples had both. I was using JS Object exclusively, but then started using RDF as that’s what more of the examples were showing.

This was my code

try:
  txn = client.txn()
  mutation = txn.create_mutation(set_nquads='<0x1fbd2> <prize> "15" .')
  request = txn.create_request(query=query, mutations=[mutation], commit_now=True)
  print(txn.do_request(request))
except Exception as e:
  print(e)
finally:
  txn.discard()
  client_stub.close()

I tried doing <Game.prize> and that solved my problem (based on you specifying type in your examples). The examples don’t make this clear.

I’ve spent so much time on this and then the tour not working, yet it was a very simple change. Was losing my mind.

What is that period at the end of the statements?

@acarey this is a good idea and should be feasable to some extent.

The DQL docs mostly predate Slash and there was no need to make examples with type dotted predicates. I believe this is covered elsewhere in the docs but not sure exactly where atm without searching.

Happens to me all the time as well!

The period is rdf syntax indicating end of statement. It is possible to have more than a single value in rdf as is used in the upcoming namespace implementation where the 4th item in the rdf will be the namespace.

1 Like

Thanks so much, this indirectly solved my problem.

I think this was a large part of my problem. Most of the adjustments I had to make were the result of this.

1 Like

@billybobthorton, we are happy that the problem got solved.

Thanks @verneleem for pitching in.

We have noted down feedback regarding documentation. Its true that DQL docs predate Slash docs. We have been working on restructuring docs recently to address some of these issues.

I am sorry for this. What I meant to say is that GraphQL prize is equivalent to DQL User.prize .

Relevant Docs : https://dgraph.io/docs/migration/graphql-dgraph/#mapping-graphql-to-a-dgraph-schema

2 Likes