laravel-graphql
laravel-graphql copied to clipboard
Access HTTP headers from php Query resolver?
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
Yes, do it "the Laravel" way:
- either inject
Request
in your constructor - or access
app('request')
where you need it.
Thanks.
There's yet another way:
- you can make your own
GraphQLController
(extend it and specify it in yourconfig/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' => …]