Result comes empty: shortest path between two nodes

What I want to do

  • Find shortest path between two give nodes
  • Result always comes empty

What I did

  • Below are my schema and mutations
    type Student {
      studentId: String! @id
      courses: [Course] @hasInverse(field: student)
      xid: String!  @search(by: [hash])
    }
    
    type Course {
     codeId: CourseTcode!
     eventId: Int!
     timestamp: DateTime! @search
     student: Student
     xid: String! @search(by: [hash])
    }
    
    type CourseTcode {
     codeConceptId: Int! @id
     course: [Course] @hasInverse(field: codeId)
     xid: String! @search(by: [hash])
    }
    
    <_:my.org/Student/10101/Course/201/Event/1> <Course.eventId> "1" .
    <_:my.org/Student/10101/Course/201/Event/1> <Course.timestamp> "2022-01-01T00:00:02.298240" .
    <_:my.org/Student/10101/Course/201/Event/1> <Course.student> 
    <_:my.org/Student/10101> .
    <_:my.org/Student/10101> <Student.studentId> "10101" .
    <_:my.org/Student/10101> <Student.courses> 
    <_:my.org/Student/10101/Course/201/Event/1> .
    <_:my.org/Student/10101/Course/201/Event/1> <Course.codeId> 
    <_:my.org/CourseTcode/201> .
    <_:my.org/CourseTcode/201> <CourseTcode.codeConceptId> "201" .
    <_:my.org/CourseTcode/201> <CourseTcode.course> 
    <_:my.org/Student/10101/Course/201/Event/1> .
    

Please list the things you have tried.

  • Tried to find shortest path query
    {
     p_uid as var(func: eq(Student.studentId, "10101"))
     d_uid as var(func: eq(CourseTcode.codeConceptId, "201")) 
    
     path as shortest(from: uid(d_uid), to: uid(p_uid), numpaths:2) {
      Course
     }
    
     get_path(func: uid(path)) @recurse(depth:2, loop:true) 
     {
      uid
     }  
    }
    

Dgraph metadata

dgraph version

PASTE THE RESULTS OF dgraph version HERE.

I see no Diagnosis predicate in your schema or even in the provided dataset. Maybe you should use CourseTcode.course

Sorry, that was a typo.

Its actually Course

if your dataset is right this should do the trick

{
 Student_uid as var(func: eq(Student.studentId, "10101"))
 CourseTcode_uid as var(func: eq(CourseTcode.codeConceptId, "201")) 

 path as shortest(from: uid(CourseTcode_uid), to: uid(Student_uid), numpaths:3) {
  CourseTcode.Course
  Course.student
 }

 get_path(func: uid(path))  {
  uid
 }

}

BTW, why recurse in the last block?

perfect, it works.

So, the shortest block should have what to match?

humm, your question is the basis behind the shortest path logic. The docs should cover this. In order to work, the SPath query should have all desired edges to traverse explicitly set in the query body.

The docs says

This is also true for typo or wrong predicate naming.