-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGraphqlController.php
86 lines (77 loc) · 2.97 KB
/
GraphqlController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
namespace App\Controller;
use App\GraphQL\Schema\Blog\Data\BlogDataSource;
use Psr\Container\ContainerInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use GraphQL\GraphQL;
use GraphQL\Type\Schema;
use GraphQL\Error\DebugFlag;
use GraphQL\Error\FormattedError;
use App\Boilerplate\GraphQL\Endpoint;
/**
* Class GraphqlController
* @package App\Controller
*/
class GraphqlController
{
/** @var ContainerInterface */
private $container;
/**
* GraphqlController constructor.
* @param ContainerInterface $container
*/
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
/**
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @param array $args
* @return ResponseInterface
* @throws \App\Boilerplate\GraphQL\Exception\PersistedQueryNotFoundException
* @throws \App\Boilerplate\GraphQL\Exception\PersistedQueryNotSupportedException
*/
public function demoEndpoint(ServerRequestInterface $request, ResponseInterface $response, array $args): ResponseInterface
{
return (new Endpoint($response, DebugFlag::INCLUDE_TRACE))
->executeSchema([
'schemaFilePath' => __DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'GraphQL'.DIRECTORY_SEPARATOR.'Schema'.DIRECTORY_SEPARATOR.'demo'.DIRECTORY_SEPARATOR.'Demo.schema.php',
])
;
}
/**
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @param array $args
* @return ResponseInterface
* @throws \App\Boilerplate\GraphQL\Exception\PersistedQueryNotFoundException
* @throws \App\Boilerplate\GraphQL\Exception\PersistedQueryNotSupportedException
*/
public function blogEndpoint(ServerRequestInterface $request, ResponseInterface $response, array $args): ResponseInterface
{
BlogDataSource::init();
return (new Endpoint($response, DebugFlag::INCLUDE_TRACE))
->executeSchema([
'schemaFilePath' => __DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'GraphQL'.DIRECTORY_SEPARATOR.'Schema'.DIRECTORY_SEPARATOR.'blog'.DIRECTORY_SEPARATOR.'Blog.schema.php',
])
;
}
/**
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @param array $args
* @return ResponseInterface
* @throws \App\Boilerplate\GraphQL\Exception\PersistedQueryNotFoundException
* @throws \App\Boilerplate\GraphQL\Exception\PersistedQueryNotSupportedException
*/
public function refsEndpoint(ServerRequestInterface $request, ResponseInterface $response, array $args): ResponseInterface
{
throw new \Exception('Not Implemented Yet');
// your code to access items in the container... $this->container->get('');
return (new Endpoint($response, DebugFlag::INCLUDE_TRACE))
->executeSchema('refs')
;
}
}