diff --git a/composer.json b/composer.json index f2d6ba1..fca0540 100644 --- a/composer.json +++ b/composer.json @@ -15,6 +15,7 @@ "zendframework/zend-hydrator": "^2.4", "zendframework/zend-modulemanager": "^2.8", "doctrine/common": "^2.8", + "doctrine/doctrine-orm-module": "^1.1.8", "zendframework/zend-mvc-console": "^1.2", "zendframework/zend-config": "^3.2", "api-skeletons/zf-doctrine-criteria": "^1.0", diff --git a/src/Type/EntityTypeAbstractFactory.php b/src/Type/EntityTypeAbstractFactory.php index f811ff8..f2bc8bb 100644 --- a/src/Type/EntityTypeAbstractFactory.php +++ b/src/Type/EntityTypeAbstractFactory.php @@ -141,10 +141,10 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o ) { $collection = $fieldResolver($source, $args, $context, $resolveInfo); - // Do not process empty collections - if (! sizeof($collection)) { - return []; - } + // It is better to process empty collections than extract an entire collection + // just to get its count. Lazy loading will fetch a whole collection to get + // a count but extra lazy will not. + // There was a check here for collection size; now removed. $filter = $args['filter'] ?? []; $filterArray = []; @@ -232,7 +232,6 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o $distinctField = $field; } break; - case 'memberof': default: $filterArray[] = [ 'type' => $filter, @@ -244,7 +243,7 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o } } - $entityClassName = ClassUtils::getRealClass(get_class($collection->first())); + $entityClassName = $collection->getTypeClass()->name; $metadata = $objectManager->getClassMetadata($entityClassName); foreach ($filterArray as $key => $filter) { @@ -265,14 +264,14 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o } //Rebuild collection using hydrators - $entityClassName = ClassUtils::getRealClass(get_class($collection->first())); $hydratorAlias = 'ZF\\Doctrine\\GraphQL\\Hydrator\\' . str_replace('\\', '_', $entityClassName); - - $data = $hydratorExtractTool - ->extractToCollection($collection, $hydratorAlias, $options); - - $matching = $data->matching($criteria); + $matching = $hydratorExtractTool + ->extractToCollection( + $collection->matching($criteria), + $hydratorAlias, + $options + ); if ($distinctField) { $distinctValueArray = []; diff --git a/test/GraphQL/CriteriaFiltersTest.php b/test/GraphQL/CriteriaFiltersTest.php index 8428faf..9041607 100644 --- a/test/GraphQL/CriteriaFiltersTest.php +++ b/test/GraphQL/CriteriaFiltersTest.php @@ -125,7 +125,7 @@ public function testIsNotNull($schemaName, $context) $result = GraphQL::executeQuery($schema, $query, $rootValue = null, $context, $variableValues = null); $output = $result->toArray(); - $this->assertEquals(3, sizeof($output['data']['artist'][0]['performance'])); + $this->assertEquals(2, sizeof($output['data']['artist'][0]['performance'])); } /** @@ -294,21 +294,6 @@ public function testOverTheLimit($schemaName, $context) $this->assertEquals(5, sizeof($output['data']['artist'][0]['performance'])); } - /** - * @dataProvider schemaDataProvider - */ - public function testMemberOf($schemaName, $context) - { - $schema = $this->getSchema($schemaName); - - $query = "{ user ( filter: { id:1 } ) { name artist ( filter: { alias_memberof:\"b2\" } ) { id alias } } }"; - - $result = GraphQL::executeQuery($schema, $query, $rootValue = null, $context, $variableValues = null); - $output = $result->toArray(); - - $this->assertEquals(['b1', 'b2', 'b3'], $output['data']['user'][0]['artist'][0]['alias']); - } - /** * @dataProvider schemaDataProvider */ diff --git a/test/GraphQL/QueryBuilderFiltersTest.php b/test/GraphQL/QueryBuilderFiltersTest.php index 13197f2..bca40ce 100644 --- a/test/GraphQL/QueryBuilderFiltersTest.php +++ b/test/GraphQL/QueryBuilderFiltersTest.php @@ -293,21 +293,6 @@ public function testOverTheLimit($schemaName, $context) $this->assertEquals(5, sizeof($output['data']['performance'])); } - /** - * @dataProvider schemaDataProvider - */ - public function testMemberOf($schemaName, $context) - { - $schema = $this->getSchema($schemaName); - - $query = "{ artist ( filter: { alias_memberof:\"b2\" } ) { id alias } }"; - - $result = GraphQL::executeQuery($schema, $query, $rootValue = null, $context, $variableValues = null); - $output = $result->toArray(); - - $this->assertEquals(['b1', 'b2', 'b3'], $output['data']['artist'][0]['alias']); - } - /** * @dataProvider schemaDataProvider */