diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 91c3c25a..ddd9c326 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -1,21 +1,28 @@ name: Go on: push: - branches: [ master ] + branches: [main] pull_request: - branches: [ master ] + branches: [main] + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: build: name: Build runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v5 - with: - go-version-file: go.mod - - run: go mod download - - uses: golangci/golangci-lint-action@v8 - with: - version: latest - - run: go build -v . - - run: make test + - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 + - uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0 + with: + go-version-file: go.mod + - uses: golangci/golangci-lint-action@82606bf257cbaff209d206a39f5134f0cfbfd2ee # v9.2.1 + with: + version: v2.12.2 + - run: make build + - run: make test diff --git a/Makefile b/Makefile index 40e5c201..e09dd8ec 100644 --- a/Makefile +++ b/Makefile @@ -6,8 +6,11 @@ fmt: lint: golangci-lint cache clean && golangci-lint run +build: + go build -v ./... + test: - go test -v ./... + go test -race -v ./... compat: go tool gorelease diff --git a/clientgenv2/template.go b/clientgenv2/template.go index 199eaf9c..0731c542 100644 --- a/clientgenv2/template.go +++ b/clientgenv2/template.go @@ -36,7 +36,7 @@ func RenderTemplate(cfg *config.Config, fragments []*Fragment, operations []*Ope Packages: cfg.Packages, PackageDoc: "// Code generated by github.com/gqlgo/gqlgenc, DO NOT EDIT.\n", Funcs: map[string]any{ - "genGetters": genGettersGenerator.GenFunc(), + "genGetters": genGettersGenerator.GenFunc(), "genConversionGetters": genGettersGenerator.ConversionGettersFunc(fragments), }, }) @@ -85,39 +85,6 @@ func (g *GenGettersGenerator) GenFunc() func(name string, p types.Type) string { } } -func (g *GenGettersGenerator) returnTypeName(t types.Type, nested bool) string { - switch it := t.(type) { - case *types.Basic: - return it.String() - case *types.Pointer: - return "*" + g.returnTypeName(it.Elem(), true) - case *types.Slice: - return "[]" + g.returnTypeName(it.Elem(), true) - case *types.Named: - s := strings.Split(it.String(), ".") - name := s[len(s)-1] - - isImported := it.Obj().Parent() != nil && it.Obj().Pkg().Name() != g.ClientPackageName - if isImported { - name = namedTypeString(it) - } - - if nested { - return name - } - - return "*" + name - case *types.Interface: - return "any" - case *types.Map: - return "map[" + g.returnTypeName(it.Key(), true) + "]" + g.returnTypeName(it.Elem(), true) - case *types.Alias: - return g.returnTypeName(it.Underlying(), nested) - default: - return fmt.Sprintf("%T----", it) - } -} - // ConversionGettersFunc returns a template function that generates conversion getters // for spread fragments. Each getter constructs the original fragment type from the // flattened parent struct's fields. @@ -165,7 +132,7 @@ func resolveTargetFragment(fragmentMap map[string]*Fragment, spread *SpreadFragm // writeConversionGetter writes a single conversion getter method that constructs // the target fragment type from the owner struct's fields. -func (g *GenGettersGenerator) writeConversionGetter(buf *bytes.Buffer, ownerName string, targetTypeName string, targetStruct *types.Struct) { +func (g *GenGettersGenerator) writeConversionGetter(buf *bytes.Buffer, ownerName, targetTypeName string, targetStruct *types.Struct) { buf.WriteString("func (t *" + ownerName + ") Get" + targetTypeName + "() *" + targetTypeName + " {\n") buf.WriteString("if t == nil {\n t = &" + ownerName + "{}\n}\n") buf.WriteString("return &" + targetTypeName + "{\n") @@ -197,6 +164,39 @@ func (g *GenGettersGenerator) writeFieldAssignment(buf *bytes.Buffer, field *typ } } +func (g *GenGettersGenerator) returnTypeName(t types.Type, nested bool) string { + switch it := t.(type) { + case *types.Basic: + return it.String() + case *types.Pointer: + return "*" + g.returnTypeName(it.Elem(), true) + case *types.Slice: + return "[]" + g.returnTypeName(it.Elem(), true) + case *types.Named: + s := strings.Split(it.String(), ".") + name := s[len(s)-1] + + isImported := it.Obj().Parent() != nil && it.Obj().Pkg().Name() != g.ClientPackageName + if isImported { + name = namedTypeString(it) + } + + if nested { + return name + } + + return "*" + name + case *types.Interface: + return "any" + case *types.Map: + return "map[" + g.returnTypeName(it.Key(), true) + "]" + g.returnTypeName(it.Elem(), true) + case *types.Alias: + return g.returnTypeName(it.Underlying(), nested) + default: + return fmt.Sprintf("%T----", it) + } +} + // typeName extracts the short type name from a types.Type. func (g *GenGettersGenerator) typeName(t types.Type) string { switch it := t.(type) { diff --git a/clientv2/client.go b/clientv2/client.go index cc5d6137..24b438d5 100644 --- a/clientv2/client.go +++ b/clientv2/client.go @@ -516,7 +516,7 @@ func (e *Encoder) Encode(v reflect.Value) ([]byte, error) { t := v.Type() switch t.Kind() { - case reflect.Ptr: + case reflect.Pointer: return e.encodePtr(v) case reflect.Struct: return e.encodeStruct(v) @@ -863,7 +863,7 @@ func (e *Encoder) prepareFields(t reflect.Type) []fieldInfo { func isNil(v reflect.Value) bool { switch v.Kind() { - case reflect.Ptr, reflect.Map, reflect.Slice, reflect.Chan, reflect.Func, reflect.Interface: + case reflect.Pointer, reflect.Map, reflect.Slice, reflect.Chan, reflect.Func, reflect.Interface: return v.IsNil() default: return false diff --git a/example/autobind/gen/client.go b/example/autobind/gen/client.go index af260565..f14b7211 100644 --- a/example/autobind/gen/client.go +++ b/example/autobind/gen/client.go @@ -4,7 +4,6 @@ package gen import ( "context" - "net/http" "github.com/gqlgo/gqlgenc/clientv2" ) @@ -17,7 +16,7 @@ type Client struct { Client *clientv2.Client } -func NewClient(cli *http.Client, baseURL string, options *clientv2.Options, interceptors ...clientv2.RequestInterceptor) GithubGraphQLClient { +func NewClient(cli clientv2.HttpClient, baseURL string, options *clientv2.Options, interceptors ...clientv2.RequestInterceptor) GithubGraphQLClient { return &Client{Client: clientv2.NewClient(cli, baseURL, options, interceptors...)} } @@ -33,14 +32,14 @@ func (t *GetUserProfileName_User_Profile) GetName() string { } type GetUserProfileName_User struct { - Profile GetUserProfileName_User_Profile "json:\"profile\" graphql:\"profile\"" + Profile *GetUserProfileName_User_Profile "json:\"profile,omitempty\" graphql:\"profile\"" } func (t *GetUserProfileName_User) GetProfile() *GetUserProfileName_User_Profile { if t == nil { t = &GetUserProfileName_User{} } - return &t.Profile + return t.Profile } type GetUserProfileName struct { diff --git a/example/autobind/model/models_gen.go b/example/autobind/model/models_gen.go index 39279c0c..17748e56 100644 --- a/example/autobind/model/models_gen.go +++ b/example/autobind/model/models_gen.go @@ -10,5 +10,5 @@ type Query struct { type User struct { ID string `json:"id"` - Profile *Profile `json:"profile"` + Profile *Profile `json:"profile,omitempty"` } diff --git a/example/enum-directive/gen/client.go b/example/enum-directive/gen/client.go index cdac04d6..d0d6c0fe 100644 --- a/example/enum-directive/gen/client.go +++ b/example/enum-directive/gen/client.go @@ -3,8 +3,6 @@ package gen import ( - "net/http" - "github.com/gqlgo/gqlgenc/clientv2" ) @@ -15,7 +13,7 @@ type Client struct { Client *clientv2.Client } -func NewClient(cli *http.Client, baseURL string, options *clientv2.Options, interceptors ...clientv2.RequestInterceptor) GithubGraphQLClient { +func NewClient(cli clientv2.HttpClient, baseURL string, options *clientv2.Options, interceptors ...clientv2.RequestInterceptor) GithubGraphQLClient { return &Client{Client: clientv2.NewClient(cli, baseURL, options, interceptors...)} } diff --git a/example/files-info/main.go b/example/files-info/main.go index 9cde4b0a..94c355df 100644 --- a/example/files-info/main.go +++ b/example/files-info/main.go @@ -18,10 +18,6 @@ const FilesDir = "./example/files-info/files/" const imageFile = "mario-strikers_1600w_original.jpg" -func newof[T any](val T) *T { - return &val -} - func getFiles(files ...string) ([]*graphql.Upload, error) { result := make([]*graphql.Upload, len(files)) @@ -31,7 +27,7 @@ func getFiles(files ...string) ([]*graphql.Upload, error) { return result, err } - result[i] = newof(uFile) + result[i] = &uFile } return result, nil diff --git a/example/input-scalar/gen/client.go b/example/input-scalar/gen/client.go index e3b27712..3eb43341 100644 --- a/example/input-scalar/gen/client.go +++ b/example/input-scalar/gen/client.go @@ -4,7 +4,6 @@ package gen import ( "context" - "net/http" "github.com/gqlgo/gqlgenc/clientv2" "github.com/gqlgo/gqlgenc/example/input-scalar/scalar" @@ -18,7 +17,7 @@ type Client struct { Client *clientv2.Client } -func NewClient(cli *http.Client, baseURL string, options *clientv2.Options, interceptors ...clientv2.RequestInterceptor) GithubGraphQLClient { +func NewClient(cli clientv2.HttpClient, baseURL string, options *clientv2.Options, interceptors ...clientv2.RequestInterceptor) GithubGraphQLClient { return &Client{Client: clientv2.NewClient(cli, baseURL, options, interceptors...)} } diff --git a/example/no-autobind/gen/client.go b/example/no-autobind/gen/client.go index af260565..13785f86 100644 --- a/example/no-autobind/gen/client.go +++ b/example/no-autobind/gen/client.go @@ -4,7 +4,6 @@ package gen import ( "context" - "net/http" "github.com/gqlgo/gqlgenc/clientv2" ) @@ -17,7 +16,7 @@ type Client struct { Client *clientv2.Client } -func NewClient(cli *http.Client, baseURL string, options *clientv2.Options, interceptors ...clientv2.RequestInterceptor) GithubGraphQLClient { +func NewClient(cli clientv2.HttpClient, baseURL string, options *clientv2.Options, interceptors ...clientv2.RequestInterceptor) GithubGraphQLClient { return &Client{Client: clientv2.NewClient(cli, baseURL, options, interceptors...)} } diff --git a/generator/testdata/nullable_input_omittable/e2e_test.go b/generator/testdata/nullable_input_omittable/e2e_test.go index 66395ad2..e2f9b5de 100644 --- a/generator/testdata/nullable_input_omittable/e2e_test.go +++ b/generator/testdata/nullable_input_omittable/e2e_test.go @@ -7,6 +7,7 @@ import ( "testing" "github.com/99designs/gqlgen/graphql" + "github.com/gqlgo/gqlgenc/clientv2" generated "github.com/gqlgo/gqlgenc/generator/testdata/nullable_input_omittable/expected" ) diff --git a/go.mod b/go.mod index be4df946..96e31c79 100644 --- a/go.mod +++ b/go.mod @@ -1,16 +1,18 @@ module github.com/gqlgo/gqlgenc -go 1.26.2 +go 1.26 + +toolchain go1.26.4 require ( - github.com/99designs/gqlgen v0.17.73 - github.com/goccy/go-yaml v1.17.1 + github.com/99designs/gqlgen v0.17.91 + github.com/goccy/go-yaml v1.19.2 github.com/google/go-cmp v0.7.0 github.com/google/uuid v1.6.0 - github.com/stretchr/testify v1.10.0 - github.com/vektah/gqlparser/v2 v2.5.26 - golang.org/x/text v0.24.0 - golang.org/x/tools v0.42.0 + github.com/stretchr/testify v1.11.1 + github.com/vektah/gqlparser/v2 v2.5.34 + golang.org/x/text v0.38.0 + golang.org/x/tools v0.46.0 ) require ( @@ -22,7 +24,7 @@ require ( github.com/kr/pretty v0.3.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/rogpeppe/go-internal v1.14.1 // indirect - github.com/sosodev/duration v1.3.1 // indirect + github.com/sosodev/duration v1.4.0 // indirect github.com/spf13/cobra v1.6.1 // indirect github.com/spf13/pflag v1.0.5 // indirect go.uber.org/atomic v1.7.0 // indirect @@ -30,8 +32,8 @@ require ( go.uber.org/zap v1.24.0 // indirect go.yaml.in/yaml/v3 v3.0.4 // indirect golang.org/x/exp v0.0.0-20251219203646-944ab1f22d93 // indirect - golang.org/x/mod v0.33.0 // indirect - golang.org/x/sync v0.19.0 // indirect + golang.org/x/mod v0.37.0 // indirect + golang.org/x/sync v0.21.0 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 16fc7e5d..a18448c5 100644 --- a/go.sum +++ b/go.sum @@ -1,13 +1,13 @@ -github.com/99designs/gqlgen v0.17.73 h1:A3Ki+rHWqKbAOlg5fxiZBnz6OjW3nwupDHEG15gEsrg= -github.com/99designs/gqlgen v0.17.73/go.mod h1:2RyGWjy2k7W9jxrs8MOQthXGkD3L3oGr0jXW3Pu8lGg= +github.com/99designs/gqlgen v0.17.91 h1:/mIvXnN0lAorqszP3Vukw10SVRfLVUYtBTQFwmYRMmI= +github.com/99designs/gqlgen v0.17.91/go.mod h1:N7+yJF6zbGIEqohF+ZtEUp/eq2dTnn0bDizLUIYPUCU= github.com/agnivade/levenshtein v1.2.1 h1:EHBY3UOn1gwdy/VbFwgo4cxecRznFk7fKWN1KOX7eoM= github.com/agnivade/levenshtein v1.2.1/go.mod h1:QVVI16kDrtSuwcpd0p1+xMC6Z/VfhtCyDIjcwga4/DU= -github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ= -github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8= github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0 h1:jfIu9sQUG6Ig+0+Ap1h4unLjW6YQJpKZVmUzxsD4E/Q= github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0/go.mod h1:t2tdKJDJF9BV14lnkjHmOQgcvEKgtqs5a1N3LNdJhGE= github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= +github.com/coder/websocket v1.8.14 h1:9L0p0iKiNOibykf283eHkKUHHrpG7f65OE3BhhO7v9g= +github.com/coder/websocket v1.8.14/go.mod h1:NX3SzP+inril6yawo5CQXx8+fk145lPDC6pumgx0mVg= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/daixiang0/gci v0.14.0 h1:h6AcLqmjIOBgojhtzY2CvBnA6RawPTkBHgtMvYD5YZ8= @@ -17,10 +17,10 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgryski/trifles v0.0.0-20230903005119-f50d829f2e54 h1:SG7nF6SRlWhcT7cNTs5R6Hk4V2lcmLz2NsG2VnInyNo= github.com/dgryski/trifles v0.0.0-20230903005119-f50d829f2e54/go.mod h1:if7Fbed8SFyPtHLHbg49SI7NAdJiC5WIA09pe59rfAA= -github.com/go-viper/mapstructure/v2 v2.2.1 h1:ZAaOCxANMuZx5RCeg0mBdEZk7DZasvvZIxtHqx8aGss= -github.com/go-viper/mapstructure/v2 v2.2.1/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM= -github.com/goccy/go-yaml v1.17.1 h1:LI34wktB2xEE3ONG/2Ar54+/HJVBriAGJ55PHls4YuY= -github.com/goccy/go-yaml v1.17.1/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA= +github.com/go-viper/mapstructure/v2 v2.5.0 h1:vM5IJoUAy3d7zRSVtIwQgBj7BiWtMPfmPEgAXnvj1Ro= +github.com/go-viper/mapstructure/v2 v2.5.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM= +github.com/goccy/go-yaml v1.19.2 h1:PmFC1S6h8ljIz6gMRBopkjP1TVT7xuwrButHID66PoM= +github.com/goccy/go-yaml v1.19.2/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= @@ -49,20 +49,18 @@ github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/f github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ= github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8= -github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I= -github.com/sosodev/duration v1.3.1 h1:qtHBDMQ6lvMQsL15g4aopM4HEfOaYuhWBw3NPTtlqq4= -github.com/sosodev/duration v1.3.1/go.mod h1:RQIBBX0+fMLc/D9+Jb/fwvVmo0eZvDDEERAikUR6SDg= +github.com/sosodev/duration v1.4.0 h1:35ed0KiVFriGHHzZZJaZLgmTEEICIyt8Sx0RQfj9IjE= +github.com/sosodev/duration v1.4.0/go.mod h1:RQIBBX0+fMLc/D9+Jb/fwvVmo0eZvDDEERAikUR6SDg= github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA= github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= -github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/vektah/gqlparser/v2 v2.5.26 h1:REqqFkO8+SOEgZHR/eHScjjVjGS8Nk3RMO/juiTobN4= -github.com/vektah/gqlparser/v2 v2.5.26/go.mod h1:D1/VCZtV3LPnQrcPBeR/q5jkSQIPti0uYCP/RI0gIeo= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= +github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= +github.com/vektah/gqlparser/v2 v2.5.34 h1:MEea5P0qhdcqfBL45ghKE+qr9laidVHTMHjav5h7ckk= +github.com/vektah/gqlparser/v2 v2.5.34/go.mod h1:mFdHLGCio7OGX1fby9ZjTW6FN+qxgmbnBcRIeeScE5s= go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI= @@ -75,14 +73,14 @@ go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc= go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg= golang.org/x/exp v0.0.0-20251219203646-944ab1f22d93 h1:fQsdNF2N+/YewlRZiricy4P1iimyPKZ/xwniHj8Q2a0= golang.org/x/exp v0.0.0-20251219203646-944ab1f22d93/go.mod h1:EPRbTFwzwjXj9NpYyyrvenVh9Y+GFeEvMNh7Xuz7xgU= -golang.org/x/mod v0.33.0 h1:tHFzIWbBifEmbwtGz65eaWyGiGZatSrT9prnU8DbVL8= -golang.org/x/mod v0.33.0/go.mod h1:swjeQEj+6r7fODbD2cqrnje9PnziFuw4bmLbBZFrQ5w= -golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4= -golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI= -golang.org/x/text v0.24.0 h1:dd5Bzh4yt5KYA8f9CJHCP4FB4D51c2c6JvN37xJJkJ0= -golang.org/x/text v0.24.0/go.mod h1:L8rBsPeo2pSS+xqN0d5u2ikmjtmoJbDBT1b7nHvFCdU= -golang.org/x/tools v0.42.0 h1:uNgphsn75Tdz5Ji2q36v/nsFSfR/9BRFvqhGBaJGd5k= -golang.org/x/tools v0.42.0/go.mod h1:Ma6lCIwGZvHK6XtgbswSoWroEkhugApmsXyrUmBhfr0= +golang.org/x/mod v0.37.0 h1:vF1DjpVEshcIqoEaauuHebaLk1O1forxjxBaVn884JQ= +golang.org/x/mod v0.37.0/go.mod h1:m8S8VeM9r4dzDwjrKO0a1sZP3YjeMamRRlD+fmR2Q/0= +golang.org/x/sync v0.21.0 h1:HLII4xRRTtCRkxYp4HNFF0Js/Og6q2i++KXbg0gHCwM= +golang.org/x/sync v0.21.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0= +golang.org/x/text v0.38.0 h1:sXmwo9DwP3OK9EZ7PqAdaooSGozfl/3a6/xJcbzPRhE= +golang.org/x/text v0.38.0/go.mod h1:YXZt3QhHUKYT53r2lLKFIVi6Ao1jdzrTR/KQ09qyxF4= +golang.org/x/tools v0.46.0 h1:7jTurBkPZu4moS/Uy4OQT1M+QBlsj3wejyZwsT8Z7rk= +golang.org/x/tools v0.46.0/go.mod h1:FrD85F8l+NWL+9XWBSyVSHO6Ne4jutsfIFba7AWQ5Ys= golang.org/x/tools/go/expect v0.1.1-deprecated h1:jpBZDwmgPhXsKZC6WhL20P4b/wmnpsEAGHaNy0n/rJM= golang.org/x/tools/go/expect v0.1.1-deprecated/go.mod h1:eihoPOH+FgIqa3FpoTwguz/bVUSGBlGQU67vpBeOrBY= golang.org/x/tools/go/packages/packagestest v0.1.1-deprecated h1:1h2MnaIAIXISqTFKdENegdpAgUXz6NrPEsbIeWaBRvM= diff --git a/graphqljson/graphql.go b/graphqljson/graphql.go index e9e0176e..77a4a7f8 100644 --- a/graphqljson/graphql.go +++ b/graphqljson/graphql.go @@ -105,7 +105,7 @@ func newDecoder(r io.Reader) *Decoder { // Decode decodes a single JSON value from d.tokenizer into v. func (d *Decoder) Decode(v any) error { rv := reflect.ValueOf(v) - if rv.Kind() != reflect.Ptr { + if rv.Kind() != reflect.Pointer { return fmt.Errorf("cannot decode into non-pointer %T", v) } @@ -165,7 +165,7 @@ func (d *Decoder) decode() error { //nolint:maintidx // If v is a nil pointer, check whether the key exists in the pointed-to // type before initializing — preserves nil for non-matching union variants. // When a __typename was seen, also require the fragment type to match. - if v.Kind() == reflect.Ptr && v.IsNil() && v.CanSet() { + if v.Kind() == reflect.Pointer && v.IsNil() && v.CanSet() { if elemType := v.Type().Elem(); elemType.Kind() == reflect.Struct { if fieldByGraphQLName(reflect.New(elemType).Elem(), key).IsValid() && d.shouldInitFragPtr(i) { v.Set(reflect.New(elemType)) @@ -173,7 +173,7 @@ func (d *Decoder) decode() error { //nolint:maintidx } } - if v.Kind() == reflect.Ptr { + if v.Kind() == reflect.Pointer { v = v.Elem() } @@ -227,7 +227,7 @@ func (d *Decoder) decode() error { //nolint:maintidx for i := range d.vs { v := d.vs[i][len(d.vs[i])-1] - if v.Kind() == reflect.Ptr { + if v.Kind() == reflect.Pointer { v = v.Elem() } @@ -256,7 +256,7 @@ func (d *Decoder) decode() error { //nolint:maintidx continue } - if v.Kind() == reflect.Ptr || v.Kind() == reflect.Slice { + if v.Kind() == reflect.Pointer || v.Kind() == reflect.Slice { // Set the pointer or slice to nil. v.Set(reflect.Zero(v.Type())) } else { @@ -276,13 +276,13 @@ func (d *Decoder) decode() error { //nolint:maintidx } // Initialize the pointer if it is nil - if v.Kind() == reflect.Ptr && v.IsNil() { + if v.Kind() == reflect.Pointer && v.IsNil() { v.Set(reflect.New(v.Type().Elem())) } // Handle both pointer and non-pointer types target := v - if v.Kind() == reflect.Ptr { + if v.Kind() == reflect.Pointer { target = v.Elem() } @@ -325,7 +325,7 @@ func (d *Decoder) decode() error { //nolint:maintidx v := d.vs[i][len(d.vs[i])-1] frontier[i] = v // TODO: Do this recursively or not? Add a test case if needed. - if v.Kind() == reflect.Ptr && v.IsNil() { + if v.Kind() == reflect.Pointer && v.IsNil() { v.Set(reflect.New(v.Type().Elem())) // v = new(T). } } @@ -335,7 +335,7 @@ func (d *Decoder) decode() error { //nolint:maintidx v := frontier[0] frontier = frontier[1:] - if v.Kind() == reflect.Ptr { + if v.Kind() == reflect.Pointer { v = v.Elem() } @@ -360,12 +360,12 @@ func (d *Decoder) decode() error { //nolint:maintidx for i := range d.vs { v := d.vs[i][len(d.vs[i])-1] // TODO: Confirm this is needed, write a test case. - // if v.Kind() == reflect.Ptr && v.IsNil() { + // if v.Kind() == reflect.Pointer && v.IsNil() { // v.Set(reflect.New(v.Type().Elem())) // v = new(T). //} // Reset slice to empty (in case it had non-zero initial value). - if v.Kind() == reflect.Ptr { + if v.Kind() == reflect.Pointer { v = v.Elem() } diff --git a/querydocument/query_document_test.go b/querydocument/query_document_test.go index 73f4cde4..73e1142c 100644 --- a/querydocument/query_document_test.go +++ b/querydocument/query_document_test.go @@ -4,10 +4,11 @@ import ( "testing" "github.com/stretchr/testify/require" - "github.com/vektah/gqlparser/v2" - "github.com/vektah/gqlparser/v2/ast" "github.com/gqlgo/gqlgenc/querydocument" + + "github.com/vektah/gqlparser/v2" + "github.com/vektah/gqlparser/v2/ast" ) const testSchema = ` @@ -146,5 +147,4 @@ func TestCollectTypesFromQueryDocuments(t *testing.T) { require.True(t, usedTypes["TodoStatus"], "enum selected inside a fragment spread should be collected") require.False(t, usedTypes["UnusedEnum"], "unreferenced enum should not be collected") }) - }