-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add field info to directive context #1084
Comments
@vektah , @seaskyways, We encountered this issue as well: #990 (comment) Adding it here for completeness |
Hi @seaskyways @vektah, |
Seems, its abandoned. |
It's not. It's going a little slow lately, but they'll be back brighter than before! |
Hi, We have identified an approach that works for us at i2O with The directive returns the value of the actual field which can then be used and modified accordingly.
|
Here is how I solved it. Pretty similar to @muhammad-i2o's solution but it is all you need if your directive is applied on config.Directives.Validate = func(ctx context.Context, obj interface{}, next graphql.Resolver, rules *string) (interface{}, error) {
val, err := next(ctx)
if err != nil {
return val, err
}
fmt.Println(">>> fieldname =", *graphql.GetPathContext(ctx).Field)
fmt.Println(">>> fieldvalue =", val)
fmt.Println(">>> rules =", *rules)
return val, nil
} |
I just tried this and everything looks good, I can use validation on input fields, we don't really need field name, do we, we just need the rules and the actual value, |
The field name is useful for error handling. |
ahh, I'm actually accepting a error message as second argument :) |
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
: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
orobj
.Minimal graphql.schema and models to reproduce
versions
gqlgen version
? 0.11.1go version
? 1.13.8The text was updated successfully, but these errors were encountered: