SchemaToGraph converts a schema definition into a graph representation.
()
| 21 | |
| 22 | // SchemaToGraph converts a schema definition into a graph representation. |
| 23 | func (b Builder) SchemaToGraph() (g Graph, err error) { |
| 24 | for _, entity := range b.schema.GetEntityDefinitions() { |
| 25 | eg, err := b.EntityToGraph(entity) |
| 26 | if err != nil { |
| 27 | return Graph{}, fmt.Errorf("failed to convert entity to graph: %w", err) |
| 28 | } |
| 29 | g.AddNodes(eg.Nodes()) |
| 30 | g.AddEdges(eg.Edges()) |
| 31 | } |
| 32 | for _, rule := range b.schema.GetRuleDefinitions() { |
| 33 | rg, err := b.RuleToGraph(rule) |
| 34 | if err != nil { |
| 35 | return Graph{}, fmt.Errorf("failed to convert entity to graph: %w", err) |
| 36 | } |
| 37 | g.AddNodes(rg.Nodes()) |
| 38 | } |
| 39 | return g, err |
| 40 | } |
| 41 | |
| 42 | // EntityToGraph takes an entity definition and converts it into a graph |
| 43 | // representation, returning the created graph and an error if any occurs. |
no test coverage detected