|
16 | 16 | use ApiPlatform\Core\Exception\ResourceClassNotFoundException;
|
17 | 17 | use ApiPlatform\Core\GraphQl\Resolver\Factory\ResolverFactoryInterface;
|
18 | 18 | use ApiPlatform\Core\GraphQl\Serializer\ItemNormalizer;
|
| 19 | +use ApiPlatform\Core\GraphQl\Type\Definition\InputUnionType; |
19 | 20 | use ApiPlatform\Core\GraphQl\Type\Definition\IterableType;
|
20 | 21 | use ApiPlatform\Core\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
|
21 | 22 | use ApiPlatform\Core\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface;
|
@@ -335,13 +336,24 @@ private function convertType(Type $type, bool $input = false, string $mutationNa
|
335 | 336 | break;
|
336 | 337 | case Type::BUILTIN_TYPE_ARRAY:
|
337 | 338 | case Type::BUILTIN_TYPE_ITERABLE:
|
338 |
| - if (!isset($this->graphqlTypes['#iterable'])) { |
339 |
| - $this->graphqlTypes['#iterable'] = new IterableType(); |
340 |
| - } |
341 |
| - $graphqlType = $this->graphqlTypes['#iterable']; |
| 339 | + $graphqlType = $this->getIterableType(); |
342 | 340 | break;
|
343 | 341 | case Type::BUILTIN_TYPE_OBJECT:
|
344 |
| - if (($input && $depth > 0) || is_a($type->getClassName(), \DateTimeInterface::class, true)) { |
| 342 | + if ($input && $depth > 0) { |
| 343 | + if (!isset($this->graphqlTypes['#stringIterableUnionInput'])) { |
| 344 | + $this->graphqlTypes['#stringIterableUnionInput'] = new InputUnionType([ |
| 345 | + 'name' => 'StringIterableUnionInput', |
| 346 | + 'description' => 'Resource\'s IRI or data (embedded entities or when updating a related existing resource)', |
| 347 | + 'types' => [ |
| 348 | + GraphQLType::string(), |
| 349 | + $this->getIterableType(), |
| 350 | + ], |
| 351 | + ]); |
| 352 | + } |
| 353 | + $graphqlType = $this->graphqlTypes['#stringIterableUnionInput']; |
| 354 | + break; |
| 355 | + } |
| 356 | + if (is_a($type->getClassName(), \DateTimeInterface::class, true)) { |
345 | 357 | $graphqlType = GraphQLType::string();
|
346 | 358 | break;
|
347 | 359 | }
|
@@ -492,6 +504,15 @@ private function getResourcePaginatedCollectionType(string $resourceClass, Graph
|
492 | 504 | return $this->graphqlTypes[$resourceClass]['connection'] = new ObjectType($configuration);
|
493 | 505 | }
|
494 | 506 |
|
| 507 | + private function getIterableType(): IterableType |
| 508 | + { |
| 509 | + if (!isset($this->graphqlTypes['#iterable'])) { |
| 510 | + $this->graphqlTypes['#iterable'] = new IterableType(); |
| 511 | + } |
| 512 | + |
| 513 | + return $this->graphqlTypes['#iterable']; |
| 514 | + } |
| 515 | + |
495 | 516 | private function isCollection(Type $type): bool
|
496 | 517 | {
|
497 | 518 | return $type->isCollection() && Type::BUILTIN_TYPE_OBJECT === $type->getBuiltinType();
|
|
0 commit comments