[BUG]: Directives seem to be called after the Resolvers
- 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ả
### github repro:
https://github.com/luisgarciaalanis/directiveBug
### What happened?
While experimenting with directives by implementing the hasRole example, I noticed the directive is called after the Resolver, beating the purpose of the directive.
### What did you expect?
Expect the has role directive to be called before the Resolver to protect the resolver if the role is not present.
### Minimal graphql.schema and models to reproduce
```
directive @hasRole(role: Role!) on FIELD_DEFINITION
enum Role {
ADMIN
USER
}
type Test {
text: String! @hasRole(role: ADMIN)
}
type Query {
test: Test!
}
```
hasRole implementation:
```
c := generated.Config{Resolvers: &graph.Resolver{}}
c.Directives.HasRole = func(ctx context.Context, obj interface{}, next graphql.Resolver, role model.Role) (res interface{}, err error) {
fmt.Println("HasRole called!")
return next(ctx)
}
srv := handler.NewDefaultServer(generated.NewExecutableSchema(c))
```
resolver implementation:
```
func (r *queryResolver) Test(ctx context.Context) (*model.Test, error) {
fmt.Println("Test resolver called!")
return &model.Test{
Text: "Hello",
}, nil
}
```
### versions
- `gqlgen version` v0.13.0
- `go version` go1.15.2 darwin/amd64
- go modules
Hướng dẫn đóng góp
Đánh giá
Issue này chưa được đánh giá.