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

Update to Doctrine ORM 3.2 #10257 #73

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
},
"require": {
"php": "^8.2",
"doctrine/orm": "^2.15",
"doctrine/orm": "^3.2",
"psr/container": "^1.1 || ^2.0",
"webonyx/graphql-php": "^15.7"
},
Expand Down
629 changes: 177 additions & 452 deletions composer.lock

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
parameters:
ignoreErrors:
-
message: "#^Cannot call method getMethods\\(\\) on ReflectionClass\\<object\\>\\|null\\.$#"
count: 1
path: src/Factory/AbstractFieldsConfigurationFactory.php

-
message: "#^Parameter \\#1 \\$property of method GraphQL\\\\Doctrine\\\\Factory\\\\AbstractFactory\\:\\:isPropertyExcluded\\(\\) expects ReflectionProperty, ReflectionProperty\\|null given\\.$#"
count: 1
path: src/Factory/Type/FilterGroupConditionTypeFactory.php

-
message: "#^Parameter \\#1 \\$property of method GraphQL\\\\Doctrine\\\\Factory\\\\Type\\\\FilterGroupConditionTypeFactory\\:\\:getLeafType\\(\\) expects ReflectionProperty, ReflectionProperty\\|null given\\.$#"
count: 1
path: src/Factory/Type/FilterGroupConditionTypeFactory.php

-
message: "#^Parameter \\#1 \\$property of method GraphQL\\\\Doctrine\\\\Factory\\\\AbstractFactory\\:\\:isPropertyExcluded\\(\\) expects ReflectionProperty, ReflectionProperty\\|null given\\.$#"
count: 1
path: src/Factory/Type/SortingTypeFactory.php

-
message: "#^Method GraphQL\\\\Doctrine\\\\Types\\:\\:getOperator\\(\\) should return GraphQL\\\\Doctrine\\\\Definition\\\\Operator\\\\AbstractOperator but returns GraphQL\\\\Type\\\\Definition\\\\NamedType&GraphQL\\\\Type\\\\Definition\\\\Type\\.$#"
count: 1
Expand Down
8 changes: 4 additions & 4 deletions src/Definition/Operator/HaveOperatorType.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace GraphQL\Doctrine\Definition\Operator;

