Skip to content

Commit

Permalink
refactor entity list response
Browse files Browse the repository at this point in the history
  • Loading branch information
dbosen committed Aug 20, 2024
1 parent c292e76 commit 5b0e859
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Drupal\graphql\GraphQL\Execution\FieldContext;
use Drupal\taxonomy\TermInterface;
use Drupal\thunder_gqls\Wrappers\EntityListResponse;
use Drupal\thunder_gqls\Wrappers\EntityListResponseInterface;

/**
Expand Down Expand Up @@ -119,7 +118,7 @@ public function resolve(TermInterface $term, string $type, array $bundles, strin
$cacheContext
);

return new EntityListResponse($query);
return $this->entityListResponse($query);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
namespace Drupal\thunder_gqls\Plugin\GraphQL\DataProducer;

use Drupal\Core\Entity\EntityTypeManager;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Entity\Query\QueryInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\graphql\GraphQL\Execution\FieldContext;
use Drupal\graphql\Plugin\GraphQL\DataProducer\DataProducerPluginBase;
use Drupal\thunder_gqls\Wrappers\EntityListResponse;
use Drupal\thunder_gqls\Wrappers\SearchApiResponse;
use GraphQL\Error\UserError;
use Symfony\Component\DependencyInjection\ContainerInterface;

Expand All @@ -23,52 +26,67 @@ abstract class ThunderEntityListProducerBase extends DataProducerPluginBase impl
*
* @var \Drupal\Core\Entity\EntityTypeManager
*/
protected $entityTypeManager;
protected EntityTypeManager $entityTypeManager;

/**
* The current user.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $currentUser;
protected AccountInterface $currentUser;

/**
* The response wrapper service.
*
* @var \Drupal\thunder_gqls\Wrappers\SearchApiResponse
*/
private SearchApiResponse $responseWrapper;

/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition): self {
return new static(
$instance = new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('entity_type.manager'),
$container->get('current_user')
$plugin_definition
);

$instance->setEntityTypeManager($container->get('entity_type.manager'));
$instance->setCurrentUser($container->get('current_user'));
$instance->setResponseWrapper($container->get('thunder_gqls.entity_list_response_wrapper'));

return $instance;
}

