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

Replace use of strings.Title with cases.Title #2268

Merged
merged 11 commits into from
Jul 3, 2022
Merged
11 changes: 10 additions & 1 deletion .github/workflows/check-federation
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@ cd _examples/federation

./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
Expand Down
10 changes: 9 additions & 1 deletion .github/workflows/check-integration
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 26 additions & 9 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,52 @@
name: Integration
on: [push, pull_request]

env:
GO_VERSION: 1.16

jobs:
integration:
strategy:
matrix:
go: [1.16, 1.18]
node: [14]
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: ${{ matrix.node }}
- run: go mod download
- run: cd integration ; npm install
- run: .github/workflows/check-integration

federation:
strategy:
matrix:
go: [1.16, 1.18]
node: [14]
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: ${{ matrix.node }}
- run: go mod download
- run: cd _examples/federation ; npm install
- run: .github/workflows/check-federation

init:
strategy:
matrix:
go: [1.16, 1.18]
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
21 changes: 13 additions & 8 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,46 @@
name: Lint
on: [push, pull_request]

env:
GO_VERSION: 1.16

jobs:
lint:
strategy:
matrix:
go: [1.16, 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
- run: .github/workflows/check-fmt
- run: .github/workflows/check-generate

coverage:
strategy:
matrix:
go: [1.16, 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
- run: .github/workflows/check-coverage
env:
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}

golangci-lint:
strategy:
matrix:
go: [1.16, 1.18]
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:
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/security.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
name: Security
on: [push, pull_request]

env:
GO_VERSION: 1.16

jobs:
nancy:
strategy:
matrix:
go: [1.16, 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
8 changes: 3 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,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.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 ./...
1 change: 1 addition & 0 deletions _examples/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
1 change: 1 addition & 0 deletions _examples/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
1 change: 1 addition & 0 deletions _examples/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ package main

import (
_ "github.com/vektah/dataloaden"
_ "golang.org/x/text"
)
7 changes: 5 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 @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions 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 @@ -38,15 +40,15 @@ 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,
DisableConcurrency: typ == b.Schema.Mutation,
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,
),
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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.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
Expand Down
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
5 changes: 4 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 @@ -98,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, 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 {
Expand Down