use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\ORM\Mapping\OneToManyAssociationMapping;
use Doctrine\ORM\QueryBuilder;
use GraphQL\Doctrine\Factory\UniqueNameFactory;
use GraphQL\Type\Definition\LeafType;
Expand Down Expand Up @@ -48,12 +48,12 @@ protected function getCollectionValuedDqlCondition(UniqueNameFactory $uniqueName
// use `=`, and not `IN()`). So we simulate an approximation of MEMBER OF that support multiple values. But it
// does **not** support composite identifiers. And that is fine because it is an official limitation of this
// library anyway.
if ($association['type'] === ClassMetadataInfo::ONE_TO_MANY) {
if ($association instanceof OneToManyAssociationMapping) {
$id = $metadata->identifier[0];

$otherClassName = $association['targetEntity'];
$otherClassName = $association->targetEntity;
$otherAlias = $uniqueNameFactory->createAliasName($otherClassName);
$otherField = $association['mappedBy'];
$otherField = $association->mappedBy;
$otherMetadata = $queryBuilder->getEntityManager()->getClassMetadata($otherClassName);
$otherId = $otherMetadata->identifier[0];

Expand Down
6 changes: 3 additions & 3 deletions src/Factory/AbstractFieldsConfigurationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ private function findIdentityField(string $className): void
{
$this->metadata = $this->entityManager->getClassMetadata($className);
foreach ($this->metadata->fieldMappings as $meta) {
if ($meta['id'] ?? false) {
$this->identityField = $meta['fieldName'];
if ($meta->id ?? false) {
$this->identityField = $meta->fieldName;
}
}
}
Expand Down Expand Up @@ -184,7 +184,7 @@ final protected function isIdentityField(string $fieldName): bool
*/
private function getTargetEntity(string $fieldName): ?string
{
return $this->metadata->associationMappings[$fieldName]['targetEntity'] ?? null;
return $this->metadata->associationMappings[$fieldName]->targetEntity ?? null;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Factory/FilteredQueryBuilderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private function applyJoins(ClassMetadata $metadata, array $joins, string $alias
$joinedAlias = $this->createJoin($alias, $field, $join['type']);

if (isset($join['joins']) || isset($join['conditions'])) {
$targetClassName = $metadata->getAssociationMapping($field)['targetEntity'];
$targetClassName = $metadata->getAssociationMapping($field)->targetEntity;
$targetMetadata = $this->entityManager->getClassMetadata($targetClassName);
$type = $this->types->getFilterGroupCondition($targetClassName);
$this->applyJoinsAndFilters($targetMetadata, $joinedAlias, $type, $join['joins'] ?? [], $join['conditions'] ?? []);
Expand Down
11 changes: 6 additions & 5 deletions src/Factory/Type/FilterGroupConditionTypeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace GraphQL\Doctrine\Factory\Type;

use Doctrine\ORM\Mapping\FieldMapping;
use GraphQL\Doctrine\Attribute\Filter;
use GraphQL\Doctrine\Attribute\FilterGroupCondition;
use GraphQL\Doctrine\Definition\Operator\AbstractOperator;
Expand Down Expand Up @@ -60,7 +61,7 @@ public function create(string $className, string $typeName): InputObjectType

// Get all scalar fields
foreach ($metadata->fieldMappings as $mapping) {
$fieldName = $mapping['fieldName'];
$fieldName = $mapping->fieldName;
$property = $metadata->getReflectionProperty($fieldName);

// Skip exclusion specified by user
Expand All @@ -76,7 +77,7 @@ public function create(string $className, string $typeName): InputObjectType

// Get all collection fields
foreach ($metadata->associationMappings as $mapping) {
$fieldName = $mapping['fieldName'];
$fieldName = $mapping->fieldName;
$operators = $this->getOperators($fieldName, Type::id(), true, $metadata->isCollectionValuedAssociation($fieldName));

$filters[] = $this->getFieldConfiguration($typeName, $fieldName, $operators);
Expand Down Expand Up @@ -105,9 +106,9 @@ public function create(string $className, string $typeName): InputObjectType
/**
* Read the type of the filterGroupCondition, either from Doctrine mapping type, or the override via attribute.
*/
private function getLeafType(ReflectionProperty $property, array $mapping): LeafType
private function getLeafType(ReflectionProperty $property, FieldMapping $mapping): LeafType
{
if ($mapping['id'] ?? false) {
if ($mapping->id ?? false) {
return Type::id();
}

Expand All @@ -127,7 +128,7 @@ private function getLeafType(ReflectionProperty $property, array $mapping): Leaf
}

/** @var LeafType $leafType */
$leafType = $this->types->get($mapping['type']);
$leafType = $this->types->get($mapping->type);

return $leafType;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Factory/Type/FilterGroupJoinTypeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ private function getJoinsFields(string $className): array
$associations = $this->entityManager->getClassMetadata($className)->associationMappings;
foreach ($associations as $association) {
$field = [
'name' => $association['fieldName'],
'type' => $this->types->getJoinOn($association['targetEntity']),
'name' => $association->fieldName,
'type' => $this->types->getJoinOn($association->targetEntity),
];

$fields[] = $field;
Expand Down
4 changes: 2 additions & 2 deletions tests/Blog/Filtering/SearchOperatorType.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ private function getSearchableFields(ClassMetadata $metadata, string $alias): ar
$fields = [];
$textType = ['string', 'text'];
foreach ($metadata->fieldMappings as $g) {
if (in_array($g['type'], $textType, true)) {
$fields[] = $alias . '.' . $g['fieldName'];
if (in_array($g->type, $textType, true)) {
$fields[] = $alias . '.' . $g->fieldName;
}
}

Expand Down
5 changes: 4 additions & 1 deletion tests/EntityManagerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ trait EntityManagerTrait
private function setUpEntityManager(): void
{
$config = ORMSetup::createAttributeMetadataConfiguration([__DIR__ . '/Blog/Model'], true);
$connection = DriverManager::getConnection(['url' => 'sqlite:///:memory:']);
$connection = DriverManager::getConnection([
'driver' => 'sqlite3',
'memory' => true,
]);

$this->entityManager = new EntityManager($connection, $config);
}
Expand Down
Loading
Loading