Help! shortestpath Query Structure?

Hello forums… thanks for any assistance you could provide.

I am attempting to build a query that produces the shortest path between a specific node Skill S and any other node of a specific type “Resource”. I’d also like to return the SUM(resistance) facet value for any given path: this is the criteria for minimization.

Here’s an example query between two individual nodes. Could anyone please help me to modify the DQL to produce a query that returns the paths between Skill S and any node of type Resource?

{

S as var(func: eq(XID, "Skill/NAICS/523930"))
R1 as var(func: eq(XID, "Resource/bob_smith"))

path as shortest(from: uid(S), to: uid(R1), numpaths: 1) {
  Skill.Skills @facets(resistance)
  Skill.Organizations @facets(resistance)
  Organization.Projects @facets(resistance)
  Project.ProjectRoles @facets(resistance)
  ProjectRole.Resource @facets(resistance)
}

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

}

Are they linked anyway? If so, they should appear in the result. But why so many edges?

Thank you for the reply, Michel.

A1: All the links seem to work well and I can execute the query perfectly between individual Skill and Resource nodes (see code block):

{

   S as var(func: eq(XID, "Skill/NAICS/54"))
   R1 as var(func: eq(XID, "Resource/bob/smith"))

   path as shortest(from: uid(S), to: uid(R1), numpaths: 1) {
      Skill.Skills @facets(resistance)
      Skill.Organizations @facets(resistance)
      Skill.Resources @facets(resistance)
      Organization.Projects @facets(resistance)
      Project.ProjectRoles @facets(resistance)
      ProjectRole.Resource @facets(resistance)
    }
  
  path(func: uid(path)) {
   dgraph.type
   Name
   XID
  }
}

A2: I’m traversing across many different types and predicates (see diagram below), though most the edges with resistance are purposefully one-directional.

Here’s my question, now:
I’m attempting to return all Resource (0…N) nodes that can be related to a single Skill node, S. Here’s what I have so far and it’s not working. There’s something about DQL execution or syntax that I’m missing (see code block):

{
  S as var(func: eq(XID, "Skill/NAICS/54"))

var(func: eq(dgraph.type,"Resource")) {
    uid
    path as shortest(from: uid(S), to: uid, numpaths: 1) { 
      Skill.Skills @facets(resistance)
      Skill.Resources @facets(resistance)
      Skill.Organizations @facets(resistance)
      Organization.Projects @facets(resistance)
      Project.ProjectRoles @facets(resistance)
      ProjectRole.Resource @facets(resistance)
    }
    
    path(func: uid(path)) {
     Name
     XID
    } 
  }
}

This query results in an error message: “line 8 column 30: Expecting argument name. Got: lex.Item [11] “(” at 8:30”, which appears to be in the shortest function line of code.

Thank you again for any advice you could offer.
JK

Okay, I think I see a problem with my query: there is no single uid passing into shortest since the context is still all Resource nodes.

Seems like this is a good example of requiring foreach functionality, which to my understanding does not yet exist in DQL.

Is there any other query approach other than:

  1. Query all Resources;
  2. Outside of DQL iterate through all Resources;
  3. Iteratively Call the shortest path query for each Resource?

For now only Lambda is available. Not sure if we gonna implement loops(e.g. foreach), time will tell.

BTW, I’ll still check your response. I didn’t have time to focus and analyze it.

This block is wrong. There’s no such a syntax in DQL. You have two roots params applied. They should be two different blocks. Something like

{

  S as var(func: eq(XID, "Skill/NAICS/54"))
  T as var(func: eq(dgraph.type,"Resource"))

    

  path as shortest(from: uid(S), to: uid(T), numpaths: 1) { 
      Skill.Skills @facets(resistance)
      Skill.Resources @facets(resistance)
      Skill.Organizations @facets(resistance)
      Organization.Projects @facets(resistance)
      Project.ProjectRoles @facets(resistance)
      ProjectRole.Resource @facets(resistance)
    }
    
    path(func: uid(path)) {
     Name
     XID
    } 
  
}

But I don’t think it is possible to do a shortest path for many possible resources nodes.