Directive on Input Type Receives Map instead of Object
- Vorherrschende Sprache
- Go
- Sterne
- 10.8k
- Forks
- 1.3k
- Ø Merge
- 2 T. 36 Min.
- Gemergte PRs (30 T.)
- 26
Beschreibung
### What happened?
I wanted to implement a custom directive for `input` types called `@validate`.
My directive hook looks like this:
```go
config.Directives.Validate = func(ctx context.Context, obj interface{}, next graphql.Resolver) (res interface{}, err error) {
if _, ok := obj.(map[string]any); ok {
return next(ctx)
}
if err := validate.StructCtx(ctx, obj); err != nil {
return nil, err
}
return next(ctx)
}
```
### What did you expect?
I expected the `validate.StructCtx` to be called, and `obj` to be of the type `model.CreateCarInput`.
### Minimal graphql.schema and models to reproduce
```gql
directive @validate on OBJECT | INPUT_OBJECT
input CreateCarInput @validate {
make: String! @goTag(key: "validate", value: "notblank")
model: String!
type: String!
year: Int!
}
```
### versions
- `go run github.com/99designs/gqlgen version` v0.17.49
- `go version` go version go1.22.3 linux/amd64
Beitragsleitfaden
Bewertung
Dieses Issue wurde noch nicht bewertet.