1
1
<?php
2
2
3
- namespace Drupal \graphql \ Routing ;
3
+ namespace Drupal \graphql ;
4
4
5
5
use Drupal \Core \Authentication \AuthenticationCollectorInterface ;
6
- use Drupal \graphql \Entity \Server ;
6
+ use Drupal \Core \Entity \EntityTypeManagerInterface ;
7
7
use Symfony \Component \Routing \Route ;
8
8
9
- class QueryRouteProvider {
9
+ class RouteProvider {
10
10
11
11
/**
12
12
* The authentication collector service.
@@ -16,21 +16,32 @@ class QueryRouteProvider {
16
16
protected $ authenticationCollector ;
17
17
18
18
/**
19
- * QueryRouteProvider constructor .
19
+ * The entity type manager service .
20
20
*
21
+ * @var \Drupal\Core\Entity\EntityTypeManagerInterface
22
+ */
23
+ protected $ entityTypeManager ;
24
+
25
+ /**
26
+ * RouteProvider constructor.
27
+ *
28
+ * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
29
+ * The entity type manager service.
21
30
* @param \Drupal\Core\Authentication\AuthenticationCollectorInterface $authenticationCollector
22
31
* The authentication collector service.
23
32
*/
24
- public function __construct (AuthenticationCollectorInterface $ authenticationCollector ) {
33
+ public function __construct (EntityTypeManagerInterface $ entityTypeManager , AuthenticationCollectorInterface $ authenticationCollector ) {
25
34
$ this ->authenticationCollector = $ authenticationCollector ;
35
+ $ this ->entityTypeManager = $ entityTypeManager ;
26
36
}
27
37
28
38
/**
29
39
* Collects routes for the server endpoints.
30
40
*/
31
41
public function routes () {
42
+ $ storage = $ this ->entityTypeManager ->getStorage ('graphql_server ' );
32
43
/** @var \Drupal\graphql\Entity\ServerInterface[] $servers */
33
- $ servers = Server:: loadMultiple ();
44
+ $ servers = $ storage -> loadMultiple ();
34
45
$ routes = [];
35
46
36
47
// Allow all authentication providers by default.
@@ -41,20 +52,20 @@ public function routes() {
41
52
42
53
$ routes ["graphql.query. $ id " ] = (new Route ($ path ))
43
54
->addDefaults ([
44
- 'server ' => $ id ,
55
+ 'graphql_server ' => $ id ,
45
56
'_graphql ' => TRUE ,
46
57
'_controller ' => '\Drupal\graphql\Controller\RequestController::handleRequest ' ,
47
58
'_disable_route_normalizer ' => TRUE ,
48
59
])
49
60
->addRequirements ([
50
- '_graphql_query_access ' => 'TRUE ' ,
61
+ '_graphql_query_access ' => 'graphql_server:{graphql_server} ' ,
51
62
'_format ' => 'json ' ,
52
63
])
53
64
->addOptions ([
54
65
'_auth ' => $ auth ,
55
66
'no_cache ' => TRUE ,
56
67
'default_url_options ' => ['path_processing ' => FALSE ],
57
- 'parameters ' => ['server ' => ['type ' => 'entity:graphql_server ' ]]
68
+ 'parameters ' => ['graphql_server ' => ['type ' => 'entity:graphql_server ' ]]
58
69
]);
59
70
}
60
71
0 commit comments