Skip to content

Commit

Permalink
Update Go (and golangci-lint, and gqlgen) versions, and test codegen (#…
Browse files Browse the repository at this point in the history
…362)

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.

I have:
- [x] Written a clear PR title and description (above)
- [x] Signed the [Khan Academy CLA](https://www.khanacademy.org/r/cla)
- [x] Added tests covering my changes, if applicable
- [x] Included a link to the issue fixed, if applicable
- [x] Included documentation, for new features
- [x] Added an entry to the changelog
  • Loading branch information
benjaminjkraft authored Nov 30, 2024
1 parent 800909d commit 1147aaf
Show file tree
Hide file tree
Showing 13 changed files with 720 additions and 471 deletions.
26 changes: 23 additions & 3 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions generate/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()})
}
Expand Down
6 changes: 3 additions & 3 deletions generate/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down
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
Expand Up @@ -921,9 +921,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")
}

Expand Down
Loading

0 comments on commit 1147aaf

Please sign in to comment.