-
Notifications
You must be signed in to change notification settings - Fork 424
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
Directives support? #156
Comments
Hey I want this too. It looks like the query parser supports directives, but I don't see a way to add new directives of your own or to handle resolution. I'll give it a go at taking this on. I'll dig into what this might look like and post back here so I don't go too far off the reservation before agreeing on a design. |
So the "official" js library doesn't support directives other than the two baked in ones, Thus adding support here would be deviating from the standard a bit and therefore is maybe why this hasn't been added yet. You can create directives in your schema via something like The AST has the notion of directives which is how skip and include work for a query. Adding support for extra field level directives seems to be pretty straight forward, it would just be generalizing skip/include to call into a directive resolver. However, there are other notions of directive that I have seen, for example https://www.apollographql.com/docs/graphql-tools/schema-directives.html, which are much more complicated. For instance, they have an
This would require resolving the field, then calling into some other resolver defined for the directive. Again that specific case isn't too hard. But this quickly gets out of control. Solving this with an abstraction like the SchemaDirectiveVisitor from Apollo seems like the right solution if this is a feature you'd actually want to add to this library. As this library doesn't really work with the SDL I am not sure this is actually a desired feature here. It probably makes more sense to just write resolvers that handle the necessary logic. If this library was able to parse a SDL document to generate types and hook into resolvers then this might be a worthwhile feature, but as it stands it is kinda antithetical to how this library views type definitions. |
I didn't know that it wasn't implemented in the official graphql-js library. I had used apollo and thought they were using something present in graphql. |
Directives are quite important, especially for building stuff relating to authorisation, scopes & permissions. How can we do this? |
Authentication and other checks can be included in the generated schema using directives. Is it possible to do that juniper right now?
I'm trying to add auth checks for certain mutations using directives but seems impossible in juniper.
Something like this,
https://gist.github.com/LawJolla/132b99179b978cf76eadfd7a6d742b22#file-scratch-graphql
Only other alternative I see is using macros. isAuthenticate!() and hasRole!(role: “MANAGER”) within the mutations.
The text was updated successfully, but these errors were encountered: