-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
98 lines (89 loc) · 1.86 KB
/
types.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package entgqlplus
import (
"log"
"strings"
"entgo.io/ent/entc/gen"
)
type (
templateData struct {
Package string
Nodes []node
Node node
AuthNode node
HasSubscription bool
Config *config
}
config struct {
Database database
DBConfig []string
Echo *bool
JWT *bool
Mutation *bool
Privacy *bool
FileUpload *bool
Subscription *bool
GqlGenPath string
GqlGen gqlGen
}
node struct {
Name string
Subscription bool
Auth bool
}
file struct {
Path string
Buffer string
}
gqlGen struct {
Schema []string `yaml:"schema"`
Exec struct {
FileName string `yaml:"filename"`
Dir string
Package string `yaml:"package"`
} `yaml:"exec"`
Model struct {
FileName string `yaml:"filename"`
Dir string
Package string `yaml:"package"`
} `yaml:"model"`
Resolver struct {
Dir string `yaml:"dir"`
Package string `yaml:"package"`
} `yaml:"resolver"`
}
appendMode string
)
func (t *templateData) parse(g *gen.Graph) {
t.Package = strings.ReplaceAll(g.Package, "/ent", "")
asCount := 0
for i := range g.Nodes {
if len(g.Nodes[i].Fields) == 0 {
continue
}
a := &annotation{}
a.decode(g.Nodes[i].Annotations[schemaAnnotationKey])
n := node{Name: g.Nodes[i].Name}
if a.SchemaOptions != nil {
n.Subscription = inArray(a.SchemaOptions, Subscription)
if n.Subscription {
t.HasSubscription = true
}
as := inArray(a.SchemaOptions, AuthSchema)
if as {
asCount++
if asCount > 1 {
log.Fatalln("entgqlplus: can't use more than one AuthSchema")
}
t.AuthNode = n
}
}
t.Nodes = append(t.Nodes, n)
}
if t.Config.JWT != nil {
if *t.Config.JWT {
if asCount == 0 {
log.Fatalln("entgqlplus: No auth schema found, use entgqlplus.AuthSchema()")
}
}
}
}