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.
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.
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")
}
gqlgen version? 0.11.1go version? 1.13.8@vektah , @seaskyways, We encountered this issue as well: https://github.com/99designs/gqlgen/issues/990#issuecomment-585550923
Adding it here for completeness
Hi @seaskyways @vektah,
Is there an ETA for this?
Most helpful comment
Hi @seaskyways @vektah,
Is there an ETA for this?