Skip to content

Commit

Permalink
Merge pull request #194 from vektah/multiline-comments
Browse files Browse the repository at this point in the history
Fix multiline comments
  • Loading branch information
vektah authored Jul 14, 2018
2 parents 112d68a + 4b3778e commit 381b346
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 14 deletions.
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

0 comments on commit 381b346

Please sign in to comment.