Pass Idiomatic graphQL+- through Dgo - RPC

Hi there,
I am prototyping with dragph.
I am doing a Go server API that will pass my front app’s request the most directly to dgraph.
My GO API will then perform some user credential / rights scoping on the request and then send the json back to the front APP.

Basically APP-> http (graphql± request) → My GO API → rpc → Dgraph (and back :wink: )

I have been using the DGO RPC example (GitHub - dgraph-io/dgo: Official Dgraph Go client).
Also is there a way to pass IDIOMATIC graphQL± through RPC ??

For now the example does things like :

pb, err := json.Marshal(p)
if err != nil {
mu := &api.Mutation{
SetJson: pb,
res, err:= txn.Mutate(ctx, mu)

If I want on the App side to pass this request for example :

curl -H "Content-Type: application/rdf" localhost:8080/mutate?commitNow=true -XPOST -d $'
  set {
   _:luke <name> "Luke Skywalker" .
   _:luke <dgraph.type> "Person" .
   _:leia <name> "Princess Leia" .
   _:leia <dgraph.type> "Person" .
   _:han <name> "Han Solo" .
   _:han <dgraph.type> "Person" .
   _:lucas <name> "George Lucas" .
   _:lucas <dgraph.type> "Person" .
   _:irvin <name> "Irvin Kernshner" .
   _:irvin <dgraph.type> "Person" .
   _:richard <name> "Richard Marquand" .
   _:richard <dgraph.type> "Person" .

   _:sw1 <name> "Star Wars: Episode IV - A New Hope" .
   _:sw1 <release_date> "1977-05-25" .
   _:sw1 <revenue> "775000000" .
   _:sw1 <running_time> "121" .
   _:sw1 <starring> _:luke .
   _:sw1 <starring> _:leia .
   _:sw1 <starring> _:han .
   _:sw1 <director> _:lucas .
   _:sw1 <dgraph.type> "Film" .

   _:sw2 <name> "Star Wars: Episode V - The Empire Strikes Back" .
   _:sw2 <release_date> "1980-05-21" .
   _:sw2 <revenue> "534000000" .
   _:sw2 <running_time> "124" .
   _:sw2 <starring> _:luke .
   _:sw2 <starring> _:leia .
   _:sw2 <starring> _:han .
   _:sw2 <director> _:irvin .
   _:sw2 <dgraph.type> "Film" .

   _:sw3 <name> "Star Wars: Episode VI - Return of the Jedi" .
   _:sw3 <release_date> "1983-05-25" .
   _:sw3 <revenue> "572000000" .
   _:sw3 <running_time> "131" .
   _:sw3 <starring> _:luke .
   _:sw3 <starring> _:leia .
   _:sw3 <starring> _:han .
   _:sw3 <director> _:richard .
   _:sw3 <dgraph.type> "Film" .

   _:st1 <name> "Star Trek: The Motion Picture" .
   _:st1 <release_date> "1979-12-07" .
   _:st1 <revenue> "139000000" .
   _:st1 <running_time> "132" .
   _:st1 <dgraph.type> "Film" .

I am new to dgraph, for now my feeling is like I have to do everything in http and not use DGO lib … really wondering.

If you wanna send RDF format just use txn.Mutate(ctx, mu). It accepts JSON (if so) and RDF. In case of RDF you use SetNquads and DeleteNquads instead of SetJson.

source GitHub - dgraph-io/dgo: Official Dgraph Go client

Thanks @MichelDiz for the answer on passing JSON,

I am progressing in my prototype, I think what I need is a way to read and modify the request when they are on my API (for validation purpose etc…).

Also it seems that I would have to manipulate strings there. Which is very un-convenient and error prone.

For example someone has tried to make a lib for this purpose here : GitHub - udacity/graphb: GraphQL Query Builder for Go
But it ends up beeing more complicated …

My understanding is that graphql requests are abstract syntax trees (AST) …

Therefore is there a golang lib to manipulate graphql as abstract syntax trees ???

Dunno, but is not hard to do so as far as I can tell. I had worked some time ago with graphql AST using JavaScript. It is easy as the AST is just an “object”. In JS is easy to manipulate the AST, but I have no idea of how to do the same with Go.


Hi there,
Still cannot find a way to marshall / unmarshall easily graphql requests in Golang.

I found this one that lets you create a request from scratch, but doesn t let you marshall the text request to idiomatic GO : graphb/three_ways_to_construct_query_test.go at 912b8fd361d78e00687f934aace09cf8eb054449 · udacity/graphb · GitHub

I found a way to mutate with JSON, so I can easily manipulate JSON in GO (when I receive the request from my API in Go) :

BUT there is no clue how to manipulate a request (marshall / unmarshall)??
Any help ?

Something that would look like (this doesn t work) :

curl -H "Content-Type: application/json" -X POST localhost:8080/**QUERY**?commitNow=true -d $'
  me(func:allofterms(name, "Star Wars")) @filter(ge(release_date, "1980")) {
    director {
    starring {

Humm, I’m confused.

You had talked about Graphql’s AST. Dgraph has no AST. Only Graphql has it. Graphl+- works differently under the hood.

Can you clarify this?

We use this one (indirectly) GitHub - vektah/gqlparser: A port of the parser from graphql-js into golang