From b647ad2494aa532f041c60af2939385c2cfb13a3 Mon Sep 17 00:00:00 2001 From: Travis Cline Date: Wed, 29 Jun 2022 23:41:00 -0700 Subject: [PATCH 1/9] github: Test more go versions --- .github/workflows/test.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 59016f50682..95d956f3c20 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,19 +2,18 @@ name: Test on: [push, pull_request] -env: - GO_VERSION: 1.16 - jobs: test: strategy: matrix: os: [ubuntu-latest, windows-latest] + go: [1.16, 1.17, 1.18] runs-on: ${{ matrix.os }} + continue-on-error: true steps: - uses: actions/checkout@v3 - uses: actions/setup-go@v3 with: - go-version: ${{ env.GO_VERSION }} + go-version: ${{ matrix.go }} - run: go mod download && go test -race ./... - run: cd _examples && go mod download && go test -race ./... From 0d43b681016f2b0d6a2ab4b7e2998b715cfed004 Mon Sep 17 00:00:00 2001 From: Travis Cline Date: Wed, 29 Jun 2022 23:44:06 -0700 Subject: [PATCH 2/9] github: Fix ci tests --- .github/workflows/integration.yml | 33 ++++++++++++++++++++++--------- .github/workflows/lint.yml | 20 ++++++++++++------- .github/workflows/security.yml | 8 ++++---- .github/workflows/test.yml | 2 +- 4 files changed, 42 insertions(+), 21 deletions(-) diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index d6b0276ea6e..4dfc0fd3be9 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -1,35 +1,50 @@ name: Integration on: [push, pull_request] -env: - GO_VERSION: 1.16 - jobs: integration: + strategy: + matrix: + go: [1.16] runs-on: ubuntu-latest timeout-minutes: 3 - container: golang:${{ env.GO_VERSION }}-alpine steps: - uses: actions/checkout@v3 - - run: apk add --no-cache --no-progress nodejs npm git bash + - uses: actions/setup-go@v3 + with: + go-version: ${{ matrix.go }} + - uses: actions/setup-node@v3 + with: + node-version: 14 - run: go mod download - run: cd integration ; npm install - run: .github/workflows/check-integration federation: + strategy: + matrix: + go: [1.16] runs-on: ubuntu-latest - container: golang:${{ env.GO_VERSION }}-alpine steps: - uses: actions/checkout@v3 - - run: apk add --no-cache --no-progress nodejs npm git bash + - uses: actions/setup-go@v3 + with: + go-version: ${{ matrix.go }} + - uses: actions/setup-node@v3 + with: + node-version: 14 - run: go mod download - run: cd _examples/federation ; npm install - run: .github/workflows/check-federation init: + strategy: + matrix: + go: [1.16] runs-on: ubuntu-latest - container: golang:${{ env.GO_VERSION }}-alpine steps: - uses: actions/checkout@v3 - - run: apk add --no-cache --no-progress alpine-sdk bash + - uses: actions/setup-go@v3 + with: + go-version: ${{ matrix.go }} - run: .github/workflows/check-init diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 68d671a0472..66339501bf3 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,41 +1,47 @@ name: Lint on: [push, pull_request] -env: - GO_VERSION: 1.16 - jobs: lint: + strategy: + matrix: + go: [1.16] runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: actions/setup-go@v3 with: - go-version: ${{ env.GO_VERSION }} + go-version: ${{ matrix.go }} - run: go mod download - run: .github/workflows/check-fmt - run: .github/workflows/check-generate coverage: + strategy: + matrix: + go: [1.16] runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: actions/setup-go@v3 with: - go-version: ${{ env.GO_VERSION }} + go-version: ${{ matrix.go }} - run: go mod download - run: .github/workflows/check-coverage env: COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }} golangci-lint: + strategy: + matrix: + go: [1.16] runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Install Go - uses: actions/setup-go@v3 + - uses: actions/setup-go@v3 with: - go-version: ${{ env.GO_VERSION }} + go-version: ${{ matrix.go }} - name: golangci-lint uses: golangci/golangci-lint-action@v3.1.0 with: diff --git a/.github/workflows/security.yml b/.github/workflows/security.yml index 4c558310dad..d78a6150f9b 100644 --- a/.github/workflows/security.yml +++ b/.github/workflows/security.yml @@ -1,16 +1,16 @@ name: Security on: [push, pull_request] -env: - GO_VERSION: 1.16 - jobs: nancy: + strategy: + matrix: + go: [1.16, 1.17, 1.18] runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: actions/setup-go@v3 with: - go-version: ${{ env.GO_VERSION }} + go-version: ${{ matrix.go }} - run: go mod download && go list -json -deps all > go.list - uses: sonatype-nexus-community/nancy-github-action@main diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 95d956f3c20..c65853b660f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,7 +7,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest] - go: [1.16, 1.17, 1.18] + go: [1.16] runs-on: ${{ matrix.os }} continue-on-error: true steps: From 00285fd859ebb767abb3889924cfbe63d06f7961 Mon Sep 17 00:00:00 2001 From: Travis Cline Date: Sat, 2 Jul 2022 10:03:44 -0700 Subject: [PATCH 3/9] github: Increase verbosity, sleep --- .github/workflows/check-federation | 13 +++++++++++-- .github/workflows/check-integration | 10 +++++++++- .github/workflows/lint.yml | 1 - 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/.github/workflows/check-federation b/.github/workflows/check-federation index 314452c58ac..1907cddcfd2 100755 --- a/.github/workflows/check-federation +++ b/.github/workflows/check-federation @@ -4,9 +4,18 @@ set -euo pipefail cd _examples/federation -./start.sh & +bash ./start.sh & -sleep 10 +sleep 5 +curl -s --connect-timeout 5 \ + --max-time 10 \ + --retry 5 \ + --retry-delay 5 \ + --retry-max-time 40 \ + --retry-connrefused \ + localhost:4003 > /dev/null + +sleep 1 echo "### running jest integration spec" ./node_modules/.bin/jest --color diff --git a/.github/workflows/check-integration b/.github/workflows/check-integration index 2472628acf2..d9b95d577d4 100755 --- a/.github/workflows/check-integration +++ b/.github/workflows/check-integration @@ -4,9 +4,17 @@ set -euo pipefail cd integration +date go run ./server/server.go & -sleep 2 +sleep 5 +curl -s --connect-timeout 5 \ + --max-time 10 \ + --retry 5 \ + --retry-delay 5 \ + --retry-max-time 40 \ + --retry-connrefused \ + localhost:8080 > /dev/null echo "### running jest integration spec" ./node_modules/.bin/jest --color diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 66339501bf3..10a6bf9bad5 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -38,7 +38,6 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - name: Install Go - uses: actions/setup-go@v3 with: go-version: ${{ matrix.go }} From 1c442aa6a877a5fdb8185103a1f618c381c66b23 Mon Sep 17 00:00:00 2001 From: Travis Cline Date: Sat, 2 Jul 2022 10:54:37 -0700 Subject: [PATCH 4/9] github: Drop bash --- .github/workflows/check-federation | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-federation b/.github/workflows/check-federation index 1907cddcfd2..8025e8e0d13 100755 --- a/.github/workflows/check-federation +++ b/.github/workflows/check-federation @@ -4,7 +4,7 @@ set -euo pipefail cd _examples/federation -bash ./start.sh & +./start.sh & sleep 5 curl -s --connect-timeout 5 \ From e49cb5d2911cfe79f4cd0170d446083448cd64b6 Mon Sep 17 00:00:00 2001 From: Travis Cline Date: Sat, 2 Jul 2022 12:23:38 -0700 Subject: [PATCH 5/9] github: Test go 1.18 and newer node verisons --- .github/workflows/integration.yml | 12 +++++++----- .github/workflows/lint.yml | 6 +++--- .github/workflows/security.yml | 2 +- .github/workflows/test.yml | 3 +-- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 4dfc0fd3be9..ca16fa3d183 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -5,7 +5,8 @@ jobs: integration: strategy: matrix: - go: [1.16] + go: [1.16, 1.18] + node: [14, 16] runs-on: ubuntu-latest timeout-minutes: 3 steps: @@ -15,7 +16,7 @@ jobs: go-version: ${{ matrix.go }} - uses: actions/setup-node@v3 with: - node-version: 14 + node-version: ${{ matrix.node }} - run: go mod download - run: cd integration ; npm install - run: .github/workflows/check-integration @@ -23,7 +24,8 @@ jobs: federation: strategy: matrix: - go: [1.16] + go: [1.16, 1.18] + node: [14, 16] runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -32,7 +34,7 @@ jobs: go-version: ${{ matrix.go }} - uses: actions/setup-node@v3 with: - node-version: 14 + node-version: ${{ matrix.node }} - run: go mod download - run: cd _examples/federation ; npm install - run: .github/workflows/check-federation @@ -40,7 +42,7 @@ jobs: init: strategy: matrix: - go: [1.16] + go: [1.16, 1.18] runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 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/.github/workflows/security.yml b/.github/workflows/security.yml index d78a6150f9b..ef57b15664b 100644 --- a/.github/workflows/security.yml +++ b/.github/workflows/security.yml @@ -5,7 +5,7 @@ jobs: nancy: strategy: matrix: - go: [1.16, 1.17, 1.18] + go: [1.16, 1.18] runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c65853b660f..f50297cacbc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,13 +1,12 @@ name: Test on: [push, pull_request] - jobs: test: strategy: matrix: os: [ubuntu-latest, windows-latest] - go: [1.16] + go: [1.16, 1.18] runs-on: ${{ matrix.os }} continue-on-error: true steps: From 57623fa6cefd8ec0fa599902738ba36062256794 Mon Sep 17 00:00:00 2001 From: Travis Cline Date: Sat, 2 Jul 2022 12:56:25 -0700 Subject: [PATCH 6/9] github: Pull out node 16 for now --- .github/workflows/integration.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index ca16fa3d183..f53f024c355 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -6,7 +6,7 @@ jobs: strategy: matrix: go: [1.16, 1.18] - node: [14, 16] + node: [14] runs-on: ubuntu-latest timeout-minutes: 3 steps: @@ -25,7 +25,7 @@ jobs: strategy: matrix: go: [1.16, 1.18] - node: [14, 16] + node: [14] runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 From 146ddaf4b66844f4b636463e80cad45c30364283 Mon Sep 17 00:00:00 2001 From: Travis Cline Date: Sat, 2 Jul 2022 13:22:20 -0700 Subject: [PATCH 7/9] github: Only lint 1.16 for now --- .github/workflows/lint.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index b99d3788fe8..10a6bf9bad5 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -5,7 +5,7 @@ jobs: lint: strategy: matrix: - go: [1.16, 1.18] + go: [1.16] runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -19,7 +19,7 @@ jobs: coverage: strategy: matrix: - go: [1.16, 1.18] + go: [1.16] runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -34,7 +34,7 @@ jobs: golangci-lint: strategy: matrix: - go: [1.16, 1.18] + go: [1.16] runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 From 8b7a940be24039ad5148918beada66ace16a279f Mon Sep 17 00:00:00 2001 From: Travis Cline Date: Sat, 2 Jul 2022 13:01:11 -0700 Subject: [PATCH 8/9] cases: Use cases.Title over strings.Title which is deprecated --- codegen/field.go | 6 ++++-- codegen/object.go | 4 +++- go.mod | 5 ++++- go.sum | 1 + plugin/resolvergen/resolver.go | 4 +++- 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/codegen/field.go b/codegen/field.go index c83c3585784..3776130a65c 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 { @@ -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 { diff --git a/codegen/object.go b/codegen/object.go index 6cf922d47c4..6ab748a7580 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 @@ -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, ), diff --git a/go.mod b/go.mod index 7c6b7795506..019da8f073a 100644 --- a/go.mod +++ b/go.mod @@ -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 +) diff --git a/go.sum b/go.sum index 1b0fba79500..772aa6e5efb 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 538aa714b1e..668a8140bb1 100644 --- a/plugin/resolvergen/resolver.go +++ b/plugin/resolvergen/resolver.go @@ -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 { @@ -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 { From 0d2e3fc072ea10f8000c00bb73e8942651736fe6 Mon Sep 17 00:00:00 2001 From: Travis Cline Date: Sat, 2 Jul 2022 14:45:03 -0700 Subject: [PATCH 9/9] gqlgen: Remove use of deprecated strings.Title --- .github/workflows/lint.yml | 6 +++--- _examples/go.mod | 1 + _examples/go.sum | 1 + _examples/tools.go | 1 + codegen/field.go | 5 +++-- codegen/object.go | 4 ++-- go.mod | 6 ++---- plugin/resolvergen/resolver.go | 3 ++- 8 files changed, 15 insertions(+), 12 deletions(-) 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 a4b623542f6..cfe881265c6 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 072ffb4d24a..79a1fee21e0 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 3776130a65c..053c86e166d 100644 --- a/codegen/field.go +++ b/codegen/field.go @@ -471,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)", cases.Title(language.English).String(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)", cases.Title(language.English).String(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 6ab748a7580..a9cb34061b4 100644 --- a/codegen/object.go +++ b/codegen/object.go @@ -40,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, @@ -48,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(), cases.Title(language.English).String(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 019da8f073a..f9620411c62 100644 --- a/go.mod +++ b/go.mod @@ -14,12 +14,10 @@ require ( github.com/stretchr/testify v1.7.1 github.com/urfave/cli/v2 v2.8.1 github.com/vektah/gqlparser/v2 v2.4.5 + 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 ) -require ( - github.com/agnivade/levenshtein v1.1.1 // indirect - golang.org/x/text v0.3.7 -) +require github.com/agnivade/levenshtein v1.1.1 // indirect diff --git a/plugin/resolvergen/resolver.go b/plugin/resolvergen/resolver.go index 668a8140bb1..a51e7cb0805 100644 --- a/plugin/resolvergen/resolver.go +++ b/plugin/resolvergen/resolver.go @@ -100,8 +100,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, cases.Title(language.English).String(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 {