-
Notifications
You must be signed in to change notification settings - Fork 15
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
How I can set custom directives to the current field? #18
Comments
Hello! :) I'm not familiar with defining a schema in this way - but I can lend a hand for sure! When you say it doesn't work, could you clarify what you mean?
One good point of reference is the |
Both
In mercurius-auth a code in applyPolicy() is never executed |
Cool thanks, makes sense that mercurius-auth |
|
you don't happen to have the fully resolved AST do you? As |
updated above |
Cool, thanks - I can take a closer look this evening :) In the meantime, I can point you to this thread, which is a good read on the subject: graphql/graphql-js#1343 - from an initial glance, I'm not sure if it's currently possible to define them in this way (this is backed up by the fact I can see directive definitions but no usages, so I don't think it's a |
This is also another excellent resource: https://www.graphql-tools.com/docs/schema-directives/#what-about-code-first-schemas |
Just taken a closer look and based on the thread in the issue I linked, it currently looks like directives cannot be defined in this way (this is reflected in the AST omitted, as it doesn't contain any directive usage). Have you considered any alternative approaches? |
Can we support defining the auth behavior outside of the schema with a config object? |
Great idea! In theory, yes, as I think it would be a case of an extra lookup within the config object as well as the schema (when traversing the schema tree to (re-)define the field resolvers for protected fields)? And if we get a match, we run The only issue I can see is when we have a field that already contains a matching directive, maybe we just run the config |
I would just support only one mode, via an option. |
Agreed - will certainly remove any edges cases that way @dmitrydrynov would you like to implement this feature? |
Hi @dmitrydrynov :) not sure if you missed my comment - would this be something you would be interested in contributing to? I was thinking of starting the implementation for this when I'm next free, but didn't want to step on your toes in case you had started it or wanted to do this! |
Hi guys,
How I can set custom directives to the current field through Javascript code?
I created a custom Directive:
Added to the schema:
How I can use my directive only for the secretData field?
I tried to add a directives parameter for field definition but it doesn't work:
Please help!
The text was updated successfully, but these errors were encountered: