-
-
Notifications
You must be signed in to change notification settings - Fork 438
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
Disable global middleware for a subset of fields #385
Comments
I think that you can use the directive |
@enzonotario I`m using global middleware ("auth:api") because 99% of my resources are protected (user must be authenticated). lighthouse.php 'route' => [
'middleware' => ['auth:api']
], I`m proposing some mechanism to disable that global middleware in some cases, when resources are public (another 1%). These does not disable/override the global middleware: extend type Query @middleware(checks: []){
}
extend type Query @group(middleware: []){
}
|
Ahh sorry! I misunderstand you. Have you tried use the I mean, if I go to
Both
the middlewares for |
@robsontenorio Thanks for bringing this up. Indeed, middlewares are among the less documented and less polished parts of Lighthouse. The solution that @enzonotario suggested should work, without having tried it myself. I plan to do some major rework on middlewares, because of an Issue i have come across, see #363. Your use-case is something that should be considered for the implementation, i added it to a small todo list over there. |
Thanks for your time! |
@enzonotario It does not work. How to reproduce
'route' => [
'middleware' => ['auth:api']
],
extend type Query @middleware(checks: []){
// ...
}
extend type Query @group(middleware: []){
// ...
}
extend type Query{
users: [User] @middleware(checks: [])
}
|
Try removing the middleware from the Then, in your
Then, in those fields that you want to reset the middlewares, put If you post your schema maybe I can help you a bit more. |
@enzonotario That does not work.
schema.graphql #import ./city.graphql
type Query @group(middleware: ["auth:api"]){
me: User @auth
} city.graphql (both wont work) extend type Query{
cities: [City] @middleware(checks: [])
}
# OR
extend type Query @group(middleware: []){
cities: [City]
}
|
Working on resolving this in #395 Global middleware from the config run the risk of aborting the whole query in case of failure. It runs before the GraphQL execution phase, and as such do not return spec compliant responses for errors. Middlewares defined through |
Describe the solution you'd like
Currently i can set a global middleware for AUTH on config.
Because 99% of my requests are protected. But in some cases 1% can be public available for unauthenticated users.
So, right now, if i use the global middleware i cant set another requests to public.
When most of queries are protected, it is easier set the global middleware than manually on each query.
Describe alternatives you've considered
If i choose to make it public, something like this would be useful. So it would override the global middleware.
The text was updated successfully, but these errors were encountered: