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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: keep pointer receiver consistent in generated go code #7219

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 2 additions & 7 deletions cmd/codegen/generator/go/templates/module_interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,7 @@ func (spec *parsedIfaceType) graphqlIDMethodCode() *Statement {
/*
The MarshalJSON method attached to the concrete implementation of the interface. e.g.:

func (r *customIfaceImpl) MarshalJSON() ([]byte, error) {
if r == nil {
return []byte("\"\""), nil
}
func (r customIfaceImpl) MarshalJSON() ([]byte, error) {
id, err := r.ID(context.Background())
if err != nil {
return nil, err
Expand All @@ -339,13 +336,11 @@ The MarshalJSON method attached to the concrete implementation of the interface.
}
*/
func (spec *parsedIfaceType) marshalJSONMethodCode() *Statement {
return Func().Params(Id("r").Op("*").Id(spec.concreteStructName())).
return Func().Params(Id("r").Id(spec.concreteStructName())).
Id("MarshalJSON").
Params().
Params(Id("[]byte"), Id("error")).
BlockFunc(func(g *Group) {
g.If(Id("r").Op("==").Nil()).Block(Return(Index().Byte().Parens(Lit(`""`)), Nil()))

g.List(Id("id"), Id("err")).Op(":=").Id("r").Dot("ID").Call(Id("marshalCtx"))
g.If(Id("err").Op("!=").Nil()).Block(Return(Nil(), Id("err")))
g.Return(Id("json").Dot("Marshal").Call(Id("id")))
Expand Down