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

Resolver interface types and function names are not Go-ified #2400

Open
menma1234 opened this issue Sep 29, 2022 · 0 comments
Open

Resolver interface types and function names are not Go-ified #2400

menma1234 opened this issue Sep 29, 2022 · 0 comments

Comments

@menma1234
Copy link

What happened?

Somewhat related to #1383.

The resolver interface types that get generated and the functions to get those resolvers from the ResolverRoot don't follow the standard Go conventions on capitalization, even though these appear to get followed for the generated field names within model structs. This causes issues with linters such as revive since they'll trip the naming convention rules on the files that have the resolver implementations.

On a similar note, this also happens for generated model names, but that's less of an issue since they live within a generated file which linters are able to detect easily so they don't trip the rules.

What did you expect?

All generated types and names are capitalized consistently.

Minimal graphql.schema and models to reproduce

GraphQL schema:

type TestType {
    vmDetail: VmDetail
}

type VmDetail {
    someVmField: String
}

Config:

schema:
  - schema.graphql
exec:
  filename: generated/generated.go
  package: generated
model:
  filename: gqlmodel/models_gen.go
  package: gqlmodel
autobind:
  - github.com/test/gqlmodel
models:
resolver:
  filename: resolver/resolver.go
  package: resolver
  type: Resolver

Generated resolver.go:

package resolver

// THIS CODE IS A STARTING POINT ONLY. IT WILL NOT BE UPDATED WITH SCHEMA CHANGES.

import (
        "context"

        "github.com/test/generated"
        "github.com/test/gqlmodel"
)

type Resolver struct{}

// // foo
func (r *testTypeResolver) VMDetail(ctx context.Context, obj *gqlmodel.TestType) (*gqlmodel.VmDetail, error) {
        panic("not implemented")
}

// // foo
func (r *vmDetailResolver) SomeVMField(ctx context.Context, obj *gqlmodel.VmDetail) (*string, error) {
        panic("not implemented")
}

// TestType returns generated.TestTypeResolver implementation.
func (r *Resolver) TestType() generated.TestTypeResolver { return &testTypeResolver{r} }

// VmDetail returns generated.VmDetailResolver implementation.
func (r *Resolver) VmDetail() generated.VmDetailResolver { return &vmDetailResolver{r} }

type testTypeResolver struct{ *Resolver }
type vmDetailResolver struct{ *Resolver }

Note the capitalization differences for "vm":

func (r *testTypeResolver) VMDetail(ctx context.Context, obj *gqlmodel.TestType) (*gqlmodel.VmDetail, error) {
                           ^^                                                               ^^

func (r *Resolver) VmDetail() generated.VmDetailResolver { return &vmDetailResolver{r} }
                   ^^                   ^^

versions

  • go run github.com/99designs/gqlgen version?
    v0.17.20

  • go version?
    go version go1.19 linux/amd64

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant