Description
When the GraphQL module is not enabled, the Social 13 code (notably in
social_post hooks) crashes because it references GraphQL DataProducers unconditionally.
Classes like Drupal\social_post\Plugin\GraphQL\DataProducer\UserPostsCreated are invoked without first checking whether
the graphql module is enabled.
Since graphql is not declared as a dependency in the module’s .info.yml, Drupal allows Social 13 to run even when GraphQL is missing — causing fatal errors.
Steps to Reproduce
- Install Open Social 13.x (ensure
social_postis enabled). - Make sure the GraphQL module is disabled.
- Trigger a post-related action (create, update, delete).
- Observe a fatal error, e.g.:
Error: Class "Drupal\graphql\Plugin\GraphQL\DataProducer\DataProducerPluginBase" not found in include() (line 31 of profiles/contrib/open_social/modules/social_features/social_post/src/Plugin/GraphQL/DataProducer/UserPostsCreated.php).
Expected Behavior
The system should not crash when GraphQL is disabled. Hook logic that relies on GraphQL should gracefully skip if the module is missing.
Actual Behavior
Hooks such as PostsHooks::postCreateDelete() and PostsHooks::postUpdate() directly reference GraphQL classes without verifying module availability, causing hard crashes when graphql is disabled.
Scope
PostsHooksCommentsHooksGroupHooks
Proposed Fix
Add a moduleExists('graphql') guard before any GraphQL-specific logic (cache tag invalidations based on GraphQL DataProducers, etc.).
Example implementation (PostsHooks)
<?php
namespace Drupal\social_post\Hooks;
use Drupal\Core\Cache\CacheTagsInvalidatorInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\hux\Attribute\Hook;
use Drupal\social_post\Entity\PostInterface;
use Drupal\social_post\Plugin\GraphQL\DataProducer\UserPostsCreated;
/**
* Provides hook related to posts.
*/
final class PostsHooks {
/**
* Construct for the hux.
*/
public function __construct(
protected CacheTagsInvalidatorInterface $cacheInvalidator,
protected ModuleHandlerInterface $moduleHandler
) {}
/**
* Implements hook_ENTITY_TYPE_delete() and hook_ENTITY_TYPE_create().
*/
#[Hook('post_delete')]
#[Hook('post_insert')]
public function postCreateDelete(EntityInterface $entity): void {
if (!$this->moduleHandler->moduleExists('graphql')) {
return;
}
if (!$entity instanceof PostInterface) {
return;
}
// Invalidate cache.
$this->cacheInvalidator->invalidateTags([UserPostsCreated::CID_BASE . $entity->getOwnerId()]);
}
/**
* Implements hook_ENTITY_TYPE_update().
*/
#[Hook('post_update')]
public function postUpdate(EntityInterface $entity): void {
if (!$this->moduleHandler->moduleExists('graphql')) {
return;
}
// Using $entity->original, $entity->getOriginal() does not exists here.
if (
!$entity instanceof PostInterface ||
empty($entity->original) ||
!$entity->original instanceof PostInterface
) {
return;
}
// Invalidate cache on author change for both.
if ($entity->original->getOwnerId() !== $entity->getOwnerId()) {
$this->cacheInvalidator->invalidateTags([UserPostsCreated::CID_BASE . $entity->getOwnerId()]);
$this->cacheInvalidator->invalidateTags([UserPostsCreated::CID_BASE . $entity->original->getOwnerId()]);
}
}
}
Alternative Solution
Declare graphql as a hard dependency in the module’s .info.yml (makes GraphQL mandatory):
dependencies:
- graphql:graphql
If GraphQL should remain optional, prefer the conditional check above.
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | 3551785-8.patch | 33.12 KB | robertragas |
Issue fork social-3551785
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
christian.wiedemann commentedComment #4
christian.wiedemann commentedComment #7
socialnicheguru commentedthe MR does not work
Comment #8
robertragas commentedThanks for reporting the issue. We also discussed this internally, and instead of adding a module check in there, we are removing this custom cache implementation and add the cache tags to the data producers removing the hard dependency on the graphql.
Off course I will still give the credits for work in this issue to everyone.
Comment #9
robertragas commentedComment #10
robertragas commentedNote that we already added this to the 13.0.0 release. Feel free to re-open the issue if there is anything you are running into.
Comment #11
robertragas commented