Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 6 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,15 @@ linters-settings:
files: $all
allow:
- $gostd
# depguard resolves imports by longest-prefix match, so the
# "go.yaml.in/..." entry below registers a "go" prefix that shadows
# the shorter $gostd-provided stdlib "go/..." packages (go/token,
# go/ast, ...). Re-allow them explicitly.
- go/
- github.com/Khan/genqlient
- github.com/vektah/gqlparser/v2
- golang.org/x/tools
- gopkg.in/yaml.v2
- go.yaml.in/yaml/v3
- github.com/alexflint/go-arg
- github.com/bmatcuk/doublestar/v4
- github.com/google/uuid
Expand Down
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Note that genqlient now requires Go 1.23 or higher, and is tested through Go 1.2

### Bug fixes:

- replaced the archived `gopkg.in/yaml.v2` dependency with the maintained `go.yaml.in/yaml/v3` (the YAML organization's successor to `gopkg.in/yaml.v3`) for config parsing.
- fixed `pointer_omitempty` not being applied to list types when `use_struct_references` is enabled. List fields like `[String!]` now correctly get the `omitempty` JSON tag.
- fixed minor typos and grammatical issues across the project

Expand Down
11 changes: 8 additions & 3 deletions generate/config.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package generate

import (
"bytes"
_ "embed"
"errors"
"fmt"
"go/token"
"io"
"os"
"path/filepath"
"strings"

"go.yaml.in/yaml/v3"
"golang.org/x/tools/go/packages"
"gopkg.in/yaml.v2"
)

var cfgFilenames = []string{".genqlient.yml", ".genqlient.yaml", "genqlient.yml", "genqlient.yaml"}
Expand Down Expand Up @@ -323,8 +326,10 @@ func ReadAndValidateConfig(filename string) (*Config, error) {
}

var config Config
err = yaml.UnmarshalStrict(text, &config)
if err != nil {
dec := yaml.NewDecoder(bytes.NewReader(text))
dec.KnownFields(true)
err = dec.Decode(&config)
if err != nil && !errors.Is(err, io.EOF) {
return nil, errorf(nil, "invalid config file %v: %v", filename, err)
}

Expand Down
7 changes: 5 additions & 2 deletions generate/generate_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package generate

import (
"bytes"
"errors"
"fmt"
"os"
Expand All @@ -9,7 +10,7 @@ import (
"strings"
"testing"

"gopkg.in/yaml.v2"
"go.yaml.in/yaml/v3"

"github.com/Khan/genqlient/internal/testutil"
)
Expand Down Expand Up @@ -133,7 +134,9 @@ func getDefaultConfig(t *testing.T) *Config {
t.Fatal(err)
}

err = yaml.UnmarshalStrict(b, &config)
dec := yaml.NewDecoder(bytes.NewReader(b))
dec.KnownFields(true)
err = dec.Decode(&config)
if err != nil {
t.Fatal(err)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
(*generate.Config)({
Schema: (generate.StringList) (len=1) {
(string) (len=35) "testdata/validConfig/schema.graphql"
},
Operations: (generate.StringList) (len=1) {
(string) (len=39) "testdata/validConfig/operations.graphql"
},
Generated: (string) (len=33) "testdata/validConfig/generated.go",
Package: (string) (len=11) "validConfig",
ExportOperations: (string) (len=25) "testdata/validConfig/0777",
ContextType: (string) (len=15) "context.Context",
ClientGetter: (string) "",
Bindings: (map[string]*generate.TypeBinding) <nil>,
PackageBindings: ([]*generate.PackageBinding) <nil>,
Casing: (generate.Casing) {
Default: (generate.CasingAlgorithm) "",
AllEnums: (generate.CasingAlgorithm) "",
Enums: (map[string]generate.CasingAlgorithm) <nil>
},
Optional: (string) "",
OptionalGenericType: (string) "",
StructReferences: (bool) true,
Extensions: (bool) true,
Comment thread
benjaminjkraft marked this conversation as resolved.
Resolved
Flatten: (bool) false,
baseDir: (string) (len=20) "testdata/validConfig",
pkgPath: (string) (len=55) "github.com/Khan/genqlient/generate/testdata/validConfig"
})
10 changes: 10 additions & 0 deletions generate/testdata/validConfig/YAML11Booleans.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
schema: schema.graphql
operations: operations.graphql

# YAML 1.1 boolean spellings (yes/no/on/off) must still decode to bools, as
# they did under gopkg.in/yaml.v2, to avoid breaking existing config files.
use_struct_references: yes
use_extensions: on

# Octal-looking strings must stay strings (e.g. "0777", not 511).
export_operations: 0777
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ require (
github.com/gorilla/websocket v1.5.0
github.com/stretchr/testify v1.9.0
github.com/vektah/gqlparser/v2 v2.5.19
go.yaml.in/yaml/v3 v3.0.4
golang.org/x/tools v0.36.0
gopkg.in/yaml.v2 v2.4.0
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum

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

Loading