-
-
Notifications
You must be signed in to change notification settings - Fork 32
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 to add headers per-query? #96
Comments
Looks like #28 will be helpful. It would mean I need to create a separate client for each role I think |
Sounds like you want to provide a custom object to the plugin's function, I think it's simple to add to villus. So would something like this work? useQuery({
query: SomeQuery,
context: { hasuraRole: 'user' }
}) Then you would have a global plugin handling this: function rolePlugin({ queryContext }) {
opContext.headers['X-Hasura-Role'] = queryContext.hasuraRole;
} Not yet sure about the naming but it's reasonable to have. |
@logaretm thanks for the quick reply! Yes, that looks great. |
This was tagged in It's similar to what you suggested initially: useQuery({
query: SomeQuery,
context: {
headers: {
// some headers
}
}
})
// can be reactive as well
useQuery({
query: SomeQuery,
context: computed(() => { .... })
}) useMutation(SomeMutation, {
context: {
headers: {
// some headers
}
}
})
// can be reactive as well
useMutation(SomeMutation, {
context: computed(() => { .... })
}) |
With Hasura, you specify user roles with a header called
X-Hasura-Role
.I've managed to set the JWT using the example, however that seems to set the header for the whole client, rather than each request.
In Apollo, I'd do something like this:
The text was updated successfully, but these errors were encountered: