-
Notifications
You must be signed in to change notification settings - Fork 0
/
resolver.go
executable file
·52 lines (42 loc) · 1.89 KB
/
resolver.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package gen
import (
"context"
"github.com/jinzhu/gorm"
"github.com/novacloudcz/graphql-orm/events"
)
type ResolutionHandlers struct {
OnEvent func(ctx context.Context, r *GeneratedResolver, e *events.Event) error
CreateComment func(ctx context.Context, r *GeneratedResolver, input map[string]interface{}) (item *Comment, err error)
UpdateComment func(ctx context.Context, r *GeneratedResolver, id string, input map[string]interface{}) (item *Comment, err error)
DeleteComment func(ctx context.Context, r *GeneratedResolver, id string) (item *Comment, err error)
DeleteAllComments func(ctx context.Context, r *GeneratedResolver) (bool, error)
QueryComment func(ctx context.Context, r *GeneratedResolver, opts QueryCommentHandlerOptions) (*Comment, error)
QueryComments func(ctx context.Context, r *GeneratedResolver, opts QueryCommentsHandlerOptions) (*CommentResultType, error)
CommentCreatedByUser func(ctx context.Context, r *GeneratedResolver, obj *Comment) (res *User, err error)
}
func DefaultResolutionHandlers() ResolutionHandlers {
handlers := ResolutionHandlers{
OnEvent: func(ctx context.Context, r *GeneratedResolver, e *events.Event) error { return nil },
CreateComment: CreateCommentHandler,
UpdateComment: UpdateCommentHandler,
DeleteComment: DeleteCommentHandler,
DeleteAllComments: DeleteAllCommentsHandler,
QueryComment: QueryCommentHandler,
QueryComments: QueryCommentsHandler,
CommentCreatedByUser: CommentCreatedByUserHandler,
}
return handlers
}
type GeneratedResolver struct {
Handlers ResolutionHandlers
DB *DB
EventController *events.EventController
}
// GetDB returns database connection or transaction for given context (if exists)
func (r *GeneratedResolver) GetDB(ctx context.Context) *gorm.DB {
db, _ := ctx.Value(KeyMutationTransaction).(*gorm.DB)
if db == nil {
db = r.DB.Query()
}
return db
}