diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 10a6bf9bad5..b99d3788fe8 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -5,7 +5,7 @@ jobs: lint: strategy: matrix: - go: [1.16] + go: [1.16, 1.18] runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -19,7 +19,7 @@ jobs: coverage: strategy: matrix: - go: [1.16] + go: [1.16, 1.18] runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -34,7 +34,7 @@ jobs: golangci-lint: strategy: matrix: - go: [1.16] + go: [1.16, 1.18] runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 diff --git a/_examples/go.mod b/_examples/go.mod index 74ad4938eab..ceda7e99234 100644 --- a/_examples/go.mod +++ b/_examples/go.mod @@ -23,5 +23,6 @@ require ( github.com/pkg/errors v0.9.1 // indirect github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 // indirect github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546 // indirect + golang.org/x/text v0.3.7 sourcegraph.com/sourcegraph/appdash-data v0.0.0-20151005221446-73f23eafcf67 // indirect ) diff --git a/_examples/go.sum b/_examples/go.sum index 776f5b47a12..bbb1402dbac 100644 --- a/_examples/go.sum +++ b/_examples/go.sum @@ -128,6 +128,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-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/_examples/tools.go b/_examples/tools.go index 4c124bccfce..c3c64c2d1c9 100644 --- a/_examples/tools.go +++ b/_examples/tools.go @@ -5,4 +5,5 @@ package main import ( _ "github.com/vektah/dataloaden" + _ "golang.org/x/text" ) diff --git a/codegen/field.go b/codegen/field.go index c83c3585784..053c86e166d 100644 --- a/codegen/field.go +++ b/codegen/field.go @@ -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 { @@ -469,10 +471,11 @@ func (f *Field) GoNameUnexported() string { } func (f *Field) ShortInvocation() string { + caser := cases.Title(language.English, cases.NoLower) 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)", caser.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)", caser.String(f.Object.Definition.Name), f.GoFieldName, f.CallArgs()) } func (f *Field) ArgsFunc() string { diff --git a/codegen/object.go b/codegen/object.go index 6cf922d47c4..a9cb34061b4 100644 --- a/codegen/object.go +++ b/codegen/object.go @@ -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 @@ -38,7 +40,7 @@ func (b *builder) buildObject(typ *ast.Definition) (*Object, error) { if err != nil { return nil, fmt.Errorf("%s: %w", typ.Name, err) } - + caser := cases.Title(language.English, cases.NoLower) obj := &Object{ Definition: typ, Root: b.Schema.Query == typ || b.Schema.Mutation == typ || b.Schema.Subscription == typ, @@ -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(), caser.String(typ.Name)+"Resolver", nil), nil, nil, ), diff --git a/go.mod b/go.mod index dcdfc0dd067..8ce34b323e0 100644 --- a/go.mod +++ b/go.mod @@ -14,6 +14,7 @@ require ( github.com/stretchr/testify v1.7.1 github.com/urfave/cli/v2 v2.8.1 github.com/vektah/gqlparser/v2 v2.4.6 + golang.org/x/text v0.3.7 golang.org/x/tools v0.1.10 google.golang.org/protobuf v1.28.0 gopkg.in/yaml.v2 v2.4.0 diff --git a/go.sum b/go.sum index ba65fc482c7..aeacaa4b728 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/plugin/resolvergen/resolver.go b/plugin/resolvergen/resolver.go index 5d892353e0f..c2a8a285c93 100644 --- a/plugin/resolvergen/resolver.go +++ b/plugin/resolvergen/resolver.go @@ -14,6 +14,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" ) //go:embed resolver.gotpl @@ -104,8 +106,9 @@ func (m *Plugin) generatePerSchema(data *codegen.Data) error { files[fn] = &File{} } + caser := cases.Title(language.English, cases.NoLower) 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, caser.String(o.Name)) files[fn].Objects = append(files[fn].Objects, o) } for _, f := range o.Fields {