forked from xo/xo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
graphql.query.go.tpl
107 lines (72 loc) · 2.72 KB
/
graphql.query.go.tpl
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
99
100
101
102
103
104
{{- if eq .Template "QUERY" }}
// {{capitalize .Name}} - {{.Description}}
type {{capitalize .Name}}Resolver interface {
{{- range .Fields}}
{{ $hasArguments := gt (.Args | len) 0}}
// {{capitalize .Name}} {{.Description}}
{{capitalize .Name}}({{if $hasArguments}}ctx context.Context, args {{capitalize .Name}}Args{{end}}) ({{genType .Type "interface" .Name "objects"}}, error)
{{- end}}
}
{{- range .Fields}}
// {{capitalize .Name}}Args are the arguments for the "{{capitalize .Name}}" query.
type {{capitalize .Name}}Args struct{
{{- range .Args}}
{{capitalize .Name}} {{genType .Type "argStruct" .Name "package"}}
{{- end}}
}
{{- end}}
{{- end}}
{{- if eq .Template "MUTATION" }}
// {{capitalize .Name}} - {{.Description}}
type {{capitalize .Name}}Resolver interface {
{{- range .Fields}}
{{- $hasArguments := gt (.Args | len) 0}}
// {{capitalize .Name}} {{.Description}}
{{capitalize .Name}}({{if $hasArguments}}ctx context.Context, args *{{capitalize .Name}}Args{{end}}) ({{genType .Type "interface" .Name "package"}}, error)
{{- end}}
}
{{- end}}
{{- if eq .Template "ARGS" }}
{{- range .Fields}}
// {{capitalize .Name}}Args are the arguments for the "{{capitalize .Name}}" query.
type {{capitalize .Name}}Args struct{
{{- range .Args}}
{{capitalize .Name}} {{genType .Type "argStruct" .Name "package"}}
{{- end}}
}
{{- end}}
{{- end}}
{{- if eq .Template "INPUT" }}
// {{.Name}} - {{.Description}}
type {{.Name}} struct {
{{- range .Fields}}
{{capitalize .Name}} {{genType .Type "argStruct" .Name "package"}} `json:"{{.Name}}"` {{- if ne .Description "" }} // {{.Description}} {{- end}}
{{- end}}
}
{{- end}}
{{- if eq .Template "PAYLOAD" }}
// {{.Name}} {{.Description}}
type {{.Name}} struct {
{{- range .Fields}}
{{capitalize .Name}} {{genType .Type "struct" .Name "objects"}} `json:"{{.Name}}"` // {{capitalize .Name}} {{.Description}}
{{- end}}
}
// {{.Name}}Resolver resolver for {{.Name}}
type {{.Name}}Resolver struct {
{{.Name}}
}
// New{{.Name}} for {{.Name}}
func New{{.Name}}(pl {{.Name}}) *{{.Name}}Resolver {
return &{{.Name}}Resolver{pl}
}
{{ range .Fields}}
// {{capitalize .Name}} {{.Description}}
func (r *{{capitalize .Parent}}Resolver) {{capitalize .Name}}() {{genType .Type "interface" .Name "objects"}} {
{{- if eq .Type.GQLType "graphql.ID" }}
return {{ if .Type.IsNullable }} & {{- end}}graphql.ID(r.{{capitalize .Parent}}.{{capitalize .Name}})
{{ else }}
return r.{{capitalize .Parent}}.{{capitalize .Name}}
{{- end}}
}
{{ end}}
{{- end}}