Graph Traversal
For the purpose of the example, we'll generate the following graph:
The first step is to generate the 3 schemas: Pet
, User
, Group
.
Add the necessary fields and edges for the schemas:
ent/schema/pet.go
ent/schema/user.go
ent/schema/group.go
Let's write the code for populating the vertices and the edges to the graph:
Let's go over a few traversals, and show the code for them:
The traversal above starts from a Group
entity, continues to its admin
(edge), continues to its friends
(edge), gets their pets
(edge), gets each pet's friends
(edge), and requests their owners.
What about the following traversal?
We want to get all pets (entities) that have an owner
(edge
) that is a friend
(edge) of some group admin
(edge).
The full example exists in GitHub.