Skip to content

Commit

Permalink
Merge pull request #235 from golanglemonade/federation-gqlgen-breakin…
Browse files Browse the repository at this point in the history
…g-change

update for gqlgen 0.17.54 federation change
  • Loading branch information
Yamashou authored Sep 24, 2024
2 parents 8830a35 + 8f807fd commit c7df292
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
go-version-file: go.mod

- name: Install Lint
run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.54.2
run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.61.0

- name: Lint
run: make lint
Expand Down
21 changes: 4 additions & 17 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,44 +23,35 @@ linters:
- gochecknoinits
- gochecknoglobals
- godox
- maligned
- gocognit
- gocyclo
- interfacer
- gomnd
- goerr113
- exhaustivestruct
- err113
- errorlint # TODO able this lint
- forbidigo
- cyclop
- govet
- errname
- varnamelen
- nilnil
- structcheck
- exhaustruct
- nonamedreturns
- golint
- ifshort
- nosnakecase
- deadcode
- scopelint
- varcheck
- depguard
- musttag
- paralleltest
- nlreturn
- mnd
fast: true

issues:
fix: true
exclude-files:
- _test\.go
- examples/**/*\.go
- example/*/*.go
max-issues-per-linter: 0
max-same-issues: 0
exclude-dirs:
- examples
- example
exclude-rules:
# Test
- path: _test\.go
Expand All @@ -83,10 +74,6 @@ issues:
text: "`Extensions` is unused" # used in line 48
linters:
- structcheck
- path: introspection/query.go
text: "`Introspection` is unused" # used in config/config.go
linters:
- varcheck
- path: config/config.go
text: "`ClientV2` is unused" # used in config/config.go
linters:
Expand Down
2 changes: 1 addition & 1 deletion clientgenv2/source_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (rs ResponseFieldList) StructType() *types.Struct {
if !ok {
continue
}
for j := 0; j < typ.NumFields(); j++ {
for j := range typ.NumFields() {
vars = append(vars, typ.Field(j))
structTags = append(structTags, typ.Tag(j))
}
Expand Down
2 changes: 1 addition & 1 deletion clientgenv2/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (g *GenGettersGenerator) GenFunc() func(name string, p types.Type) string {
}
var buf bytes.Buffer

for i := 0; i < it.NumFields(); i++ {
for i := range it.NumFields() {
field := it.Field(i)

returns := g.returnTypeName(field.Type(), false)
Expand Down
12 changes: 6 additions & 6 deletions clientv2/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,8 @@ func (c *Client) do(_ context.Context, req *http.Request, _ *GQLRequestInfo, res

func (c *Client) parseResponse(body []byte, httpCode int, result interface{}) error {
errResponse := &ErrorResponse{}
isKOCode := httpCode < 200 || 299 < httpCode
if isKOCode {
isOKCode := httpCode < 200 || 299 < httpCode
if isOKCode {
errResponse.NetworkError = &HTTPError{
Code: httpCode,
Message: fmt.Sprintf("Response body %s", string(body)),
Expand All @@ -345,7 +345,7 @@ func (c *Client) parseResponse(body []byte, httpCode int, result interface{}) er
var gqlErr *GqlErrorList
if errors.As(err, &gqlErr) {
errResponse.GqlErrors = &gqlErr.Errors
} else if !isKOCode {
} else if !isOKCode {
return err
}
}
Expand Down Expand Up @@ -535,7 +535,7 @@ type fieldInfo struct {
func prepareFields(t reflect.Type) []fieldInfo {
num := t.NumField()
fields := make([]fieldInfo, 0, num)
for i := 0; i < num; i++ {
for i := range num {
f := t.Field(i)
if f.PkgPath != "" && !f.Anonymous { // Skip unexported fields unless they are embedded
continue
Expand Down Expand Up @@ -619,7 +619,7 @@ func encodeMap(v reflect.Value) ([]byte, error) {

func encodeSlice(v reflect.Value) ([]byte, error) {
result := make([]json.RawMessage, v.Len())
for i := 0; i < v.Len(); i++ {
for i := range v.Len() {
encodedValue, err := encode(v.Index(i))
if err != nil {
return nil, err
Expand All @@ -631,7 +631,7 @@ func encodeSlice(v reflect.Value) ([]byte, error) {

func encodeArray(v reflect.Value) ([]byte, error) {
result := make([]json.RawMessage, v.Len())
for i := 0; i < v.Len(); i++ {
for i := range v.Len() {
encodedValue, err := encode(v.Index(i))
if err != nil {
return nil, err
Expand Down
13 changes: 11 additions & 2 deletions generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,17 @@ func Generate(ctx context.Context, cfg *config.Config, options ...api.Option) er
}

if cfg.Federation.Version != 0 {
if fed, ok := federation.New(cfg.Federation.Version).(plugin.EarlySourceInjector); ok {
var (
fedPlugin plugin.Plugin
err error
)

fedPlugin, err = federation.New(cfg.Federation.Version, cfg.GQLConfig)
if err != nil {
return fmt.Errorf("failed to create federation plugin: %w", err)
}

if fed, ok := fedPlugin.(plugin.EarlySourceInjector); ok {
if source := fed.InjectSourceEarly(); source != nil {
cfg.GQLConfig.Sources = append(cfg.GQLConfig.Sources, source)
}
Expand All @@ -81,7 +91,6 @@ func Generate(ctx context.Context, cfg *config.Config, options ...api.Option) er

// sort Implements to ensure a deterministic output
for _, v := range cfg.GQLConfig.Schema.Implements {
v := v
sort.Slice(v, func(i, j int) bool { return v[i].Name < v[j].Name })
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.22.5
toolchain go1.22.6

require (
github.com/99designs/gqlgen v0.17.51
github.com/99designs/gqlgen v0.17.54
github.com/google/go-cmp v0.6.0
github.com/google/uuid v1.6.0
github.com/stretchr/testify v1.9.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/99designs/gqlgen v0.17.51 h1:KHLvUckplsZi14Zv1JdHkemXSkulksN/Dwe7VflePSQ=
github.com/99designs/gqlgen v0.17.51/go.mod h1:77/+pVe6zlTsz++oUg2m8VLgzdUPHxjoAG3BxI5y8Rc=
github.com/99designs/gqlgen v0.17.54 h1:AsF49k/7RJlwA00RQYsYN0T8cQuaosnV/7G1dHC3Uh8=
github.com/99designs/gqlgen v0.17.54/go.mod h1:77/+pVe6zlTsz++oUg2m8VLgzdUPHxjoAG3BxI5y8Rc=
github.com/agnivade/levenshtein v1.1.1 h1:QY8M92nrzkmr798gCo3kmMyqXFzdQVpxLlGPRBij0P8=
github.com/agnivade/levenshtein v1.1.1/go.mod h1:veldBMzWxcCG2ZvUTKD2kJNRdCk5hVbJomOvKkmgYbo=
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ=
Expand Down
4 changes: 2 additions & 2 deletions graphqljson/graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func (d *Decoder) decode() error { //nolint:maintidx
if v.Kind() != reflect.Struct {
continue
}
for i := 0; i < v.NumField(); i++ {
for i := range v.NumField() {
if isGraphQLFragment(v.Type().Field(i)) || v.Type().Field(i).Anonymous {
// Add GraphQL fragment or embedded struct.
d.vs = append(d.vs, []reflect.Value{v.Field(i)})
Expand Down Expand Up @@ -352,7 +352,7 @@ func (d *Decoder) popAllVs() {
// fieldByGraphQLName returns an exported struct field of struct v
// that matches GraphQL name, or invalid reflect.Value if none found.
func fieldByGraphQLName(v reflect.Value, name string) reflect.Value {
for i := 0; i < v.NumField(); i++ {
for i := range v.NumField() {
if v.Type().Field(i).PkgPath != "" {
// Skip unexported field.
continue
Expand Down
2 changes: 0 additions & 2 deletions introspection/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ func (p parser) parseDirectiveDefinition(directiveValue *DirectiveType) *ast.Dir
func (p parser) parseObjectFields(typeVale *FullType) ast.FieldList {
fieldList := make(ast.FieldList, 0, len(typeVale.Fields))
for _, field := range typeVale.Fields {
field := field
typ := p.getType(&field.Type)
args := make(ast.ArgumentDefinitionList, 0, len(field.Args))
for _, arg := range field.Args {
Expand All @@ -134,7 +133,6 @@ func (p parser) parseObjectFields(typeVale *FullType) ast.FieldList {
func (p parser) parseInputObjectFields(typeVale *FullType) ast.FieldList {
fieldList := make(ast.FieldList, 0, len(typeVale.InputFields))
for _, field := range typeVale.InputFields {
field := field
typ := p.getType(&field.Type)
fieldDefinition := &ast.FieldDefinition{
Description: pointerString(field.Description),
Expand Down

0 comments on commit c7df292

Please sign in to comment.