Is it possible to achieve transitive relationship

The structure looks like below

type Story @dgraph(type: "Story") {
  id : ID!
  name : String! @search(by: [term]) @dgraph(pred: "name")
  description : String @search @dgraph(pred: "description")
  characters : [Character] @dgraph(pred: "characters")
  locations : [Location] @dgraph(pred: "locations")
}

type Character @dgraph(type: "Character") {
  id : ID!
  name : String! @search(by: [term]) @dgraph(pred: "name")
  description : String @search @dgraph(pred: "description")
  visited : [Location] @hasInverse(field: visitors) @dgraph(pred: "visited")
  has_stories : [Story] @hasInverse(field: characters) @dgraph(pred: "has_stories")
}

type Location @dgraph(type: "Location") {
  id : ID!
  name : String! @search(by: [term]) @dgraph(pred: "name")
  description : String @search @dgraph(pred: "description")
  visitors : [Character] @dgraph(pred: "visitors")
  has_stories : [Story] @hasInverse(field: locations) @dgraph(pred: "has_stories")
}
  • A story is added.
  • A character is added to the story
  • Characters visits locations (Location is created )

So, when we look for locations in stories, we have to traverse via

stories -> characters -> visited

We were expecting the same result with the below relationship

stories -> locations

as locations are linked to characters and characters are linked to the stories

Welcome @maddygoround!

The traversals work on the basis of the data asserted in dgraph. If the stories -> characters -> visited chain is asserted, then that’s what the queries will reflect. Thus, if we have not expressly established the stories -> locations link, the queries cannot pick it up directly and will have to go through the characters node. I understand that you expect that the location is “inferred” by some mechanism, but that capability does not exist in Dgraph yet.

Thanks for the quick reply.