|
19 | 19 | use ApiPlatform\GraphQl\Resolver\Factory\ResolverFactory; |
20 | 20 | use ApiPlatform\GraphQl\Resolver\Factory\ResolverFactoryInterface; |
21 | 21 | use ApiPlatform\GraphQl\Type\Definition\TypeInterface; |
| 22 | +use ApiPlatform\Metadata\FilterInterface; |
22 | 23 | use ApiPlatform\Metadata\GraphQl\Mutation; |
23 | 24 | use ApiPlatform\Metadata\GraphQl\Operation; |
24 | 25 | use ApiPlatform\Metadata\GraphQl\Query; |
@@ -292,41 +293,6 @@ public function resolveResourceArgs(array $args, Operation $operation): array |
292 | 293 | $args[$id]['type'] = $this->typeConverter->resolveType($arg['type']); |
293 | 294 | } |
294 | 295 |
|
295 | | - /* |
296 | | - * This is @experimental, read the comment on the parameterToObjectType function as additional information. |
297 | | - */ |
298 | | - foreach ($operation->getParameters() ?? [] as $parameter) { |
299 | | - $key = $parameter->getKey(); |
300 | | - |
301 | | - if (str_contains($key, ':property')) { |
302 | | - if (!($filterId = $parameter->getFilter()) || !$this->filterLocator->has($filterId)) { |
303 | | - continue; |
304 | | - } |
305 | | - |
306 | | - $parsedKey = explode('[:property]', $key); |
307 | | - $flattenFields = []; |
308 | | - foreach ($this->filterLocator->get($filterId)->getDescription($operation->getClass()) as $key => $value) { |
309 | | - $values = []; |
310 | | - parse_str($key, $values); |
311 | | - if (isset($values[$parsedKey[0]])) { |
312 | | - $values = $values[$parsedKey[0]]; |
313 | | - } |
314 | | - |
315 | | - $name = key($values); |
316 | | - $flattenFields[] = ['name' => $name, 'required' => $value['required'] ?? null, 'description' => $value['description'] ?? null, 'leafs' => $values[$name], 'type' => $value['type'] ?? 'string']; |
317 | | - } |
318 | | - |
319 | | - $args[$parsedKey[0]] = $this->parameterToObjectType($flattenFields, $parsedKey[0]); |
320 | | - continue; |
321 | | - } |
322 | | - |
323 | | - $args[$key] = ['type' => GraphQLType::string()]; |
324 | | - |
325 | | - if ($parameter->getRequired()) { |
326 | | - $args[$key]['type'] = GraphQLType::nonNull($args[$key]['type']); |
327 | | - } |
328 | | - } |
329 | | - |
330 | 296 | return $args; |
331 | 297 | } |
332 | 298 |
|
@@ -448,12 +414,15 @@ private function getResourceFieldConfiguration(?string $property, ?string $field |
448 | 414 |
|
449 | 415 | $args = []; |
450 | 416 |
|
451 | | - if (!$input && !$rootOperation instanceof Mutation && !$rootOperation instanceof Subscription && !$isStandardGraphqlType && $isCollectionType) { |
452 | | - if (!$this->isEnumClass($resourceClass) && $this->pagination->isGraphQlEnabled($resourceOperation)) { |
453 | | - $args = $this->getGraphQlPaginationArgs($resourceOperation); |
454 | | - } |
| 417 | + if (!$input && !$rootOperation instanceof Mutation && !$rootOperation instanceof Subscription && !$isStandardGraphqlType) { |
| 418 | + if ($isCollectionType) { |
| 419 | + if (!$this->isEnumClass($resourceClass) && $this->pagination->isGraphQlEnabled($resourceOperation)) { |
| 420 | + $args = $this->getGraphQlPaginationArgs($resourceOperation); |
| 421 | + } |
455 | 422 |
|
456 | | - $args = $this->getFilterArgs($args, $resourceClass, $rootResource, $resourceOperation, $rootOperation, $property, $depth); |
| 423 | + $args = $this->getFilterArgs($args, $resourceClass, $rootResource, $resourceOperation, $rootOperation, $property, $depth); |
| 424 | + $args = $this->getParameterArgs($rootOperation, $args); |
| 425 | + } |
457 | 426 | } |
458 | 427 |
|
459 | 428 | if ($this->itemResolverFactory instanceof ResolverFactory) { |
@@ -488,6 +457,52 @@ private function getResourceFieldConfiguration(?string $property, ?string $field |
488 | 457 | return null; |
489 | 458 | } |
490 | 459 |
|
| 460 | + /* |
| 461 | + * This function is @experimental, read the comment on the parameterToObjectType function for additional information. |
| 462 | + * @experimental |
| 463 | + */ |
| 464 | + private function getParameterArgs(Operation $operation, array $args = []): array |
| 465 | + { |
| 466 | + foreach ($operation->getParameters() ?? [] as $parameter) { |
| 467 | + $key = $parameter->getKey(); |
| 468 | + |
| 469 | + if (!str_contains($key, ':property')) { |
| 470 | + $args[$key] = ['type' => GraphQLType::string()]; |
| 471 | + |
| 472 | + if ($parameter->getRequired()) { |
| 473 | + $args[$key]['type'] = GraphQLType::nonNull($args[$key]['type']); |
| 474 | + } |
| 475 | + |
| 476 | + continue; |
| 477 | + } |
| 478 | + |
| 479 | + if (!($filterId = $parameter->getFilter()) || !$this->filterLocator->has($filterId)) { |
| 480 | + continue; |
| 481 | + } |
| 482 | + |
| 483 | + $filter = $this->filterLocator->get($filterId); |
| 484 | + $parsedKey = explode('[:property]', $key); |
| 485 | + $flattenFields = []; |
| 486 | + |
| 487 | + if ($filter instanceof FilterInterface) { |
| 488 | + foreach ($filter->getDescription($operation->getClass()) as $name => $value) { |
| 489 | + $values = []; |
| 490 | + parse_str($name, $values); |
| 491 | + if (isset($values[$parsedKey[0]])) { |
| 492 | + $values = $values[$parsedKey[0]]; |
| 493 | + } |
| 494 | + |
| 495 | + $name = key($values); |
| 496 | + $flattenFields[] = ['name' => $name, 'required' => $value['required'] ?? null, 'description' => $value['description'] ?? null, 'leafs' => $values[$name], 'type' => $value['type'] ?? 'string']; |
| 497 | + } |
| 498 | + |
| 499 | + $args[$parsedKey[0]] = $this->parameterToObjectType($flattenFields, $parsedKey[0]); |
| 500 | + } |
| 501 | + } |
| 502 | + |
| 503 | + return $args; |
| 504 | + } |
| 505 | + |
491 | 506 | private function getGraphQlPaginationArgs(Operation $queryOperation): array |
492 | 507 | { |
493 | 508 | $paginationType = $this->pagination->getGraphQlPaginationType($queryOperation); |
|
0 commit comments