Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix multiline comments #194

Merged
merged 1 commit into from
Jul 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

5 changes: 3 additions & 2 deletions codegen/templates/models.gotpl
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ import (
{{ range $enum := .Enums }}
type {{.GoType}} string
const (
{{ range $value := .Values }}
{{$enum.GoType}}{{ .Name|toCamel }} {{$enum.GoType}} = {{.Name|quote}} {{with .Description}} // {{.}} {{end}}
{{ range $value := .Values -}}
{{with .Description}} {{.|prefixLines "// "}} {{end}}
{{$enum.GoType}}{{ .Name|toCamel }} {{$enum.GoType}} = {{.Name|quote}}
{{- end }}
)

Expand Down
17 changes: 11 additions & 6 deletions codegen/templates/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ import (

func Run(name string, tpldata interface{}) (*bytes.Buffer, error) {
t := template.New("").Funcs(template.FuncMap{
"ucFirst": ucFirst,
"lcFirst": lcFirst,
"quote": strconv.Quote,
"rawQuote": rawQuote,
"toCamel": ToCamel,
"dump": dump,
"ucFirst": ucFirst,
"lcFirst": lcFirst,
"quote": strconv.Quote,
"rawQuote": rawQuote,
"toCamel": ToCamel,
"dump": dump,
"prefixLines": prefixLines,
})

for filename, data := range data {
Expand Down Expand Up @@ -132,3 +133,7 @@ func dump(val interface{}) string {
panic(fmt.Errorf("unsupported type %T", val))
}
}

func prefixLines(prefix, s string) string {
return prefix + strings.Replace(s, "\n", "\n"+prefix, -1)
}
12 changes: 7 additions & 5 deletions example/starwars/models_gen.go

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

3 changes: 3 additions & 0 deletions test/generated.go

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

3 changes: 3 additions & 0 deletions test/models-go/generated.go

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

3 changes: 3 additions & 0 deletions test/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ type Element {
}

enum DATE_FILTER_OP {
# multi
# line
# comment
EQ
NEQ
GT
Expand Down