laravel-graphql icon indicating copy to clipboard operation
laravel-graphql copied to clipboard

Access HTTP headers from php Query resolver?

Open ericfong opened this issue 6 years ago • 3 comments

can I access HTTP headers from php Query resolver?

I want to access the 'User-Agent', 'Accept-Language' and some other custom HTTP header from resolver.

Thanks a lot

ericfong avatar Jul 30 '18 03:07 ericfong

Yes, do it "the Laravel" way:

  • either inject Request in your constructor
  • or access app('request') where you need it.

mfn avatar Jul 30 '18 06:07 mfn

Thanks.

ericfong avatar Jul 30 '18 07:07 ericfong

There's yet another way:

  • you can make your own GraphQLController (extend it and specify it in your config/graphql.php)
  • override queryContext and add it do the context right from the start

This way your resolver does not just receive User $user (the third arg) but e.g. ['user' => …, 'request' => …]

mfn avatar Jul 30 '18 08:07 mfn