Creating a GO API that can handle queries and mutations from HTTP requests

Hey ArrowHeadDev,

you basically have to put correct jsons as mutations, and it will work.

So when you have a http endpoint mutation like:

{
    "set": [
        {
            "uid": "_:new",
            "dgraph.type": "Element",
            "elementName": "Test"
        }
    ]
}

You have to change it to:

SetMutation := `
	{
		"uid": "_:new",
		"dgraph.type": "Element",
		"elementName": "Test"
	}
`

And pass this to the request, and it should work.

I wanted a more streamlined approach for doing this, so I wrote a simple wrapper pkg for dgo. Still a work in progress, but hope you can get some inspiration from it. GitHub - ppp225/ndgo: ndgo is a dgraph dgo wrapper. Provides abstractions and helper functions.

Using ndgo, you could run the above using resp, err := txn.Set(SetMutation)

2 Likes