Changed NodeDef to use example instead of manually passing string and type

graph-rework-2
noah metz 2023-07-10 21:24:47 -06:00
parent e12d02eb3f
commit fb7fb5938d
1 changed files with 7 additions and 7 deletions

@ -23,12 +23,12 @@ type NodeDef struct {
Reflect reflect.Type Reflect reflect.Type
} }
func NewNodeDef(type_name string, reflect reflect.Type, load_func NodeLoadFunc, gql_type *graphql.Object) NodeDef { func NewNodeDef(example Node, load_func NodeLoadFunc, gql_type *graphql.Object) NodeDef {
return NodeDef{ return NodeDef{
Type: NodeType(type_name), Type: example.Type(),
Load: load_func, Load: load_func,
GQLType: gql_type, GQLType: gql_type,
Reflect: reflect, Reflect: reflect.TypeOf(example),
} }
} }
@ -158,19 +158,19 @@ func NewContext(db * badger.DB, log Logger) * Context {
Types: map[uint64]NodeDef{}, Types: map[uint64]NodeDef{},
} }
err := ctx.RegisterNodeType(NewNodeDef("graph_node", reflect.TypeOf((*GraphNode)(nil)), LoadGraphNode, GQLTypeGraphNode())) err := ctx.RegisterNodeType(NewNodeDef((*GraphNode)(nil), LoadGraphNode, GQLTypeGraphNode()))
if err != nil { if err != nil {
panic(err) panic(err)
} }
err = ctx.RegisterNodeType(NewNodeDef("simple_lockable", reflect.TypeOf((*SimpleLockable)(nil)), LoadSimpleLockable, GQLTypeSimpleLockable())) err = ctx.RegisterNodeType(NewNodeDef((*SimpleLockable)(nil), LoadSimpleLockable, GQLTypeSimpleLockable()))
if err != nil { if err != nil {
panic(err) panic(err)
} }
err = ctx.RegisterNodeType(NewNodeDef("simple_thread", reflect.TypeOf((*SimpleThread)(nil)), LoadSimpleThread, GQLTypeSimpleThread())) err = ctx.RegisterNodeType(NewNodeDef((*SimpleThread)(nil), LoadSimpleThread, GQLTypeSimpleThread()))
if err != nil { if err != nil {
panic(err) panic(err)
} }
err = ctx.RegisterNodeType(NewNodeDef("gql_thread", reflect.TypeOf((*GQLThread)(nil)), LoadGQLThread, GQLTypeGQLThread())) err = ctx.RegisterNodeType(NewNodeDef((*GQLThread)(nil), LoadGQLThread, GQLTypeGQLThread()))
if err != nil { if err != nil {
panic(err) panic(err)
} }