nuwave / lighthouse

A framework for serving GraphQL from Laravel
https://lighthouse-php.com
MIT License
3.37k stars 438 forks source link

@inject context user returns null with multi-guards #1763

Open waldorllc opened 3 years ago

waldorllc commented 3 years ago

My Lighthouse's (v5.0.2) default guard is 'web', but I use an 'admin' guard also. Default guard context works properly in any case, but when I need to use admin's context – it returns null. (Whereas admin guard works correctly like a guard: it protects field and mutations as expected).

There is a mutation example: addNote(text: String!): Note! @create @inject(context: "user.id", name: "admin_id") @guard(with: "admin")

I've tried to create a custom mutator and it possible to get an access to admin's context via $context->request()->user(); (Whereas for default guard $context->user works also)

But if I have a lot of simple mutations like @create, @update, etc., do I really need to create multiple custom mutator methods in this case instead of just using @inject directive?

And another problem: if I need to give an access to the same mutation to multiple guards, I do need to write it twice (or more) and name differently.

Do I misunderstand something?

Many thanks!

spawnia commented 3 years ago

Using multiple guards is supported somewhat badly. Could you set up a PR with a failing test case as the basis for implementing a fix?