dgo icon indicating copy to clipboard operation
dgo copied to clipboard

Lexing error in v2 API

Open RJKeevil opened this issue 7 months ago • 9 comments

Describe the bug

Hello, i'm in the process of moving to the v2 apis to make use of namespaces. In doing so I am getting lexing errors in queries that previously worked (and still succeed in ratel). I think the json parsing has differences.

To Reproduce

Take the following json from one of our test cases: {"set":[{"uid":"_:R_1","dgraph.type":["Record","Agg1Record"],"Record.type":"agg1","Record.updateTS":"2025-06-24T08:59:24.894369149Z","Record.identifier":"agg1:BASIC1","Record.dateTime":"2017-02-20T12:00:00Z","Record.raw":"{\"doc\":\"Aggregation Document 1\"}","Record.hash":"3bpk0kclixpif","Record.individualEntity":[{"uid":"_:E_1_1","dgraph.type":["Entity","IndividualEntity"],"IndividualEntity.updateTS":"2025-06-24T08:59:24.894369149Z","IndividualEntity.identifier":"agg1:BASIC1:1","IndividualEntity.full":true,"IndividualEntity.displayName":"Aggregate 1 High","IndividualEntity.nameNormalised":"aggregate 1 high","IndividualEntity.customNameEmbedding":"22ejj75adgi22","IndividualEntity.nameParsed":"{\"initials\":[\"a\",\"h\"],\"raw\":\"aggregate 1 high\",\"words\":[\"aggregate\",\"1\",\"high\"]}","IndividualEntity.graphEmbedding":"te1kunpmfqr8","IndividualEntity.name":"Aggregate 1 High","IndividualEntity.individualID":1}]}]}

In Ratel I get Message: Done

When passing the same string to ns.Client.RunDQL(ctx, ns.Name, mutation) I get: at line 1 column 1: Unexpected character while lexing DQL: U+0022 '\"'"

Expected behavior

The structure of a set request matched in ratel and v2 api

Environment

  • OS: amazonlinux
  • Language Go
  • Version latest master

RJKeevil avatar Jun 24 '25 09:06 RJKeevil

Ratel uses the /mutate endpoint which takes this type of json-formatted payload. When you say "previously worked", what lang/library/endpoint were you using?

matthewmcneely avatar Jun 24 '25 20:06 matthewmcneely

I was using dgo with the v1 apis over grpc, via SetJson. All my set commands are pretty much arrays of json documents, it would be great if I could also use that in v2 as there would be a lot to convert otherwise! Plus im not sure the blanknode references work the same way in RDF? It may be i can already use json in v2 but im reading the docs wrong btw.

RJKeevil avatar Jun 24 '25 21:06 RJKeevil

E.g. this doc page implies json mutations should work as I am using them https://docs.hypermode.com/dgraph/dql/json

RJKeevil avatar Jun 25 '25 08:06 RJKeevil

So, using SetJson like this:

https://github.com/hypermodeinc/dgo/blob/4a519e53fb9debc14d70dffa9680b5ce7d154d7e/example_set_object_test.go#L122

If so, note that the "set" field is not present, just the json encoded object. Hopefully, this will be moot when/if we get namespace support for v25. I'm guessing your existing code uses dg.NewTxn() as in the example_set_object_test.go file.

matthewmcneely avatar Jun 25 '25 17:06 matthewmcneely

Hi @matthewmcneely, that is that pattern i was using previously in the v1 apis. However I dont think that supports the namespace functionality, which is why I was looking for an equivalent v2 function, i.e. using RunDQL with a set of a json array. So you think instead the SetJson function will be modified to include namespaces? i.e. via your PR?

RJKeevil avatar Jun 25 '25 21:06 RJKeevil

Right, if that PR gets merged, instead of txn := client.NewTxn(), you'd use txn := client.NewTxnInNamespace("foo")

matthewmcneely avatar Jun 25 '25 23:06 matthewmcneely

Cool. I still think this Lexing issue needs fixing however, as it will confuse a lot of people that the examples in first page of the DQL docs (JSON data format) doesnt run in the RunDQL function?

I might try a PR to make the examples from the docs unit tests.

RJKeevil avatar Jun 26 '25 07:06 RJKeevil

OK ive updated the tests in a draft PR at https://github.com/hypermodeinc/dgo/pull/267, it shows the failure with a basic example and references the docs that claims this should be working. Hope this helps!

RJKeevil avatar Jun 26 '25 11:06 RJKeevil