-
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
Support Directives on Input Types #511
Comments
I do not believe that we currently support directives on As you suggest they could definitely be invoked whenever an input is used, but even then it's not 100% clear (e.g. would a variable input directive be invoked at runtime just once, or each time the variable is used). But I could also imagine use-cases for code-gen time invocation, e.g. mapping an input type to a Go type. We do note this in the directive docs but we could be clearer about what specific locations we support directives and what happens if you implement them. |
@mathewbyrne the reason I thought it was supported was because in the example of the type system extension there's an Searching through the generated code it didn't seem to ever be called, but thought it might've been my lack of understanding the generated code entirely I understand your comments about when/how it should be called. For us, adding in some sort of input property/input object directive would be great. It would allow us to not have to add function calls to ensure that a given user has permission to filter/query by various fields (from a security perspective that adds onus to a developer to ensure they remember to add those checks as well as the reviewer to ensure that they're obvious- we do that and have tests for those flows, but reducing the mental burden of rapidly iterating on api's is always a plus in my book). That way we can have a handful of types and know that they can always be used securely and reduce the exposure of surface areas |
@vektah @mathewbyrne our team would be happy to tackle this issue. If you can provide a bit more design guidance so we don't go down the wrong rabbit hole. We were thinking that you can have two types of input directives:
Which I think would cover 80% of use cases directives for inputs. If your team agrees on that we'd be happy to start working on this (and save us a tremendous headache at the moment) |
Hey @sdalezman, sorry it took a bit to get back to you. We'd been keen to support Directive Middlewares on Input objects. I think it would work more or less the same as fields, where when the argument is resolved for a given input type, the middleware stack is run. Obviously these directives will have the same interface as other directives, and be supplied through the generated directive root. We'd be happy to give feedback on a proposal issue if you think the scope of the change warrants. Please be sure to work against the |
Somehow, my directive works on INPUT_FIELD_DEFINITION, but I'm not able to get its value or name: directive @can(action: Action!) on INPUT_FIELD_DEFINITION
type Mutation {
register(payload: RegisterPayload!): AuthResult!
}
input RegisterPayload {
email: String!
password: String!
referrer: String @can(action: Create)
} allows me implement this directive function: func can(
ctx context.Context,
obj interface{},
next graphql.Resolver,
action gqlgen.Action,
) (interface{}, error) {
rc := graphql.GetResolverContext(ctx)
log.Printf("field %s has value %#v", rc.Field.Name, obj)
return next(ctx)
} prints I would have expected to get Is there currently a way to do that? |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
hi @steebchen: were you able to get the value or name for the INPUT_FIELD_DEFINITION directive? |
@steebchen : thanks for the response. May I ask what was your workaround for this? Thanks! |
Sorry, that was unclear: I just didn't use directives for my use case anymore :P |
Looks like this will be worked on here: #1084 |
Expected Behaviour
When defining a graphql schema you should be able to define a directive on an entire input object or an input field
Actual Behavior
Can't define any directive on a input field
Minimal graphql.schema and models to reproduce
where the directive evaluates to the input from the logging example:
Input logging will never be called. I think this has to do with how FieldMiddleware calls directives, but this is only from a cursory glance at the generated code
The text was updated successfully, but these errors were encountered: