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

Update Go (and golangci-lint, and gqlgen) versions, and test codegen #362

Merged
merged 4 commits into from
Nov 30, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Update Go (and golangci-lint, and gqlgen) versions, and test codegen
Originally my goal here was to add a check that generated code is up to
date. (In #360 I was reminded that we have that for first-party code,
but not gqlgen.)

Then I figured I'd update the Go version to support 1.23, which required
updating gqlgen and golangci-lint, both of which now have minimum Go
versions of 1.22. So now that's ours too. Those are the only upstream
supported versions anyway, so hopefully people are updated.

I suspect the CI version-setting stuff can get simplified a bit with all
the Go toolchain version stuff, but for now I didn't bother.
benjaminjkraft committed Nov 30, 2024
commit b0ca2443be6274857973b3aa3c0037599379ee90
26 changes: 23 additions & 3 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go: [ '1.20', '1.21', '1.22' ]
go: [ '1.22', '1.23' ]

steps:
- name: Set up Go
@@ -39,7 +39,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.22'
go-version: '1.23'
id: go

- name: Git checkout
@@ -48,4 +48,24 @@ jobs:
- name: Run lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.56.1 # should match internal/lint/go.mod
version: v1.62.2 # should match internal/lint/go.mod

generate:
name: Check generated code
runs-on: ubuntu-latest

steps:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.23'
id: go

- name: Git checkout
uses: actions/checkout@v2

- name: Check up to date
run: |
go generate -v -x ./...
echo "if this fails, please check in the results of `go generate ./...`"
git diff --exit-code
2 changes: 2 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -20,6 +20,8 @@ When releasing a new version:

<!-- Add new changes in this section! -->

Note that genqlient now requires Go 1.22.5 or higher, and is tested through Go 1.23.3.

### Breaking changes:

- omitempty validation:
4 changes: 2 additions & 2 deletions generate/types.go
Original file line number Diff line number Diff line change
@@ -351,7 +351,7 @@ func (typ *goStructType) FlattenedFields() ([]*selector, error) {
field := queue[0]
queue = queue[1:]
if field.IsEmbedded() {
typ, ok := field.GoType.(*goStructType)
structField, ok := field.GoType.(*goStructType)
if !ok {
// Should never happen: embeds correspond to named fragments,
// and even if the fragment is of interface type in GraphQL,
@@ -365,7 +365,7 @@ func (typ *goStructType) FlattenedFields() ([]*selector, error) {
}

// Enqueue the embedded fields for our BFS.
for _, subField := range typ.Fields {
for _, subField := range structField.Fields {
queue = append(queue,
&selector{subField, field.Selector + "." + subField.Selector()})
}
6 changes: 3 additions & 3 deletions generate/validation.go
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ func selectionsMatch(
actual, ok := actualSelectionSet[i].(*ast.Field)
switch {
case !ok:
return errorf(actual.Position,
return errorf(pos,
"expected selection #%d to be field, got %T",
i, actualSelectionSet[i])
case actual.Name != expected.Name:
@@ -55,7 +55,7 @@ func selectionsMatch(
actual, ok := actualSelectionSet[i].(*ast.InlineFragment)
switch {
case !ok:
return errorf(actual.Position,
return errorf(pos,
"expected selection %d to be inline fragment, got %T",
i, actualSelectionSet[i])
case actual.TypeCondition != expected.TypeCondition:
@@ -71,7 +71,7 @@ func selectionsMatch(
actual, ok := actualSelectionSet[i].(*ast.FragmentSpread)
switch {
case !ok:
return errorf(actual.Position,
return errorf(pos,
"expected selection %d to be fragment spread, got %T",
i, actualSelectionSet[i])
case actual.Name != expected.Name:
17 changes: 10 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
module github.com/Khan/genqlient

go 1.20
go 1.22.5

toolchain go1.23.3

require (
github.com/99designs/gqlgen v0.17.44
github.com/99designs/gqlgen v0.17.57
github.com/alexflint/go-arg v1.4.2
github.com/bmatcuk/doublestar/v4 v4.6.1
github.com/bradleyjkemp/cupaloy/v2 v2.6.0
github.com/google/uuid v1.6.0
github.com/gorilla/websocket v1.5.0
github.com/stretchr/testify v1.9.0
github.com/vektah/gqlparser/v2 v2.5.16
golang.org/x/tools v0.18.0
github.com/vektah/gqlparser/v2 v2.5.19
golang.org/x/tools v0.24.0
gopkg.in/yaml.v2 v2.4.0
)

require (
github.com/agnivade/levenshtein v1.1.1 // indirect
github.com/alexflint/go-scalar v1.0.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-viper/mapstructure/v2 v2.2.1 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/sosodev/duration v1.2.0 // indirect
golang.org/x/mod v0.15.0 // indirect
github.com/sosodev/duration v1.3.1 // indirect
golang.org/x/mod v0.20.0 // indirect
golang.org/x/sync v0.8.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
29 changes: 16 additions & 13 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions internal/integration/integration_test.go
Original file line number Diff line number Diff line change
@@ -820,9 +820,6 @@ func TestFlatten(t *testing.T) {
}

func TestGeneratedCode(t *testing.T) {
// TODO(benkraft): Check that gqlgen is up to date too. In practice that's
// less likely to be a problem, since it should only change if you update
// the schema, likely too add something new, in which case you'll notice.
RunGenerateTest(t, "internal/integration/genqlient.yaml")
}

Loading