|
22 | 22 | use ApiPlatform\Metadata\GraphQl\Query; |
23 | 23 | use ApiPlatform\Metadata\GraphQl\Subscription; |
24 | 24 | use ApiPlatform\Metadata\InflectorInterface; |
25 | | -use ApiPlatform\Metadata\OpenApiParameterFilterInterface; |
26 | 25 | use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface; |
27 | 26 | use ApiPlatform\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface; |
28 | 27 | use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface; |
@@ -356,6 +355,8 @@ private function parameterToObjectType(array $flattenFields, string $name): Inpu |
356 | 355 | if (isset($fields[$key])) { |
357 | 356 | if ($type instanceof ListOfType) { |
358 | 357 | $key .= '_list'; |
| 358 | + } elseif ($fields[$key]['type'] instanceof InputObjectType && !$type instanceof InputObjectType) { |
| 359 | + continue; |
359 | 360 | } |
360 | 361 | } |
361 | 362 |
|
@@ -497,56 +498,64 @@ private function getResourceFieldConfiguration(?string $property, ?string $field |
497 | 498 | */ |
498 | 499 | private function getParameterArgs(Operation $operation, array $args = []): array |
499 | 500 | { |
| 501 | + $groups = []; |
| 502 | + |
500 | 503 | foreach ($operation->getParameters() ?? [] as $parameter) { |
501 | 504 | $key = $parameter->getKey(); |
502 | 505 |
|
503 | | - if (!str_contains($key, ':property')) { |
504 | | - $args[$key] = ['type' => GraphQLType::string()]; |
505 | | - |
506 | | - if ($parameter->getRequired()) { |
507 | | - $args[$key]['type'] = GraphQLType::nonNull($args[$key]['type']); |
| 506 | + if (str_contains($key, '[')) { |
| 507 | + $key = str_replace('.', $this->nestingSeparator, $key); |
| 508 | + parse_str($key, $values); |
| 509 | + $rootKey = key($values); |
| 510 | + |
| 511 | + $leafs = $values[$rootKey]; |
| 512 | + $name = key($leafs); |
| 513 | + |
| 514 | + $filterLeafs = []; |
| 515 | + if (($filterId = $parameter->getFilter()) && $this->filterLocator->has($filterId)) { |
| 516 | + $filter = $this->filterLocator->get($filterId); |
| 517 | + |
| 518 | + if ($filter instanceof FilterInterface) { |
| 519 | + $property = $parameter->getProperty() ?? $name; |
| 520 | + $property = str_replace('.', $this->nestingSeparator, $property); |
| 521 | + $description = $filter->getDescription($operation->getClass()); |
| 522 | + |
| 523 | + foreach ($description as $descKey => $descValue) { |
| 524 | + $descKey = str_replace('.', $this->nestingSeparator, $descKey); |
| 525 | + parse_str($descKey, $descValues); |
| 526 | + if (isset($descValues[$property]) && \is_array($descValues[$property])) { |
| 527 | + $filterLeafs = array_merge($filterLeafs, $descValues[$property]); |
| 528 | + } |
| 529 | + } |
| 530 | + } |
508 | 531 | } |
509 | 532 |
|
510 | | - continue; |
511 | | - } |
| 533 | + if ($filterLeafs) { |
| 534 | + $leafs[$name] = $filterLeafs; |
| 535 | + } |
512 | 536 |
|
513 | | - if (!($filterId = $parameter->getFilter()) || !$this->filterLocator->has($filterId)) { |
| 537 | + $groups[$rootKey][] = [ |
| 538 | + 'name' => $name, |
| 539 | + 'leafs' => $leafs[$name], |
| 540 | + 'required' => $parameter->getRequired(), |
| 541 | + 'description' => $parameter->getDescription(), |
| 542 | + 'type' => 'string', |
| 543 | + ]; |
514 | 544 | continue; |
515 | 545 | } |
516 | 546 |
|
517 | | - $filter = $this->filterLocator->get($filterId); |
518 | | - $parsedKey = explode('[:property]', $key); |
519 | | - $flattenFields = []; |
| 547 | + $args[$key] = ['type' => GraphQLType::string()]; |
520 | 548 |
|
521 | | - if ($filter instanceof FilterInterface) { |
522 | | - foreach ($filter->getDescription($operation->getClass()) as $name => $value) { |
523 | | - $values = []; |
524 | | - parse_str($name, $values); |
525 | | - if (isset($values[$parsedKey[0]])) { |
526 | | - $values = $values[$parsedKey[0]]; |
527 | | - } |
528 | | - |
529 | | - $name = key($values); |
530 | | - $flattenFields[] = ['name' => $name, 'required' => $value['required'] ?? null, 'description' => $value['description'] ?? null, 'leafs' => $values[$name], 'type' => $value['type'] ?? 'string']; |
531 | | - } |
532 | | - |
533 | | - $args[$parsedKey[0]] = $this->parameterToObjectType($flattenFields, $parsedKey[0]); |
| 549 | + if ($parameter->getRequired()) { |
| 550 | + $args[$key]['type'] = GraphQLType::nonNull($args[$key]['type']); |
534 | 551 | } |
| 552 | + } |
535 | 553 |
|
536 | | - if ($filter instanceof OpenApiParameterFilterInterface) { |
537 | | - foreach ($filter->getOpenApiParameters($parameter) as $value) { |
538 | | - $values = []; |
539 | | - parse_str($value->getName(), $values); |
540 | | - if (isset($values[$parsedKey[0]])) { |
541 | | - $values = $values[$parsedKey[0]]; |
542 | | - } |
543 | | - |
544 | | - $name = key($values); |
545 | | - $flattenFields[] = ['name' => $name, 'required' => $value->getRequired(), 'description' => $value->getDescription(), 'leafs' => $values[$name], 'type' => $value->getSchema()['type'] ?? 'string']; |
546 | | - } |
547 | | - |
548 | | - $args[$parsedKey[0]] = $this->parameterToObjectType($flattenFields, $parsedKey[0].$operation->getShortName().$operation->getName()); |
549 | | - } |
| 554 | + foreach ($groups as $key => $flattenFields) { |
| 555 | + $name = $key.$operation->getShortName().$operation->getName(); |
| 556 | + $inputObject = $this->parameterToObjectType($flattenFields, $name); |
| 557 | + $this->typesContainer->set($name, $inputObject); |
| 558 | + $args[$key] = $inputObject; |
550 | 559 | } |
551 | 560 |
|
552 | 561 | return $args; |
|
0 commit comments