1// Code generated by github.com/vektah/gqlgen, DO NOT EDIT.
2
3package {{ .PackageName }}
4
5import (
6{{- range $import := .Imports }}
7 {{- $import.Write }}
8{{ end }}
9)
10
11{{ range $model := .Models }}
12 {{- if .IsInterface }}
13 type {{.GoType}} interface {}
14 {{- else }}
15 type {{.GoType}} struct {
16 {{- range $field := .Fields }}
17 {{- if $field.GoVarName }}
18 {{ $field.GoVarName }} {{$field.Signature}} `json:"{{$field.GQLName}}"`
19 {{- else }}
20 {{ $field.GoFKName }} {{$field.GoFKType}}
21 {{- end }}
22 {{- end }}
23 }
24 {{- end }}
25{{- end}}
26
27{{ range $enum := .Enums }}
28 type {{.GoType}} string
29 const (
30 {{ range $value := .Values -}}
31 {{with .Description}} {{.|prefixLines "// "}} {{end}}
32 {{$enum.GoType}}{{ .Name|toCamel }} {{$enum.GoType}} = {{.Name|quote}}
33 {{- end }}
34 )
35
36 func (e {{.GoType}}) IsValid() bool {
37 switch e {
38 case {{ range $index, $element := .Values}}{{if $index}},{{end}}{{ $enum.GoType }}{{ $element.Name|toCamel }}{{end}}:
39 return true
40 }
41 return false
42 }
43
44 func (e {{.GoType}}) String() string {
45 return string(e)
46 }
47
48 func (e *{{.GoType}}) UnmarshalGQL(v interface{}) error {
49 str, ok := v.(string)
50 if !ok {
51 return fmt.Errorf("enums must be strings")
52 }
53
54 *e = {{.GoType}}(str)
55 if !e.IsValid() {
56 return fmt.Errorf("%s is not a valid {{.GQLType}}", str)
57 }
58 return nil
59 }
60
61 func (e {{.GoType}}) MarshalGQL(w io.Writer) {
62 fmt.Fprint(w, strconv.Quote(e.String()))
63 }
64
65{{- end }}