Exposed load function maps in graph context constructor

graph-rework-2
noah metz 2023-07-02 09:34:36 -06:00
parent 638148afab
commit 1c6983ff4a
2 changed files with 11 additions and 3 deletions

@ -195,7 +195,7 @@ func LoadNodeRecurse(ctx * GraphContext, id NodeID, loaded_nodes map[NodeID]Grap
return node, nil
}
func NewGraphContext(db * badger.DB, log Logger, types TypeList, type_map ObjTypeMap, queries FieldMap, subscriptions FieldMap, mutations FieldMap) * GraphContext {
func NewGraphContext(db * badger.DB, log Logger, state_loads StateLoadMap, node_loads NodeLoadMap, types TypeList, type_map ObjTypeMap, queries FieldMap, subscriptions FieldMap, mutations FieldMap) * GraphContext {
gql, err := NewGQLContext(types, type_map, queries, subscriptions, mutations)
if err != nil {
panic(err)
@ -217,6 +217,14 @@ func NewGraphContext(db * badger.DB, log Logger, types TypeList, type_map ObjTyp
},
}
for name, fn := range(state_loads) {
ctx.StateLoadFuncs[name] = fn
}
for name, fn := range(node_loads) {
ctx.NodeLoadFuncs[name] = fn
}
return &ctx
}

@ -58,7 +58,7 @@ func logTestContext(t * testing.T, components []string) * GraphContext {
t.Fatal(err)
}
return NewGraphContext(db, NewConsoleLogger(components), TypeList{}, ObjTypeMap{}, FieldMap{}, FieldMap{}, FieldMap{})
return NewGraphContext(db, NewConsoleLogger(components), StateLoadMap{}, NodeLoadMap{}, TypeList{}, ObjTypeMap{}, FieldMap{}, FieldMap{}, FieldMap{})
}
func testContext(t * testing.T) * GraphContext {
@ -67,7 +67,7 @@ func testContext(t * testing.T) * GraphContext {
t.Fatal(err)
}
return NewGraphContext(db, NewConsoleLogger([]string{}), TypeList{}, ObjTypeMap{}, FieldMap{}, FieldMap{}, FieldMap{})
return NewGraphContext(db, NewConsoleLogger([]string{}), StateLoadMap{}, NodeLoadMap{}, TypeList{}, ObjTypeMap{}, FieldMap{}, FieldMap{}, FieldMap{})
}
func fatalErr(t * testing.T, err error) {