11<?php
22
3- namespace Drupal \graphql \ Routing ;
3+ namespace Drupal \graphql ;
44
55use Drupal \Core \Authentication \AuthenticationCollectorInterface ;
6- use Drupal \graphql \Entity \Server ;
6+ use Drupal \Core \Entity \EntityTypeManagerInterface ;
77use Symfony \Component \Routing \Route ;
88
9- class QueryRouteProvider {
9+ class RouteProvider {
1010
1111 /**
1212 * The authentication collector service.
@@ -16,21 +16,32 @@ class QueryRouteProvider {
1616 protected $ authenticationCollector ;
1717
1818 /**
19- * QueryRouteProvider constructor .
19+ * The entity type manager service .
2020 *
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.
2130 * @param \Drupal\Core\Authentication\AuthenticationCollectorInterface $authenticationCollector
2231 * The authentication collector service.
2332 */
24- public function __construct (AuthenticationCollectorInterface $ authenticationCollector ) {
33+ public function __construct (EntityTypeManagerInterface $ entityTypeManager , AuthenticationCollectorInterface $ authenticationCollector ) {
2534 $ this ->authenticationCollector = $ authenticationCollector ;
35+ $ this ->entityTypeManager = $ entityTypeManager ;
2636 }
2737
2838 /**
2939 * Collects routes for the server endpoints.
3040 */
3141 public function routes () {
42+ $ storage = $ this ->entityTypeManager ->getStorage ('graphql_server ' );
3243 /** @var \Drupal\graphql\Entity\ServerInterface[] $servers */
33- $ servers = Server:: loadMultiple ();
44+ $ servers = $ storage -> loadMultiple ();
3445 $ routes = [];
3546
3647 // Allow all authentication providers by default.
@@ -41,20 +52,20 @@ public function routes() {
4152
4253 $ routes ["graphql.query. $ id " ] = (new Route ($ path ))
4354 ->addDefaults ([
44- 'server ' => $ id ,
55+ 'graphql_server ' => $ id ,
4556 '_graphql ' => TRUE ,
4657 '_controller ' => '\Drupal\graphql\Controller\RequestController::handleRequest ' ,
4758 '_disable_route_normalizer ' => TRUE ,
4859 ])
4960 ->addRequirements ([
50- '_graphql_query_access ' => 'TRUE ' ,
61+ '_graphql_query_access ' => 'graphql_server:{graphql_server} ' ,
5162 '_format ' => 'json ' ,
5263 ])
5364 ->addOptions ([
5465 '_auth ' => $ auth ,
5566 'no_cache ' => TRUE ,
5667 'default_url_options ' => ['path_processing ' => FALSE ],
57- 'parameters ' => ['server ' => ['type ' => 'entity:graphql_server ' ]]
68+ 'parameters ' => ['graphql_server ' => ['type ' => 'entity:graphql_server ' ]]
5869 ]);
5970 }
6071
0 commit comments