22
33namespace Drupal \graphql \Routing ;
44
5+ use Drupal \Core \Authentication \AuthenticationCollectorInterface ;
56use Drupal \graphql \Entity \Server ;
67use Symfony \Component \Routing \Route ;
78
8- class QueryRoutes {
9+ class QueryRouteProvider {
10+
11+ /**
12+ * The authentication collector service.
13+ *
14+ * @var \Drupal\Core\Authentication\AuthenticationCollectorInterface
15+ */
16+ protected $ authenticationCollector ;
17+
18+ /**
19+ * QueryRouteProvider constructor.
20+ *
21+ * @param \Drupal\Core\Authentication\AuthenticationCollectorInterface $authenticationCollector
22+ * The authentication collector service.
23+ */
24+ public function __construct (AuthenticationCollectorInterface $ authenticationCollector ) {
25+ $ this ->authenticationCollector = $ authenticationCollector ;
26+ }
927
1028 /**
1129 * Collects routes for the server endpoints.
@@ -15,6 +33,9 @@ public function routes() {
1533 $ servers = Server::loadMultiple ();
1634 $ routes = [];
1735
36+ // Allow all authentication providers by default.
37+ $ auth = array_keys ($ this ->authenticationCollector ->getSortedProviders ());
38+
1839 foreach ($ servers as $ id => $ server ) {
1940 $ path = $ server ->get ('endpoint ' );
2041
@@ -30,6 +51,7 @@ public function routes() {
3051 '_format ' => 'json ' ,
3152 ])
3253 ->addOptions ([
54+ '_auth ' => $ auth ,
3355 'no_cache ' => TRUE ,
3456 'default_url_options ' => ['path_processing ' => FALSE ],
3557 'parameters ' => ['server ' => ['type ' => 'entity:graphql_server ' ]]
0 commit comments