99designs / 99designs/gqlgen

Add field info to directive context

Aperta
#1,084 9 commenti 13 reazioni 0 assegnatari Vedi su GitHub
accepted
Lingua principale
Go
Stelle
10.8k
Fork
1.3k
Merge medio
2g 36m
PR unite (30g)
26

Descrizione

### What happened?
I was writing a directive to validate fields. GQLgen did not give me the functionality I need.
I have the following directive that applies on `INPUT_FIELD_DEFINITION`:
```
func (r resolver) directiveValidate(
ctx context.Context, obj interface{}, next graphql.Resolver, rules string,
) (res interface{}, err error) {
v := validator.New()
err = v.VarCtx(ctx, obj, rules)
if err != nil {
return
}

return next(ctx)
}
```
Unfortunately there is no way for me to check which field is this directive running on right now. `obj` is pointing to the parent object instead of the field the directive is on.

### What did you expect?
I expect to receive in the directive information regarding the field related perhaps in the function context.
What I need is the field's name as in the schema and the field's value either provided in `ctx` or `obj`.

### Minimal graphql.schema and models to reproduce
```
directive @validate(rules: String!) on INPUT_FIELD_DEFINITION
input Login {
# unless I explicitly pass to the directive the field name, there is no way to know what field is being "validated" when the directive runs.
username: String! @validate(rules: "min=6")
}
```

### versions
- `gqlgen version`? 0.11.1
- `go version`? 1.13.8
- dep or go modules? go modules

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.