Check Edges

# Define Types

type Person {
    name
    age
    friend
    owns_pet
}

type Animal {
    name
}

# Define Directives and index

name: string @index(term) @lang .
age: int @index(int) .
friend: [uid] @count .
owns_pet: [uid] .

I want to check whether there is a edge ‘friend’ between A and c

Assuming this mutation:

{
  set{
    _:a <name> "A" .
    _:b <name> "B" .
    _:c <name> "C" .

    _:a <friend> _:b .
  }
}

If you get empty response in qry_ac, it can be concluded that there is no edge between a and c.

{
  a as var(func: eq(name, "A"))
  c as var(func: eq(name, "C"))
  b as var(func: eq(name, "B"))
	#get a to b linl  
  qry_ab(func: uid(a)) @cascade{
    uid
    friend @filter(uid(b)){
      uid
    }
  }
  #get a to c link
  qry_ac(func: uid(a)) @cascade{
    uid
    friend @filter(uid(c)){
      uid
    }      
  }
}

The response is as below.

{
  "data": {
    "qry_ab": [
      {
        "uid": "0x1",
        "friend": [
          {
            "uid": "0x2"
          }
        ]
      }
    ],
    "qry_ac": []
  }
}
2 Likes

Thanks it work out!

1 Like