Skip to content

Commit

Permalink
cases: Use cases.Title over strings.Title which is deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
tmc committed Jul 2, 2022
1 parent 57623fa commit 9644f56
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
6 changes: 4 additions & 2 deletions codegen/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"github.com/99designs/gqlgen/codegen/config"
"github.com/99designs/gqlgen/codegen/templates"
"github.com/vektah/gqlparser/v2/ast"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)

type Field struct {
Expand Down Expand Up @@ -470,9 +472,9 @@ func (f *Field) GoNameUnexported() string {

func (f *Field) ShortInvocation() string {
if f.Object.Kind == ast.InputObject {
return fmt.Sprintf("%s().%s(ctx, &it, data)", strings.Title(f.Object.Definition.Name), f.GoFieldName)
return fmt.Sprintf("%s().%s(ctx, &it, data)", cases.Title(language.English).String(f.Object.Definition.Name), f.GoFieldName)
}
return fmt.Sprintf("%s().%s(%s)", strings.Title(f.Object.Definition.Name), f.GoFieldName, f.CallArgs())
return fmt.Sprintf("%s().%s(%s)", cases.Title(language.English).String(f.Object.Definition.Name), f.GoFieldName, f.CallArgs())
}

func (f *Field) ArgsFunc() string {
Expand Down
4 changes: 3 additions & 1 deletion codegen/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (

"github.com/99designs/gqlgen/codegen/config"
"github.com/vektah/gqlparser/v2/ast"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)

type GoFieldType int
Expand Down Expand Up @@ -46,7 +48,7 @@ func (b *builder) buildObject(typ *ast.Definition) (*Object, error) {
Stream: typ == b.Schema.Subscription,
Directives: dirs,
ResolverInterface: types.NewNamed(
types.NewTypeName(0, b.Config.Exec.Pkg(), strings.Title(typ.Name)+"Resolver", nil),
types.NewTypeName(0, b.Config.Exec.Pkg(), cases.Title(language.English).String(typ.Name)+"Resolver", nil),
nil,
nil,
),
Expand Down
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@ require (
gopkg.in/yaml.v2 v2.4.0
)

require github.com/agnivade/levenshtein v1.1.1 // indirect
require (
github.com/agnivade/levenshtein v1.1.1 // indirect
golang.org/x/text v0.3.7
)
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9sn
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
Expand Down
4 changes: 3 additions & 1 deletion plugin/resolvergen/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"github.com/99designs/gqlgen/codegen/templates"
"github.com/99designs/gqlgen/internal/rewrite"
"github.com/99designs/gqlgen/plugin"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)

func New() plugin.Plugin {
Expand Down Expand Up @@ -99,7 +101,7 @@ func (m *Plugin) generatePerSchema(data *codegen.Data) error {
}

rewriter.MarkStructCopied(templates.LcFirst(o.Name) + templates.UcFirst(data.Config.Resolver.Type))
rewriter.GetMethodBody(data.Config.Resolver.Type, strings.Title(o.Name))
rewriter.GetMethodBody(data.Config.Resolver.Type, cases.Title(language.English).String(o.Name))
files[fn].Objects = append(files[fn].Objects, o)
}
for _, f := range o.Fields {
Expand Down

0 comments on commit 9644f56

Please sign in to comment.