Grapqhl error, Class not found

Created on 16 April 2024, 7 months ago
Updated 21 August 2024, 3 months ago

Problem/Motivation

I am getting the below error, and I can't figure out what is causing it.

The website encountered an unexpected error. Please try again later.
Error: Class "\Drupal\dynamic_reference\DataDynamicReferenceDefinition" not found in Drupal\Core\TypedData\TypedDataManager->createDataDefinition() (line 120 of core/lib/Drupal/Core/TypedData/TypedDataManager.php).
Drupal\Core\TypedData\TypedDataManager->createDataDefinition() (Line: 1354)
Drupal\graphql_core_schema\EntitySchemaBuilder->getDataPropertyType() (Line: 878)
Drupal\graphql_core_schema\EntitySchemaBuilder->getFieldItemType() (Line: 793)
Drupal\graphql_core_schema\EntitySchemaBuilder->getFieldItemListType() (Line: 1239)
Drupal\graphql_core_schema\EntitySchemaBuilder->createEntityFields() (Line: 1135)
Drupal\graphql_core_schema\EntitySchemaBuilder->addContentEntityBundleType() (Line: 1041)
Drupal\graphql_core_schema\EntitySchemaBuilder->generateTypeForEntityType() (Line: 271)
Drupal\graphql_core_schema\Plugin\GraphQL\Schema\CoreComposableSchema->getSchemaDefinition() (Line: 769)
Drupal\graphql_core_schema\Plugin\GraphQL\Schema\CoreComposableSchema->getSchemaDocument() (Line: 705)
Drupal\graphql_core_schema\Plugin\GraphQL\Schema\CoreComposableSchema->getSchema() (Line: 253)
Drupal\graphql\Entity\Server->configuration() (Line: 199)
Drupal\graphql\Entity\Server->executeOperation() (Line: 27)
Drupal\graphql\GraphQL\Utility\Introspection->introspect() (Line: 87)
Drupal\graphql\Controller\ExplorerController->viewExplorer()
call_user_func_array() (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 580)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 169)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 81)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 58)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 23)
Stack\StackedHttpKernel->handle() (Line: 718)
Drupal\Core\DrupalKernel->handle() (Line: 19)

Steps to reproduce

I can't reproduce this locally, it only happens on my staging ENV.

πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States mcanada

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @mcanada
  • πŸ‡¨πŸ‡­Switzerland ayalon

    Is the module "dynamic_reference" installed? Try restarting your webserver to clear the APCU cache.

  • πŸ‡ΊπŸ‡ΈUnited States mcanada

    Can somebody help with this? we are stuck!

  • πŸ‡ΊπŸ‡ΈUnited States mcanada

    BTW, Yes @ayalon the module is on.

  • πŸ‡¨πŸ‡­Switzerland ayalon

    I can't. The module has now dependancy on this module. Something with your entity model (TypedDataManager) is fishy.

  • I've got the same error. It is with a dynamic_entity_reference when it goes wrong. The error talks about 'dynamic_entity' and that is where it goes wrong. The module is not 'dynamic_entity', but 'dynamic_entity_reference'.

  • It seems to me that is a problem with the dynamic_entity_reference module, since they have this code in their 'DynamicEntityReference.php' file:

     * @DataType(
     *   id = "dynamic_entity_reference",
     *   label = @Translation("Dynamic entity reference"),
     *   definition_class = "\Drupal\dynamic_reference\DataDynamicReferenceDefinition"
     * )

    If i manually edit this and clear caches, the error is gone, but then a different error occurs:

    Drupal\Component\Plugin\Exception\PluginNotFoundException
    The "dynamic_entity" plugin does not exist. Valid plugin IDs for Drupal\Core\TypedData\TypedDataManager are: dynamic_entity_reference, ...

    Drupal\Core\Plugin\DefaultPluginManager:53
    doGetDefinition
    Drupal\Core\Plugin\DefaultPluginManager:25
    getDefinition
    Drupal\Core\TypedData\TypedDataManager: 115
    createDataDefinition
    Drupal\dynamic_entity_reference\DataDynamicReferenceDefinition: 31
    create
    Drupal\Core\TypedData\DataReferenceDefinition: 42
    createFromDataType
    Drupal\Core\TypedData\TypedDataManager: 120
    createDataDefinition
    Drupal\graphql_core_schema\EntitySchemaBuilder: 879
    getDataPropertyType
    Drupal\graphql_core_schema\EntitySchemaBuilder: 456
    getFieldItemType
    Drupal\graphql_core_schema\EntitySchemaBuilder: 387
    getFieldItemListType
    Drupal\graphql_core_schema\EntitySchemaBuilder: 766
    createEntityFields
    Drupal\graphql_core_schema\EntitySchemaBuilder: 532
    addContentEntityType
    Drupal\graphql_core_schema\EntitySchemaBuilder: 586
    generateTypeForEntityType
    Drupal\graphql_core_schema\Plugin\GraphQL\Schema\CoreComposableSchema: 176
    getSchemaDefinition
    Drupal\graphql_core_schema\Plugin\GraphQL\Schema\CoreComposableSchema: 381
    getSchemaDocument
    Drupal\graphql_core_schema\Plugin\GraphQL\Schema\CoreComposableSchema: 303
    getSchema
    ...

  • It seems to me that is a problem with the dynamic_entity_reference module, since they have this code in their 'DynamicEntityReference.php' file:

     * @DataType(
     *   id = "dynamic_entity_reference",
     *   label = @Translation("Dynamic entity reference"),
     *   definition_class = "\Drupal\dynamic_reference\DataDynamicReferenceDefinition"
     * )
    

    If i manually edit this and clear caches, the error is gone, but then a different error occurs:

    Drupal\Component\Plugin\Exception\PluginNotFoundException
    The "dynamic_entity" plugin does not exist. Valid plugin IDs for Drupal\Core\TypedData\TypedDataManager are: dynamic_entity_reference, ...

    Drupal\Core\Plugin\DefaultPluginManager:53
    doGetDefinition
    Drupal\Core\Plugin\DefaultPluginManager:25
    getDefinition
    Drupal\Core\TypedData\TypedDataManager: 115
    createDataDefinition
    Drupal\dynamic_entity_reference\DataDynamicReferenceDefinition: 31
    create
    Drupal\Core\TypedData\DataReferenceDefinition: 42
    createFromDataType
    Drupal\Core\TypedData\TypedDataManager: 120
    createDataDefinition
    Drupal\graphql_core_schema\EntitySchemaBuilder: 879
    getDataPropertyType
    Drupal\graphql_core_schema\EntitySchemaBuilder: 456
    getFieldItemType
    Drupal\graphql_core_schema\EntitySchemaBuilder: 387
    getFieldItemListType
    Drupal\graphql_core_schema\EntitySchemaBuilder: 766
    createEntityFields
    Drupal\graphql_core_schema\EntitySchemaBuilder: 532
    addContentEntityType
    Drupal\graphql_core_schema\EntitySchemaBuilder: 586
    generateTypeForEntityType
    Drupal\graphql_core_schema\Plugin\GraphQL\Schema\CoreComposableSchema: 176
    getSchemaDefinition
    Drupal\graphql_core_schema\Plugin\GraphQL\Schema\CoreComposableSchema: 381
    getSchemaDocument
    Drupal\graphql_core_schema\Plugin\GraphQL\Schema\CoreComposableSchema: 303
    getSchema
    ...

  • πŸ‡¨πŸ‡­Switzerland dulnan

    I looked into this. There are two problems here:

    First, the dynamic_entity_reference module has a broken annotation, as already spotted in #6:
    https://git.drupalcode.org/project/dynamic_entity_reference/-/blob/3.x/s...
    This should be fixed in the module itself, because the same error will happen every time one tries to load the definition of this data type.

    Second, even if this is fixed, there is this code in core that gets called when trying to get the definition for the "dynamic_entity_reference" data type: https://git.drupalcode.org/project/drupal/-/blob/11.x/core/lib/Drupal/Co...
    This is the class that the DataDynamicReferenceDefinition class extends from. The method will remove the "_reference" from the string and then call ::create with "dynamic_entity", which is not a valid plugin ID.

    Because the schema builder tries to figure out the best possible type for an entity reference field, it tries to get the definitions of fields and items. That way a "field_image" results in a field in GraphQL with type "MediaImage", instead of a generic "Entity" interface.

    I'll see if it's possible to work around these issues in the schema builder.

  • Status changed to Fixed 4 months ago
  • πŸ‡¨πŸ‡­Switzerland dulnan

    I was able to add rudimentary support for this specific field type, even if its data definitions are broken. Because we don't (yet) support union types, the type of the field is always going to be "Entity".

  • πŸ‡ΊπŸ‡ΈUnited States markdorison

    Thank you for the fix @dulnan! Is there any way we could get a new release with this included?

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024