Skip to content

Commit

Permalink
Merge branch 'feature/continued-9.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
TomHAnderson committed Dec 12, 2023
2 parents 0cd36cf + 2f30437 commit 2ad5aa9
Showing 1 changed file with 42 additions and 43 deletions.
85 changes: 42 additions & 43 deletions src/Type/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,50 +178,49 @@ protected function addAssociations(array &$fields): void
}

$associationMetadata = $classMetadata->getAssociationMapping($associationName);

switch ($associationMetadata['type']) {
case ClassMetadataInfo::ONE_TO_ONE:
case ClassMetadataInfo::MANY_TO_ONE:
case ClassMetadataInfo::TO_ONE:
$targetEntity = $associationMetadata['targetEntity'];
$fields[$associationName] = function () use ($targetEntity) {
$entity = $this->typeManager->build(self::class, $targetEntity);

return [
'type' => $entity->getGraphQLType(),
'description' => $entity->getDescription(),
];
};
break;
case ClassMetadataInfo::ONE_TO_MANY:
case ClassMetadataInfo::MANY_TO_MANY:
case ClassMetadataInfo::TO_MANY:
$targetEntity = $associationMetadata['targetEntity'];
$fields[$associationName] = function () use ($targetEntity, $associationName) {
$entity = $this->typeManager->build(self::class, $targetEntity);
$shortName = $this->getTypeName() . '_' . $associationName;

return [
'type' => $this->typeManager->build(
Connection::class,
$shortName . '_Connection',
$entity->getGraphQLType(),
),
'args' => [
'filter' => $this->filterFactory->get(
$entity,
$this,
$associationName,
$this->metadata['fields'][$associationName],
),
'pagination' => $this->typeManager->get('pagination'),
],
'description' => $this->metadata['fields'][$associationName]['description'],
'resolve' => $this->collectionFactory->get($entity),
];
};
break;
if (
in_array($associationMetadata['type'], [
ClassMetadataInfo::ONE_TO_ONE,
ClassMetadataInfo::MANY_TO_ONE,
ClassMetadataInfo::TO_ONE,
])
) {
$targetEntity = $associationMetadata['targetEntity'];
$fields[$associationName] = function () use ($targetEntity) {
$entity = $this->typeManager->build(self::class, $targetEntity);

return [
'type' => $entity->getGraphQLType(),
'description' => $entity->getDescription(),
];
};
}

// Collections
$targetEntity = $associationMetadata['targetEntity'];
$fields[$associationName] = function () use ($targetEntity, $associationName) {
$entity = $this->typeManager->build(self::class, $targetEntity);
$shortName = $this->getTypeName() . '_' . $associationName;

return [
'type' => $this->typeManager->build(
Connection::class,
$shortName . '_Connection',
$entity->getGraphQLType(),
),
'args' => [
'filter' => $this->filterFactory->get(
$entity,
$this,
$associationName,
$this->metadata['fields'][$associationName],
),
'pagination' => $this->typeManager->get('pagination'),
],
'description' => $this->metadata['fields'][$associationName]['description'],
'resolve' => $this->collectionFactory->get($entity),
];
};
}
}
}

0 comments on commit 2ad5aa9

Please sign in to comment.