Skip to content

Commit

Permalink
trying to get description with generated models
Browse files Browse the repository at this point in the history
  • Loading branch information
andrioid committed Aug 26, 2018
1 parent 2dcb2dd commit 6ae8238
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 9 deletions.
4 changes: 2 additions & 2 deletions codegen/enum.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package codegen

type Enum struct {
*NamedType

Values []EnumValue
Description string
Values []EnumValue
}

type EnumValue struct {
Expand Down
5 changes: 3 additions & 2 deletions codegen/enum_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ func (cfg *Config) buildEnums(types NamedTypes) []Enum {
}

enum := Enum{
NamedType: namedType,
Values: values,
NamedType: namedType,
Values: values,
Description: typ.Description,
}
enum.GoType = templates.ToCamel(enum.GQLType)
enums = append(enums, enum)
Expand Down
5 changes: 3 additions & 2 deletions codegen/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package codegen

type Model struct {
*NamedType

Fields []ModelField
Description string
Fields []ModelField
}

type ModelField struct {
Expand All @@ -12,4 +12,5 @@ type ModelField struct {
GoFieldName string
GoFKName string
GoFKType string
Description string
}
1 change: 1 addition & 0 deletions codegen/models_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func (cfg *Config) buildModels(types NamedTypes, prog *loader.Program, imports *
default:
continue
}
model.Description = typ.Description // It's this or change both obj2Model and buildObject

models = append(models, model)
}
Expand Down
2 changes: 1 addition & 1 deletion codegen/templates/data.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions codegen/templates/models.gotpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Code generated by github.com/99designs/gqlgen, DO NOT EDIT.
// Dirt

package {{ .PackageName }}

Expand All @@ -9,10 +10,13 @@ import (
)

{{ range $model := .Models }}
{{with .Description}} {{.|prefixLines "// "}} {{end}}

{{- if .IsInterface }}
type {{.GoType}} interface {}
{{- else }}
type {{.GoType}} struct {

{{- range $field := .Fields }}
{{- if $field.GoFieldName }}
{{ $field.GoFieldName }} {{$field.Signature}} `json:"{{$field.GQLName}}"`
Expand All @@ -25,12 +29,13 @@ import (
{{- end}}

{{ range $enum := .Enums }}
{{with .Description}} {{.|prefixLines "// "}} {{end}}
type {{.GoType}} string
const (
{{ range $value := .Values -}}
{{ range $value := .Values}}
{{with .Description}} {{.|prefixLines "// "}} {{end}}
{{$enum.GoType}}{{ .Name|toCamel }} {{$enum.GoType}} = {{.Name|quote}}
{{- end }}
{{ end }}
)

func (e {{.GoType}}) IsValid() bool {
Expand Down

0 comments on commit 6ae8238

Please sign in to comment.