99designs / 99designs/gqlgen

WithStack not declared by package errors

Đang mở
#2,489 1 bình luận 2 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Go
Star
10.8k
Fork
1.3k
Merge trung bình
2 ngày 36 phút
Pull request đã merge (30 ngày)
26

Mô tả

### What happened?
I generated models & resolvers and implemented several resolver's methods.
In these methods I used `errors.WithStack(err)` from `github.com/pkg/errors` package.

When I run generate one more time, it automatically replaces `github.com/pkg/errors` with `errors` and after that complaining that method not declared.

### What did you expect?

I expect that it won't change import for `github.com/pkg/errors` package.

### Minimal graphql.schema and models to reproduce

Schema:
```graphql
type Query {
myUser(email: String!): User!
}

type User {
id: String!
email: String!
}
```

Resolvers with implementation
```go
package graph

// This file will be automatically regenerated based on the schema, any resolver implementations
// will be copied through when generating and any unknown code will be moved to the end.
// Code generated by github.com/99designs/gqlgen version v0.17.22

import (
"context"
"github.com/pkg/errors"

"github.com/bynov/test-graphql/graph/model"
)

// MyUser is the resolver for the myUser field.
func (r *queryResolver) MyUser(ctx context.Context, email string) (*model.User, error) {
if email == "1" {
return nil, errors.WithStack(errors.New("test"))
}

return &model.User{
ID: "1",
Email: email,
}, nil
}

// Query returns QueryResolver implementation.
func (r *Resolver) Query() QueryResolver { return &queryResolver{r} }

type queryResolver struct{ *Resolver }
```

gclgen.yml
```yml
# Where are all the schema files located? globs are supported eg src/**/*.graphqls
schema:
- graph/*.graphqls

# Where should the generated server code go?
exec:
filename: graph/generated.go
package: graph

# Uncomment to enable federation
# federation:
# filename: graph/federation.go
# package: graph

# Where should any generated models go?
model:
filename: graph/model/models_gen.go
package: model

# Where should the resolver implementations go?
resolver:
layout: follow-schema
dir: graph
package: graph

# Optional: turn on use ` + "`" + `gqlgen:"fieldName"` + "`" + ` tags in your models
# struct_tag: json

# Optional: turn on to use []Thing instead of []*Thing
# omit_slice_element_pointers: false

# Optional: turn off to make struct-type struct fields not use pointers
# e.g. type Thing struct { FieldA OtherThing } instead of { FieldA *OtherThing }
# struct_fields_always_pointers: true

# Optional: turn off to make resolvers return values instead of pointers for structs
# resolvers_always_return_pointers: true

# Optional: set to speed up generation time by not performing a final validation pass.
# skip_validation: true

# gqlgen will search for any type names in the schema in these go packages
# if they match it will use them, otherwise it will generate them.
autobind:
# - "github.com/bynov/test-graphql/graph/model"

# This section declares type mapping between the GraphQL and go type systems
#
# The first line in each type will be used as defaults for resolver arguments and
# modelgen, the others will be allowed when binding to fields. Configure them to
# your liking
models:
ID:
model:
- github.com/99designs/gqlgen/graphql.ID
- github.com/99designs/gqlgen/graphql.Int
- github.com/99designs/gqlgen/graphql.Int64
- github.com/99designs/gqlgen/graphql.Int32
Int:
model:
- github.com/99designs/gqlgen/graphql.Int
- github.com/99designs/gqlgen/graphql.Int64
- github.com/99designs/gqlgen/graphql.Int32
```

Adding new type:
```graphql
type NewUser {
id: String!
}
```

Run generate `go run github.com/99designs/gqlgen generate` and got error: `validation failed: packages.Load: /Users/bynov/go/src/github.com/bynov/test-graphql/graph/schema.resolvers.go:17:22: WithStack not declared by package errors`

### versions
- `go run github.com/99designs/gqlgen version v0.17.22`
- `go version go1.19.4 darwin/amd64`

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.