99designs / gqlgen

go generate based graphql server library
https://gqlgen.com
MIT License
9.88k stars 1.15k forks source link

How can I avoid gqlgen always generate extra reslover that i dont need #2623

Open Shihansin opened 1 year ago

Shihansin commented 1 year ago

What happened?

when i define a graphl gen with "scalar time" type , it will generate an extra reslover to me

scalar Time

type User {
  id: ID!
  firstname: String!
  lastname: String!
  email: String!
  hashedPassword: String!
  birthday: Time!
}

it generate an "birthday" reslover , that i don't want

// CreateUser is the resolver for the createUser field.
func (r *mutationResolver) CreateUser(ctx context.Context, input schema.CreateUserInput) (*model.User, error) {
    panic(fmt.Errorf("not implemented: CreateUser - createUser"))
}

// Birthday is the resolver for the birthday field.
func (r *createUserInputResolver) Birthday(ctx context.Context, obj *schema.CreateUserInput, data *time.Time) error {
    panic(fmt.Errorf("not implemented: Birthday - birthday"))
}

when i try to use gqlgen.yaml configure a self defined models

models:
  ReqPdConfig:
    model:
      - shihansin/server/db/syncworker.ReqPdConfig

ReqPdConfig is a struct include multiple struct , but itself is a whole big struct , but it generate many resolver to me

func (r *reqPdConfigResolver) AwardConfig(ctx context.Context, obj *syncworker.ReqPdConfig, data []*graphql1.AwardInput) error {
    panic(fmt.Errorf("not implemented: AwardConfig - awardConfig"))
}

// Qa is the resolver for the qa field.
func (r *reqPdConfigResolver) Qa(ctx context.Context, obj *syncworker.ReqPdConfig, data []*graphql1.QAInput) error {
    panic(fmt.Errorf("not implemented: Qa - qa"))
}

// HighLight is the resolver for the highLight field.
func (r *reqPdConfigResolver) HighLight(ctx context.Context, obj *syncworker.ReqPdConfig, data []*graphql1.HighlightInput) error {
    panic(fmt.Errorf("not implemented: HighLight - highLight"))
}

// AboutProduct is the resolver for the aboutProduct field.
func (r *reqPdConfigResolver) AboutProduct(ctx context.Context, obj *syncworker.ReqPdConfig, data []*graphql1.AboutProductInput) error {
    panic(fmt.Errorf("not implemented: AboutProduct - aboutProduct"))
}

// Mutation returns graphql1.MutationResolver implementation.
func (r *Resolver) Mutation() graphql1.MutationResolver { return &mutationResolver{r} }

// ReqPdConfig returns graphql1.ReqPdConfigResolver implementation.
func (r *Resolver) ReqPdConfig() graphql1.ReqPdConfigResolver { return &reqPdConfigResolver{r} }

What did you expect?

how can i avoid it , which is only generate one single reslover , or generate the reslover that i want

Minimal graphql.schema and models to reproduce

versions

vamshiaruru-virgodesigns commented 1 year ago

Does your model.User field have the birthday field? Remove that models.User and try to generate your code again.

Shihansin commented 1 year ago

i fix this error , i found that it is because the pointer type *time and type time are different , gqlgen treat pointer type and nomal type are different , then it will generate a extra reslover

Does your model.User field have the birthday field? Remove that models.User and try to generate your code again.

i fix this error , i found that it is because the pointer type *time and type time are different , gqlgen treat pointer type and nomal type are different , then it will generate a extra reslover