From 086313e492ccef0b1eaa64da8b7468f09485763b Mon Sep 17 00:00:00 2001 From: Daniel Bosen Date: Mon, 19 Aug 2024 18:07:08 +0200 Subject: [PATCH] Extract repose method --- .../GraphQL/DataProducer/ThunderSearchApi.php | 4 +--- .../ThunderSearchApiProducerBase.php | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/modules/thunder_gqls/src/Plugin/GraphQL/DataProducer/ThunderSearchApi.php b/modules/thunder_gqls/src/Plugin/GraphQL/DataProducer/ThunderSearchApi.php index d3fc2924e..969014844 100644 --- a/modules/thunder_gqls/src/Plugin/GraphQL/DataProducer/ThunderSearchApi.php +++ b/modules/thunder_gqls/src/Plugin/GraphQL/DataProducer/ThunderSearchApi.php @@ -81,9 +81,7 @@ protected function resolve( $cacheContext ); - return $this->classResolver - ->getInstanceFromDefinition(SearchApiResponse::class) - ->setQuery($query); + return $this->searchApiResponse($query); } } diff --git a/modules/thunder_gqls/src/Plugin/GraphQL/DataProducer/ThunderSearchApiProducerBase.php b/modules/thunder_gqls/src/Plugin/GraphQL/DataProducer/ThunderSearchApiProducerBase.php index c0ab04b1a..13aeb8a17 100644 --- a/modules/thunder_gqls/src/Plugin/GraphQL/DataProducer/ThunderSearchApiProducerBase.php +++ b/modules/thunder_gqls/src/Plugin/GraphQL/DataProducer/ThunderSearchApiProducerBase.php @@ -10,6 +10,7 @@ use Drupal\graphql\Plugin\GraphQL\DataProducer\DataProducerPluginBase; use Drupal\search_api\Entity\Index; use Drupal\search_api\Query\QueryInterface; +use Drupal\thunder_gqls\Wrappers\SearchApiResponse; use GraphQL\Error\UserError; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -167,4 +168,19 @@ protected function buildBaseQuery( return $query; } + /** + * The search api response. + * + * @param \Drupal\search_api\Query\QueryInterface $query + * The search api query. + * + * @return \Drupal\thunder_gqls\Wrappers\SearchApiResponse + * The search api response. + */ + protected function searchApiResponse(QueryInterface $query): SearchApiResponse { + return $this->classResolver + ->getInstanceFromDefinition(SearchApiResponse::class) + ->setQuery($query); + } + }