How to develop a function in go for dgraph?

(护群神兽之点赞狂魔) #1

I want to make a function named helloshortest.
I git clone the go source from dgraph repo in github.
and do some little changes .
Here is what I have done.
git status >
git_status.txt (538 Bytes)

git diff >
git_diff.txt (2.3 KB)

cat query/helloshortest.go
helloshortest.go (1.3 KB)

It works.Query like this

 foo as helloshortest(from: 0x10, to: 0x4) {
 bar(func: uid(foo)) {

with response

  "extensions": {
    "server_latency": {
      "parsing_ns": 13978,
      "processing_ns": 39104,
      "encoding_ns": 480361
    "txn": {
      "start_ts": 90008
  "data": {
    "bar": [],
    "hello shortest Path": [
        "uid": "0x10",
        "_weight_": 4

Okay, from now on, the true problem is I didn’t return a correct result.
I need to fix the code ,the function HelloShortestPath in helloshortest.go

I want to know how to deal with the graph ,what a SubGraph really means.
what does *pb.List or *pb.Query means ?
How to fetch a node 's data . or how to wallk the graph .

I need some infomation and help to complete my own helloshortest correctlly.

(Michel Conrado) #2

What version are you using? I’m v1.0.12-rc3 and I can’t run your query.
": Invalid query. No function used at root and no aggregation or math variables found in the body." cuz the keyword “shortest” is mandatory.

(护群神兽之点赞狂魔) #3

I just clone from master branch.
Thank you Michel .
I read the source code of shortest.go again and again .
Finally , I get it. Now ,I know how to complete the rest of my work.