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