Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error "type definition ... not found" in advanced many-to-many-fields. #39

Closed
RobinBrackez opened this issue May 27, 2019 · 4 comments
Closed
Assignees
Labels

Comments

@RobinBrackez
Copy link

@RobinBrackez RobinBrackez commented May 27, 2019

Issue:
Object of type A contains an advanced many to many-relation with object of type B.

You make a data-hub config for type A and you want to display some info of type B.

{
  getA (id: 1){
    id,
    b {
      ... on object_B {
        id
      }
    }
  }
}

This results in the error "type definition B not found". You get this error even without requesting any info of object B.

I found \Pimcore\Bundle\DataHubBundle\GraphQL\ClassTypeDefinitions::build to be partly responsible. In that method the classes are loaded alphabetically, first class A, then class B. However, class A has a reference to class B, so it executes \Pimcore\Bundle\DataHubBundle\GraphQL\ClassTypeDefinitions::get with "B" as parameter, but at that moment, class B isn't loaded yet, so it throws the error.

This is not the case with simple many-to-one fields. In that case, all the classes are loaded before the get() method gets executed.

This screenshot contains a real life example. Class "Dealer" (A) has a reference to "Order" (B). Dealer gets loaded in the build() foreach-loop, then jumps to the get() method to collect Order, which at that time isn't loaded yet, because the foreach-loop in build() is still processing "Dealer".
Selection_999(121)

Hope this is clear :)

@weisswurstkanone
Copy link
Collaborator

@weisswurstkanone weisswurstkanone commented May 28, 2019

Please provide the full stack trace.

Besides that it seems that the sample is not correct.
Should it be rather be something like this ?

{
getAAA(id: 53) {
id
manytomany {
element {
... on object_BBB {
id
}
}
}
}
}

where manytomany is the advanced manytomany field.

@RobinBrackez
Copy link
Author

@RobinBrackez RobinBrackez commented May 29, 2019

I'm sorry, it's an "Advanced Many-To-Many Object Relation", not an "Advanced Many-To-Many Relation".
I did some tests and the "Advanced Many-To-Many Relation" works as you describe in your example (I didn't know I had to add an extra "element" tag).
But the "Advanced Many-To-Many Object Relation" doesn't work.

Stacktrace:

Exception:
type definition BBB not found

  at vendor/pimcore/data-hub/src/GraphQL/ClassTypeDefinitions.php:57
  at Pimcore\Bundle\DataHubBundle\GraphQL\ClassTypeDefinitions::get('BBB')
     (vendor/pimcore/data-hub/src/GraphQL/Type/ObjectMetadataType.php:63)
  at Pimcore\Bundle\DataHubBundle\GraphQL\Type\ObjectMetadataType->build(array('name' => 'object_AAA_bField'))
     (vendor/pimcore/data-hub/src/GraphQL/Type/ObjectMetadataType.php:48)
  at Pimcore\Bundle\DataHubBundle\GraphQL\Type\ObjectMetadataType->__construct(object(Service), object(AdvancedManyToManyObjectRelation), object(ClassDefinition))
     (vendor/pimcore/data-hub/src/GraphQL/FieldConfigGenerator/ObjectsMetadata.php:52)
  at Pimcore\Bundle\DataHubBundle\GraphQL\FieldConfigGenerator\ObjectsMetadata->getFieldType(object(AdvancedManyToManyObjectRelation), object(ClassDefinition), null)
     (vendor/pimcore/data-hub/src/GraphQL/FieldConfigGenerator/ObjectsMetadata.php:36)
  at Pimcore\Bundle\DataHubBundle\GraphQL\FieldConfigGenerator\ObjectsMetadata->getGraphQlFieldConfig(object(AdvancedManyToManyObjectRelation), object(ClassDefinition), null)
     (vendor/pimcore/data-hub/src/GraphQL/Service.php:120)
  at Pimcore\Bundle\DataHubBundle\GraphQL\Service->buildDataQueryConfig('advancedManyToManyObjectRelation', object(AdvancedManyToManyObjectRelation), object(ClassDefinition), null)
     (vendor/pimcore/data-hub/src/GraphQL/FieldHelper/DataObjectFieldHelper.php:57)
  at Pimcore\Bundle\DataHubBundle\GraphQL\FieldHelper\DataObjectFieldHelper->getGraphQlFieldConfig(object(AdvancedManyToManyObjectRelation), object(ClassDefinition), null)
     (vendor/pimcore/data-hub/src/GraphQL/FieldHelper/DataObjectFieldHelper.php:172)
  at Pimcore\Bundle\DataHubBundle\GraphQL\FieldHelper\DataObjectFieldHelper->getFieldConfigFromConfig(array('attributes' => array('attribute' => 'bField', 'label' => 'bField', 'dataType' => 'advancedManyToManyObjectRelation', 'layout' => array('allowedClassId' => 'BBB', 'visibleFields' => 'name', 'columns' => array(), 'fieldtype' => 'advancedManyToManyObjectRelation', 'phpdocType' => '\\Pimcore\\Model\\DataObject\\Data\\ObjectMetadata[]', 'enableBatchEdit' => false, 'allowMultipleAssignments' => false, 'width' => '', 'height' => '', 'maxItems' => '', 'queryColumnType' => 'text', 'relationType' => true, 'optimizedAdminLoading' => false, 'lazyLoading' => true, 'classes' => array(), 'pathFormatterClass' => '', 'name' => 'bField', 'title' => 'bField', 'tooltip' => 'Doesn\'t work', 'mandatory' => false, 'noteditable' => false, 'index' => false, 'locked' => false, 'style' => '', 'permissions' => null, 'datatype' => 'data', 'invisible' => false, 'visibleGridView' => false, 'visibleSearch' => false, 'columnKeys' => array())), 'isOperator' => false), object(ClassDefinition), array('isRoot' => true))
     (vendor/pimcore/data-hub/src/GraphQL/Type/PimcoreObjectType.php:92)
  at Pimcore\Bundle\DataHubBundle\GraphQL\Type\PimcoreObjectType->build(array('clientname' => 'test', 'configuration' => object(Configuration)))
     (vendor/pimcore/data-hub/src/GraphQL/ClassTypeDefinitions.php:41)
  at Pimcore\Bundle\DataHubBundle\GraphQL\ClassTypeDefinitions::build(object(Service), array('clientname' => 'test', 'configuration' => object(Configuration)))
     (vendor/pimcore/data-hub/src/Controller/WebserviceController.php:71)
  at Pimcore\Bundle\DataHubBundle\Controller\WebserviceController->webonyxAction(object(Service), object(LocaleService), object(Factory), object(Request))
     (vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php:151)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
     (vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php:68)
  at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
     (vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:200)
  at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
     (web/app.php:42)

Objects:
class_AAA_export.json.txt
class_BBB_export.json.txt

Selection_999(124)
Selection_999(123)
Selection_999(126)

@weisswurstkanone
Copy link
Collaborator

@weisswurstkanone weisswurstkanone commented May 29, 2019

thx for the clarification!

@RobinBrackez
Copy link
Author

@RobinBrackez RobinBrackez commented May 29, 2019

That works! Thanks for the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants