graphql-directives-auth | GraphQL Apollo server authorisation example using schema | GraphQL library
kandi X-RAY | graphql-directives-auth Summary
kandi X-RAY | graphql-directives-auth Summary
GraphQL Apollo server authorisation example using schema directives
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of graphql-directives-auth
graphql-directives-auth Key Features
graphql-directives-auth Examples and Code Snippets
Community Discussions
Trending Discussions on graphql-directives-auth
QUESTION
I am trying to set up an Apollo backend for a project I'm working on, where I'm attempting to implement schema directives. However, I am not able to add my schema directive to mutations. So to my main question: How do I implement an auth directive for mutations?
I have added @auth(requires: ADMIN)
to the end of my users query, which is working fine. Apollo will then require a bearer token with admin access for performing the users query.
ANSWER
Answered 2019-Jan-02 at 16:21The issue here is that the referenced implementation throws an error when the wrapping resolver does not find any required roles (neither for the object type nor the field in question) in these lines of code.
The logic is that as you use the directive for some field of an object type, you also need to provide a requirement for the type itself. In my opinion this logic isn't too bad and is as the code comment suggests to be on the safe side. The author of that implementation probably focused on usage of the directive for actual data types, not for queries or mutations.
Let me be even a little more specific: What you and I do (as I am trying to accomplish the same thing as you today), when using the directive for one or several queries/mutations is actually applying the directive on the fields of the schema types Query
and Mutation
. So if we don't want a minimum requirement for all queries and/or mutations of our schema, the code should not throw an error in that condition I linked above, but it should call the wrapped resolver just as if the requirements were met (because there are none).
Example:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install graphql-directives-auth
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page