/
root.go
75 lines (68 loc) · 1.72 KB
/
root.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package graphql
import "github.com/graphql-go/graphql"
func (m *Module) statusField() *graphql.Field {
return &graphql.Field{
Type: statusType,
Description: "get system status",
Resolve: m.statusQuery,
}
}
func (m *Module) rootQuery() *graphql.Object {
return graphql.NewObject(graphql.ObjectConfig{
Name: "Query",
Fields: graphql.Fields{
"status": m.statusField(),
},
})
}
func (m *Module) rootQueryUnauthorized() *graphql.Object {
return graphql.NewObject(graphql.ObjectConfig{
Name: "Query",
Fields: graphql.Fields{
"status": m.statusField(),
},
})
}
// root mutation
func (m *Module) rootMutation() *graphql.Object {
return graphql.NewObject(graphql.ObjectConfig{
Name: "Mutation",
Fields: graphql.Fields{
"logout": &graphql.Field{
Type: successType,
Description: "Logout of the system",
Resolve: m.logoutMutator,
},
"refreshAccessToken": &graphql.Field{
Type: jwtTokensType,
Description: "Refresh jwt token",
Args: graphql.FieldConfigArgument{
"refreshToken": &graphql.ArgumentConfig{
Type: graphql.NewNonNull(graphql.String),
},
},
Resolve: m.refreshAccessTokenMutator,
},
},
})
}
func (m *Module) rootMutationUnauthorized() *graphql.Object {
return graphql.NewObject(graphql.ObjectConfig{
Name: "Mutation",
Fields: graphql.Fields{
"login": &graphql.Field{
Type: jwtTokensType,
Description: "Login to system",
Args: graphql.FieldConfigArgument{
"email": &graphql.ArgumentConfig{
Type: graphql.NewNonNull(graphql.String),
},
"password": &graphql.ArgumentConfig{
Type: graphql.NewNonNull(graphql.String),
},
},
Resolve: m.loginMutator,
},
},
})
}