-
Notifications
You must be signed in to change notification settings - Fork 4
/
context.go
61 lines (47 loc) · 1.51 KB
/
context.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
53
54
55
56
57
58
59
60
61
package gql
import (
"context"
"github.com/reearth/reearth-cms/server/internal/adapter"
"github.com/reearth/reearth-cms/server/internal/usecase"
"github.com/reearth/reearth-cms/server/internal/usecase/interfaces"
"github.com/reearth/reearthx/account/accountdomain/user"
"github.com/reearth/reearthx/account/accountusecase"
)
type ContextKey string
const (
contextLoaders ContextKey = "loaders"
contextDataloaders ContextKey = "dataloaders"
)
func AttachUsecases(ctx context.Context, u *interfaces.Container, enableDataLoaders bool) context.Context {
loaders := NewLoaders(u)
dataloaders := loaders.DataLoadersWith(ctx, enableDataLoaders)
ctx = adapter.AttachUsecases(ctx, u)
ctx = context.WithValue(ctx, contextLoaders, loaders)
ctx = context.WithValue(ctx, contextDataloaders, dataloaders)
return ctx
}
func getUser(ctx context.Context) *user.User {
return adapter.User(ctx)
}
//
//func getLang(ctx context.Context, lang *language.Tag) string {
// return adapter.Lang(ctx, lang)
//}
func getOperator(ctx context.Context) *usecase.Operator {
return adapter.Operator(ctx)
}
func getAcOperator(ctx context.Context) *accountusecase.Operator {
if op := getOperator(ctx); op != nil {
return op.AcOperator
}
return nil
}
func usecases(ctx context.Context) *interfaces.Container {
return adapter.Usecases(ctx)
}
func loaders(ctx context.Context) *Loaders {
return ctx.Value(contextLoaders).(*Loaders)
}
func dataloaders(ctx context.Context) *DataLoaders {
return ctx.Value(contextDataloaders).(*DataLoaders)
}