diff --git a/src/GraphQL/ClassTypeDefinitions.php b/src/GraphQL/ClassTypeDefinitions.php index 7ff94c7b..8eee7382 100644 --- a/src/GraphQL/ClassTypeDefinitions.php +++ b/src/GraphQL/ClassTypeDefinitions.php @@ -37,12 +37,8 @@ public static function build(Service $graphQlService, $context = []) { $db = Db::get(); $listing = $db->fetchAllAssociative('SELECT id, name FROM classes'); - foreach ($listing as $class) { - $id = $class['id']; - $name = $class['name']; - $objectType = new PimcoreObjectType($graphQlService, $name, $id, [], $context); - self::$definitions[$name] = $objectType; + self::$definitions[$class['name']] = $graphQlService->buildDataObjectType($class['name'], [], $context); } /** diff --git a/src/GraphQL/DataObjectTypeFactory.php b/src/GraphQL/DataObjectTypeFactory.php new file mode 100644 index 00000000..65c23eac --- /dev/null +++ b/src/GraphQL/DataObjectTypeFactory.php @@ -0,0 +1,53 @@ +className = $className; + $this->setGraphQLService($graphQlService); + } + + /** + * @return mixed + */ + public function build(string $className, $config = [], $context = []) + { + if (!isset(self::$registry[$className])) { + $class = ClassDefinition::getByName($className); + $operatorImpl = new $this->className($this->getGraphQlService(), $className, $class->getId(), $config, $context); + self::$registry[$className] = $operatorImpl; + } + + return self::$registry[$className]; + } +} diff --git a/src/GraphQL/Service.php b/src/GraphQL/Service.php index d637beae..e4fffa2f 100644 --- a/src/GraphQL/Service.php +++ b/src/GraphQL/Service.php @@ -427,6 +427,23 @@ public function buildGeneralType($typeName) return $result; } + /** + * @param string $className + * @param array $config + * @param array $context + * + * @return mixed + * + * @throws \Exception + */ + public function buildDataObjectType(string $className, $config = [], $context = []) + { + $factory = $this->generalTypeGeneratorFactories->get('object'); + $result = $factory->build($className, $config, $context); + + return $result; + } + /** * @param string $typeName * diff --git a/src/Resources/config/graphql.yml b/src/Resources/config/graphql.yml index f83a796b..3c0dce6d 100644 --- a/src/Resources/config/graphql.yml +++ b/src/Resources/config/graphql.yml @@ -39,6 +39,7 @@ services: pimcore.datahub.graphql.dataobjecttype.quantity_value_input: '@Pimcore\Bundle\DataHubBundle\GraphQL\DataObjectType\QuantityValueInputType' pimcore.datahub.graphql.dataobjecttype.input_quantity_value_input: '@Pimcore\Bundle\DataHubBundle\GraphQL\DataObjectType\InputQuantityValueInputType' + pimcore.datahub.graphql.dataobjecttype.object: '@Pimcore\Bundle\DataHubBundle\GraphQL\DataObjectType\PimcoreObjectType' pimcore.datahub.graphql.dataobjecttype.object_tree: '@Pimcore\Bundle\DataHubBundle\GraphQL\DataObjectType\ObjectTreeType' pimcore.datahub.graphql.dataobjecttype._object_folder: '@Pimcore\Bundle\DataHubBundle\GraphQL\DataObjectType\ObjectFolderType' pimcore.datahub.graphql.dataobjecttype.asset_metadata_manytoone: '@Pimcore\Bundle\DataHubBundle\GraphQL\DataObjectType\HrefType' @@ -85,6 +86,14 @@ services: tags: - { name: pimcore.datahub.graphql.generaltype_factory, id: document_tree } + + pimcore.datahub.graphql.generaltype.factory.object: + class: Pimcore\Bundle\DataHubBundle\GraphQL\DataObjectTypeFactory + arguments: + $className: Pimcore\Bundle\DataHubBundle\GraphQL\DataObjectType\PimcoreObjectType + tags: + - { name: pimcore.datahub.graphql.generaltype_factory, id: object } + pimcore.datahub.graphql.generaltype.factory.object_tree: class: Pimcore\Bundle\DataHubBundle\GraphQL\GeneralTypeFactory arguments: