Allow overriding the request role via a GraphQL directive
See original GitHub issueAs mentioned on Discord, it isn’t possible to change the role used by an existing websocket connection, since X-Hasura-Role
is sent as a header when opening the connection. @0x777 suggests allowing a special @hasura(role:)
directive on a GraphQL operation definition, like this:
subscription s @hasura(role: "new-role") {
vote_count {
article_id
count
}
}
This would override the role that would otherwise be used for that particular request.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Creating schema directives - Apollo GraphQL Docs
In your subclass, you override the visitor method for each location your directive can appear in. You can see each location's corresponding ...
Read more >Authorization with GraphQL and custom directives
We define a directive with the name auth which can be used on single fields. The directive expects a parameter requires of type...
Read more >Authorization In GraphQL Using Custom Schema Directives
To do this we override the getDirectiveDeclaration method in IsAuthenticatedDirective In our directive declaration we specify the name of the ...
Read more >Spring for GraphQL request validation using directives.
The default arguments of a directive can be overridden if needed. In the example above the @Pattern overrides one argument. The message of ......
Read more >GraphQL Directive - Techdozo
Implementing @auth Directive · The authDataFetcher first checks if the user has the required role by getting the role from the GraphQlContext as ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
Top Related Hashnode Post
No results found
A user can have multiple roles and each role could have different permissions on different tables, in such cases, you would want to make a query by specifying the appropriate role (since we don’t support multiple roles). On http, you can set
x-hasura-role
to the appropriate role and make the request but this feature is lacking on the ws transport as the role gets set when the connection is initialized.The last bit you posted is great, because the function/data structure is recursive. So we can generate it like this: