diff --git a/context.go b/context.go new file mode 100644 index 0000000..04ef191 --- /dev/null +++ b/context.go @@ -0,0 +1,18 @@ +package tether + +import "gorm.io/gorm" + +type AuthCtx struct { + UserID string + IsLoggedIn bool +} + +type QueryCtx struct { + DB *gorm.DB + AuthCtx *AuthCtx +} + +type MutationCtx struct { + DB *gorm.DB + AuthCtx *AuthCtx +} diff --git a/engine.go b/engine.go index 4100c4b..f21853e 100644 --- a/engine.go +++ b/engine.go @@ -6,10 +6,16 @@ import ( ) type Engine struct { - db *gorm.DB - channels map[string]*reactivity.Channel + db *gorm.DB + channels map[string]*reactivity.Channel + mutations []func(ctx *MutationCtx) error + queries []func(ctx *QueryCtx) error } func NewEngine(db *gorm.DB) *Engine { return &Engine{db: db, channels: make(map[string]*reactivity.Channel)} } + +func (e *Engine) RegisterMutation(mutation func(ctx *MutationCtx) error) { + e.mutations = append(e.mutations, mutation) +}