1
<?php
2

3
namespace Nuwave\Lighthouse\Schema;
4

5
use Illuminate\Http\Request;
6
use Nuwave\Lighthouse\Support\Contracts\GraphQLContext;
7

8
class Context implements GraphQLContext
9
{
10
    /**
11
     * An instance of the incoming HTTP request.
12
     *
13
     * @var \Illuminate\Http\Request
14
     */
15
    public $request;
16

17
    /**
18
     * An instance of the currently authenticated user.
19
     *
20
     * @var \Illuminate\Contracts\Auth\Authenticatable|null
21
     */
22
    public $user;
23

24 1
    public function __construct(Request $request)
25
    {
26 1
        $this->request = $request;
27 1
        $this->user = $request->user(config('lighthouse.guard'));
28
    }
29

30
    /**
31
     * Get instance of authenticated user.
32
     *
33
     * May be null since some fields may be accessible without authentication.
34
     *
35
     * @return \Illuminate\Contracts\Auth\Authenticatable|null
36
     */
37 1
    public function user()
38
    {
39 1
        return $this->user;
40
    }
41

42 1
    public function request(): Request
43
    {
44 1
        return $this->request;
45
    }
46
}

Read our documentation on viewing source code .

Loading