/**
* EntityLoad constructor.
* Set the entity type manager service.
*
* @param array $configuration
* The plugin configuration array.
* @param string $pluginId
* The plugin id.
* @param array $pluginDefinition
* The plugin definition array.
* @param \Drupal\Core\Entity\EntityTypeManager $entityTypeManager
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity type manager service.
* @param \Drupal\Core\Session\AccountInterface $current_user
* The current user.
*/
public function __construct(
array $configuration,
string $pluginId,
array $pluginDefinition,
EntityTypeManager $entityTypeManager,
AccountInterface $current_user,
) {
parent::__construct($configuration, $pluginId, $pluginDefinition);
private function setEntityTypeManager(EntityTypeManagerInterface $entityTypeManager): void {

Check warning on line 68 in modules/thunder_gqls/src/Plugin/GraphQL/DataProducer/ThunderEntityListProducerBase.php

View workflow job for this annotation

GitHub Actions / drupal-coder (drupal practice)

[drupal-coder (drupal practice)] modules/thunder_gqls/src/Plugin/GraphQL/DataProducer/ThunderEntityListProducerBase.php#L68 <DrupalPractice.Objects.UnusedPrivateMethod.UnusedMethod>

Unused private method setEntityTypeManager()
Raw output
/github/workspace/modules/thunder_gqls/src/Plugin/GraphQL/DataProducer/ThunderEntityListProducerBase.php:68:11: warning: Unused private method setEntityTypeManager() (DrupalPractice.Objects.UnusedPrivateMethod.UnusedMethod)
$this->entityTypeManager = $entityTypeManager;
$this->currentUser = $current_user;
}

/**
* Set the current user.
*
* @param \Drupal\Core\Session\AccountInterface $currentUser
* The current user.
*/
private function setCurrentUser(AccountInterface $currentUser): void {

Check warning on line 78 in modules/thunder_gqls/src/Plugin/GraphQL/DataProducer/ThunderEntityListProducerBase.php

View workflow job for this annotation

GitHub Actions / drupal-coder (drupal practice)

[drupal-coder (drupal practice)] modules/thunder_gqls/src/Plugin/GraphQL/DataProducer/ThunderEntityListProducerBase.php#L78 <DrupalPractice.Objects.UnusedPrivateMethod.UnusedMethod>

Unused private method setCurrentUser()
Raw output
/github/workspace/modules/thunder_gqls/src/Plugin/GraphQL/DataProducer/ThunderEntityListProducerBase.php:78:11: warning: Unused private method setCurrentUser() (DrupalPractice.Objects.UnusedPrivateMethod.UnusedMethod)
$this->currentUser = $currentUser;
}

/**
* Set the response wrapper service.
*
* @param \Drupal\thunder_gqls\Wrappers\SearchApiResponse $responseWrapper
* The response wrapper service.
*/
private function setResponseWrapper(SearchApiResponse $responseWrapper): void {

Check warning on line 88 in modules/thunder_gqls/src/Plugin/GraphQL/DataProducer/ThunderEntityListProducerBase.php

View workflow job for this annotation

GitHub Actions / drupal-coder (drupal practice)

[drupal-coder (drupal practice)] modules/thunder_gqls/src/Plugin/GraphQL/DataProducer/ThunderEntityListProducerBase.php#L88 <DrupalPractice.Objects.UnusedPrivateMethod.UnusedMethod>

Unused private method setResponseWrapper()
Raw output
/github/workspace/modules/thunder_gqls/src/Plugin/GraphQL/DataProducer/ThunderEntityListProducerBase.php:88:11: warning: Unused private method setResponseWrapper() (DrupalPractice.Objects.UnusedPrivateMethod.UnusedMethod)
$this->responseWrapper = $responseWrapper;
}

/**
Expand Down Expand Up @@ -202,4 +220,17 @@ protected function createPublishedCondition(string $type, array $conditions) {
];
}

/**
* The entity list response.
*
* @param \Drupal\Core\Entity\Query\QueryInterface $query
* The entity query.
*
* @return \Drupal\thunder_gqls\Wrappers\EntityListResponse The search api response.

Check failure on line 229 in modules/thunder_gqls/src/Plugin/GraphQL/DataProducer/ThunderEntityListProducerBase.php

View workflow job for this annotation

GitHub Actions / drupal-coder (drupal)

[drupal-coder (drupal)] modules/thunder_gqls/src/Plugin/GraphQL/DataProducer/ThunderEntityListProducerBase.php#L229 <Drupal.Commenting.FunctionComment.ReturnTypeSpaces>

Return type "\Drupal\thunder_gqls\Wrappers\EntityListResponse The search api response." must not contain spaces
Raw output
/github/workspace/modules/thunder_gqls/src/Plugin/GraphQL/DataProducer/ThunderEntityListProducerBase.php:229:6: error: Return type "\Drupal\thunder_gqls\Wrappers\EntityListResponse The search api response." must not contain spaces (Drupal.Commenting.FunctionComment.ReturnTypeSpaces)
* The entity list response.
*/
protected function entityListResponse(QueryInterface $query): EntityListResponse {
return $this->responseWrapper->setQuery($query);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Drupal\thunder_gqls\Plugin\GraphQL\DataProducer;

use Drupal\Core\DependencyInjection\ClassResolverInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
Expand Down Expand Up @@ -36,7 +35,7 @@ abstract class ThunderSearchApiProducerBase extends DataProducerPluginBase imple
protected LanguageManagerInterface $languageManager;

/**
* The class resolver service.
* The response wrapper service.
*
* @var \Drupal\thunder_gqls\Wrappers\SearchApiResponse
*/
Expand All @@ -59,7 +58,7 @@ public static function create(

$instance->setEntityTypeManager($container->get('entity_type.manager'));
$instance->setLanguageManager($container->get('language_manager'));
$instance->setResponseWrapper($container->get('thunder_gqls.search_api_response'));
$instance->setResponseWrapper($container->get('thunder_gqls.search_api_response_wrapper'));

return $instance;
}
Expand All @@ -85,10 +84,10 @@ private function setLanguageManager(LanguageManagerInterface $languageManager):
}

/**
* Set the class resolver service.
* Set the response wrapper service.
*
* @param \Drupal\thunder_gqls\Wrappers\SearchApiResponse $responseWrapper
* The class resolver service.
* The response wrapper service.
*/
private function setResponseWrapper(SearchApiResponse $responseWrapper): void {

Check warning on line 92 in modules/thunder_gqls/src/Plugin/GraphQL/DataProducer/ThunderSearchApiProducerBase.php

View workflow job for this annotation

GitHub Actions / drupal-coder (drupal practice)

[drupal-coder (drupal practice)] modules/thunder_gqls/src/Plugin/GraphQL/DataProducer/ThunderSearchApiProducerBase.php#L92 <DrupalPractice.Objects.UnusedPrivateMethod.UnusedMethod>

Unused private method setResponseWrapper()
Raw output
/github/workspace/modules/thunder_gqls/src/Plugin/GraphQL/DataProducer/ThunderSearchApiProducerBase.php:92:11: warning: Unused private method setResponseWrapper() (DrupalPractice.Objects.UnusedPrivateMethod.UnusedMethod)
$this->responseWrapper = $responseWrapper;
Expand Down
4 changes: 3 additions & 1 deletion modules/thunder_gqls/thunder_gqls.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ services:
thunder_gqls.buffer.search_api_result:
class: Drupal\thunder_gqls\GraphQL\Buffers\SearchApiResultBuffer
Drupal\thunder_gqls\GraphQL\Buffers\SearchApiResultBuffer: '@thunder_gqls.buffer.search_api_result'
thunder_gqls.search_api_response:
thunder_gqls.search_api_response_wrapper:
class: Drupal\thunder_gqls\Wrappers\SearchApiResponse
thunder_gqls.entity_list_response_wrapper:
class: Drupal\thunder_gqls\Wrappers\EntityListResponse

0 comments on commit 5b0e859

Please sign in to comment.