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

entgql: change enum receiver to e #233

Merged
merged 1 commit into from
Feb 14, 2022
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
10 changes: 5 additions & 5 deletions entgql/internal/todo/ent/category/category.go

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

10 changes: 5 additions & 5 deletions entgql/internal/todo/ent/todo/todo.go

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

10 changes: 5 additions & 5 deletions entgql/internal/todofed/ent/category/category.go

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

10 changes: 5 additions & 5 deletions entgql/internal/todofed/ent/todo/todo.go

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

10 changes: 5 additions & 5 deletions entgql/internal/todopulid/ent/category/category.go

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

10 changes: 5 additions & 5 deletions entgql/internal/todopulid/ent/todo/todo.go

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

10 changes: 5 additions & 5 deletions entgql/internal/todouuid/ent/category/category.go

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

10 changes: 5 additions & 5 deletions entgql/internal/todouuid/ent/todo/todo.go

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

11 changes: 5 additions & 6 deletions entgql/template/enum.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,19 @@ in the LICENSE file in the root directory of this source tree.
{{ range $f := $.EnumFields }}
{{ $enum := trimPackage $f.Type.String $.Package -}}
{{- if not $f.HasGoType }}
{{ $receiver := receiver $f.BuilderField -}}
// MarshalGQL implements graphql.Marshaler interface.
func ({{ $receiver }} {{ $enum }}) MarshalGQL(w io.Writer) {
io.WriteString(w, strconv.Quote({{ $receiver }}.String()))
func (e {{ $enum }}) MarshalGQL(w io.Writer) {
io.WriteString(w, strconv.Quote(e.String()))
}

// UnmarshalGQL implements graphql.Unmarshaler interface.
func ({{ $receiver }} *{{ $enum }}) UnmarshalGQL(val interface{}) error {
func (e *{{ $enum }}) UnmarshalGQL(val interface{}) error {
str, ok := val.(string)
if !ok {
return fmt.Errorf("enum %T must be a string", val)
}
*{{ $receiver }} = {{ $enum }}(str)
if err := {{ $f.Validator }}(*{{ $receiver }}); err != nil {
*e = {{ $enum }}(str)
if err := {{ $f.Validator }}(*e); err != nil {
return fmt.Errorf("%s is not a valid {{ $enum }}", str)
}
return nil
Expand Down