• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

api-platform / core / 7196499749

13 Dec 2023 02:17PM UTC coverage: 37.359% (+1.4%) from 36.003%
7196499749

push

github

web-flow
ci: conflict sebastian/comparator (#6032)

* ci: conflict sebastian/comparator

* for lowest

10295 of 27557 relevant lines covered (37.36%)

28.14 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/GraphQl/Type/FieldsBuilder.php
1
<?php
2

3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <dunglas@gmail.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
declare(strict_types=1);
13

14
namespace ApiPlatform\GraphQl\Type;
15

16
use ApiPlatform\Doctrine\Odm\State\Options as ODMOptions;
17
use ApiPlatform\Doctrine\Orm\State\Options;
18
use ApiPlatform\GraphQl\Resolver\Factory\ResolverFactory;
19
use ApiPlatform\GraphQl\Resolver\Factory\ResolverFactoryInterface;
20
use ApiPlatform\GraphQl\Type\Definition\TypeInterface;
21
use ApiPlatform\Metadata\GraphQl\Mutation;
22
use ApiPlatform\Metadata\GraphQl\Operation;
23
use ApiPlatform\Metadata\GraphQl\Query;
24
use ApiPlatform\Metadata\GraphQl\Subscription;
25
use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
26
use ApiPlatform\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface;
27
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
28
use ApiPlatform\Metadata\ResourceClassResolverInterface;
29
use ApiPlatform\Metadata\Util\Inflector;
30
use ApiPlatform\State\Pagination\Pagination;
31
use GraphQL\Type\Definition\InputObjectType;
32
use GraphQL\Type\Definition\ListOfType;
33
use GraphQL\Type\Definition\NonNull;
34
use GraphQL\Type\Definition\NullableType;
35
use GraphQL\Type\Definition\Type as GraphQLType;
36
use GraphQL\Type\Definition\WrappingType;
37
use Psr\Container\ContainerInterface;
38
use Symfony\Component\Config\Definition\Exception\InvalidTypeException;
39
use Symfony\Component\PropertyInfo\Type;
40
use Symfony\Component\Serializer\NameConverter\AdvancedNameConverterInterface;
41
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
42

43
/**
44
 * Builds the GraphQL fields.
45
 *
46
 * @author Alan Poulain <contact@alanpoulain.eu>
47
 */
48
final class FieldsBuilder implements FieldsBuilderInterface, FieldsBuilderEnumInterface
49
{
50
    private readonly TypeBuilderEnumInterface|TypeBuilderInterface $typeBuilder;
51

52
    public function __construct(private readonly PropertyNameCollectionFactoryInterface $propertyNameCollectionFactory, private readonly PropertyMetadataFactoryInterface $propertyMetadataFactory, private readonly ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory, private readonly ResourceClassResolverInterface $resourceClassResolver, private readonly TypesContainerInterface $typesContainer, TypeBuilderEnumInterface|TypeBuilderInterface $typeBuilder, private readonly TypeConverterInterface $typeConverter, private readonly ResolverFactoryInterface $itemResolverFactory, private readonly ?ResolverFactoryInterface $collectionResolverFactory, private readonly ?ResolverFactoryInterface $itemMutationResolverFactory, private readonly ?ResolverFactoryInterface $itemSubscriptionResolverFactory, private readonly ContainerInterface $filterLocator, private readonly Pagination $pagination, private readonly ?NameConverterInterface $nameConverter, private readonly string $nestingSeparator)
53
    {
54
        if ($typeBuilder instanceof TypeBuilderInterface) {
×
55
            @trigger_error(sprintf('$typeBuilder argument of FieldsBuilder implementing "%s" is deprecated since API Platform 3.1. It has to implement "%s" instead.', TypeBuilderInterface::class, TypeBuilderEnumInterface::class), \E_USER_DEPRECATED);
×
56
        }
57
        $this->typeBuilder = $typeBuilder;
×
58
    }
59

60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function getNodeQueryFields(): array
64
    {
65
        return [
×
66
            'type' => $this->typeBuilder->getNodeInterface(),
×
67
            'args' => [
×
68
                'id' => ['type' => GraphQLType::nonNull(GraphQLType::id())],
×
69
            ],
×
70
            'resolve' => ($this->itemResolverFactory)(),
×
71
        ];
×
72
    }
73

74
    /**
75
     * {@inheritdoc}
76
     */
77
    public function getItemQueryFields(string $resourceClass, Operation $operation, array $configuration): array
78
    {
79
        if ($operation instanceof Query && $operation->getNested()) {
×
80
            return [];
×
81
        }
82

83
        $fieldName = lcfirst('item_query' === $operation->getName() ? $operation->getShortName() : $operation->getName().$operation->getShortName());
×
84

85
        if ($fieldConfiguration = $this->getResourceFieldConfiguration(null, $operation->getDescription(), $operation->getDeprecationReason(), new Type(Type::BUILTIN_TYPE_OBJECT, true, $resourceClass), $resourceClass, false, $operation)) {
×
86
            $args = $this->resolveResourceArgs($configuration['args'] ?? [], $operation);
×
87
            $extraArgs = $this->resolveResourceArgs($operation->getExtraArgs() ?? [], $operation);
×
88
            $configuration['args'] = $args ?: $configuration['args'] ?? ['id' => ['type' => GraphQLType::nonNull(GraphQLType::id())]] + $extraArgs;
×
89

90
            return [$fieldName => array_merge($fieldConfiguration, $configuration)];
×
91
        }
92

93
        return [];
×
94
    }
95

96
    /**
97
     * {@inheritdoc}
98
     */
99
    public function getCollectionQueryFields(string $resourceClass, Operation $operation, array $configuration): array
100
    {
101
        if ($operation instanceof Query && $operation->getNested()) {
×
102
            return [];
×
103
        }
104

105
        $fieldName = lcfirst('collection_query' === $operation->getName() ? $operation->getShortName() : $operation->getName().$operation->getShortName());
×
106

107
        if ($fieldConfiguration = $this->getResourceFieldConfiguration(null, $operation->getDescription(), $operation->getDeprecationReason(), new Type(Type::BUILTIN_TYPE_OBJECT, false, null, true, null, new Type(Type::BUILTIN_TYPE_OBJECT, false, $resourceClass)), $resourceClass, false, $operation)) {
×
108
            $args = $this->resolveResourceArgs($configuration['args'] ?? [], $operation);
×
109
            $extraArgs = $this->resolveResourceArgs($operation->getExtraArgs() ?? [], $operation);
×
110
            $configuration['args'] = $args ?: $configuration['args'] ?? $fieldConfiguration['args'] + $extraArgs;
×
111

112
            return [Inflector::pluralize($fieldName) => array_merge($fieldConfiguration, $configuration)];
×
113
        }
114

115
        return [];
×
116
    }
117

118
    /**
119
     * {@inheritdoc}
120
     */
121
    public function getMutationFields(string $resourceClass, Operation $operation): array
122
    {
123
        $mutationFields = [];
×
124
        $resourceType = new Type(Type::BUILTIN_TYPE_OBJECT, true, $resourceClass);
×
125
        $description = $operation->getDescription() ?? ucfirst("{$operation->getName()}s a {$operation->getShortName()}.");
×
126

127
        if ($fieldConfiguration = $this->getResourceFieldConfiguration(null, $description, $operation->getDeprecationReason(), $resourceType, $resourceClass, false, $operation)) {
×
128
            $fieldConfiguration['args'] += ['input' => $this->getResourceFieldConfiguration(null, null, $operation->getDeprecationReason(), $resourceType, $resourceClass, true, $operation)];
×
129
        }
130

131
        $mutationFields[$operation->getName().$operation->getShortName()] = $fieldConfiguration ?? [];
×
132

133
        return $mutationFields;
×
134
    }
135

136
    /**
137
     * {@inheritdoc}
138
     */
139
    public function getSubscriptionFields(string $resourceClass, Operation $operation): array
140
    {
141
        $subscriptionFields = [];
×
142
        $resourceType = new Type(Type::BUILTIN_TYPE_OBJECT, true, $resourceClass);
×
143
        $description = $operation->getDescription() ?? sprintf('Subscribes to the action event of a %s.', $operation->getShortName());
×
144

145
        if ($fieldConfiguration = $this->getResourceFieldConfiguration(null, $description, $operation->getDeprecationReason(), $resourceType, $resourceClass, false, $operation)) {
×
146
            $fieldConfiguration['args'] += ['input' => $this->getResourceFieldConfiguration(null, null, $operation->getDeprecationReason(), $resourceType, $resourceClass, true, $operation)];
×
147
        }
148

149
        if (!$fieldConfiguration) {
×
150
            return [];
×
151
        }
152

153
        $subscriptionName = $operation->getName();
×
154
        // TODO: 3.0 change this
155
        if ('update_subscription' === $subscriptionName) {
×
156
            $subscriptionName = 'update';
×
157
        }
158

159
        $subscriptionFields[$subscriptionName.$operation->getShortName().'Subscribe'] = $fieldConfiguration;
×
160

161
        return $subscriptionFields;
×
162
    }
163

164
    /**
165
     * {@inheritdoc}
166
     */
167
    public function getResourceObjectTypeFields(?string $resourceClass, Operation $operation, bool $input, int $depth = 0, array $ioMetadata = null): array
168
    {
169
        $fields = [];
×
170
        $idField = ['type' => GraphQLType::nonNull(GraphQLType::id())];
×
171
        $optionalIdField = ['type' => GraphQLType::id()];
×
172
        $clientMutationId = GraphQLType::string();
×
173
        $clientSubscriptionId = GraphQLType::string();
×
174

175
        if (null !== $ioMetadata && \array_key_exists('class', $ioMetadata) && null === $ioMetadata['class']) {
×
176
            if ($input) {
×
177
                return ['clientMutationId' => $clientMutationId];
×
178
            }
179

180
            return [];
×
181
        }
182

183
        if ($operation instanceof Subscription && $input) {
×
184
            return [
×
185
                'id' => $idField,
×
186
                'clientSubscriptionId' => $clientSubscriptionId,
×
187
            ];
×
188
        }
189

190
        if ('delete' === $operation->getName()) {
×
191
            $fields = [
×
192
                'id' => $idField,
×
193
            ];
×
194

195
            if ($input) {
×
196
                $fields['clientMutationId'] = $clientMutationId;
×
197
            }
198

199
            return $fields;
×
200
        }
201

202
        if (!$input || (!$operation->getResolver() && 'create' !== $operation->getName())) {
×
203
            $fields['id'] = $idField;
×
204
        }
205
        if ($input && $depth >= 1) {
×
206
            $fields['id'] = $optionalIdField;
×
207
        }
208

209
        ++$depth; // increment the depth for the call to getResourceFieldConfiguration.
×
210

211
        if (null !== $resourceClass) {
×
212
            foreach ($this->propertyNameCollectionFactory->create($resourceClass) as $property) {
×
213
                $context = [
×
214
                    'normalization_groups' => $operation->getNormalizationContext()['groups'] ?? null,
×
215
                    'denormalization_groups' => $operation->getDenormalizationContext()['groups'] ?? null,
×
216
                ];
×
217
                $propertyMetadata = $this->propertyMetadataFactory->create($resourceClass, $property, $context);
×
218
                $propertyTypes = $propertyMetadata->getBuiltinTypes();
×
219

220
                if (
221
                    !$propertyTypes
×
222
                    || (!$input && false === $propertyMetadata->isReadable())
×
223
                    || ($input && false === $propertyMetadata->isWritable())
×
224
                ) {
225
                    continue;
×
226
                }
227

228
                // guess union/intersect types: check each type until finding a valid one
229
                foreach ($propertyTypes as $propertyType) {
×
230
                    if ($fieldConfiguration = $this->getResourceFieldConfiguration($property, $propertyMetadata->getDescription(), $propertyMetadata->getDeprecationReason(), $propertyType, $resourceClass, $input, $operation, $depth, null !== $propertyMetadata->getSecurity())) {
×
231
                        $fields['id' === $property ? '_id' : $this->normalizePropertyName($property, $resourceClass)] = $fieldConfiguration;
×
232
                        // stop at the first valid type
233
                        break;
×
234
                    }
235
                }
236
            }
237
        }
238

239
        if ($operation instanceof Mutation && $input) {
×
240
            $fields['clientMutationId'] = $clientMutationId;
×
241
        }
242

243
        return $fields;
×
244
    }
245

246
    /**
247
     * {@inheritdoc}
248
     */
249
    public function getEnumFields(string $enumClass): array
250
    {
251
        $rEnum = new \ReflectionEnum($enumClass);
×
252

253
        $enumCases = [];
×
254
        /* @var \ReflectionEnumUnitCase|\ReflectionEnumBackedCase */
255
        foreach ($rEnum->getCases() as $rCase) {
×
256
            if ($rCase instanceof \ReflectionEnumBackedCase) {
×
257
                $enumCase = ['value' => $rCase->getBackingValue()];
×
258
            } else {
259
                $enumCase = ['value' => $rCase->getValue()];
×
260
            }
261

262
            $propertyMetadata = $this->propertyMetadataFactory->create($enumClass, $rCase->getName());
×
263
            if ($enumCaseDescription = $propertyMetadata->getDescription()) {
×
264
                $enumCase['description'] = $enumCaseDescription;
×
265
            }
266
            $enumCases[$rCase->getName()] = $enumCase;
×
267
        }
268

269
        return $enumCases;
×
270
    }
271

272
    /**
273
     * {@inheritdoc}
274
     */
275
    public function resolveResourceArgs(array $args, Operation $operation): array
276
    {
277
        foreach ($args as $id => $arg) {
×
278
            if (!isset($arg['type'])) {
×
279
                throw new \InvalidArgumentException(sprintf('The argument "%s" of the custom operation "%s" in %s needs a "type" option.', $id, $operation->getName(), $operation->getShortName()));
×
280
            }
281

282
            $args[$id]['type'] = $this->typeConverter->resolveType($arg['type']);
×
283
        }
284

285
        return $args;
×
286
    }
287

288
    /**
289
     * Get the field configuration of a resource.
290
     *
291
     * @see http://webonyx.github.io/graphql-php/type-system/object-types/
292
     */
293
    private function getResourceFieldConfiguration(?string $property, ?string $fieldDescription, ?string $deprecationReason, Type $type, string $rootResource, bool $input, Operation $rootOperation, int $depth = 0, bool $forceNullable = false): ?array
294
    {
295
        try {
296
            $isCollectionType = $this->typeBuilder->isCollection($type);
×
297

298
            if (
299
                $isCollectionType
×
300
                && $collectionValueType = $type->getCollectionValueTypes()[0] ?? null
×
301
            ) {
302
                $resourceClass = $collectionValueType->getClassName();
×
303
            } else {
304
                $resourceClass = $type->getClassName();
×
305
            }
306

307
            $resourceOperation = $rootOperation;
×
308
            if ($resourceClass && $depth >= 1 && $this->resourceClassResolver->isResourceClass($resourceClass)) {
×
309
                $resourceMetadataCollection = $this->resourceMetadataCollectionFactory->create($resourceClass);
×
310
                $resourceOperation = $resourceMetadataCollection->getOperation($isCollectionType ? 'collection_query' : 'item_query');
×
311
            }
312

313
            if (!$resourceOperation instanceof Operation) {
×
314
                throw new \LogicException('The resource operation should be a GraphQL operation.');
×
315
            }
316

317
            $graphqlType = $this->convertType($type, $input, $resourceOperation, $rootOperation, $resourceClass ?? '', $rootResource, $property, $depth, $forceNullable);
×
318

319
            $graphqlWrappedType = $graphqlType;
×
320
            if ($graphqlType instanceof WrappingType) {
×
321
                if (method_exists($graphqlType, 'getInnermostType')) {
×
322
                    $graphqlWrappedType = $graphqlType->getInnermostType();
×
323
                } else {
324
                    $graphqlWrappedType = $graphqlType->getWrappedType(true);
×
325
                }
326
            }
327
            $isStandardGraphqlType = \in_array($graphqlWrappedType, GraphQLType::getStandardTypes(), true);
×
328
            if ($isStandardGraphqlType) {
×
329
                $resourceClass = '';
×
330
            }
331

332
            // Check mercure attribute if it's a subscription at the root level.
333
            if ($rootOperation instanceof Subscription && null === $property && !$rootOperation->getMercure()) {
×
334
                return null;
×
335
            }
336

337
            $args = [];
×
338

339
            if (!$input && !$rootOperation instanceof Mutation && !$rootOperation instanceof Subscription && !$isStandardGraphqlType && $isCollectionType) {
×
340
                if ($this->pagination->isGraphQlEnabled($resourceOperation)) {
×
341
                    $args = $this->getGraphQlPaginationArgs($resourceOperation);
×
342
                }
343

344
                $args = $this->getFilterArgs($args, $resourceClass, $rootResource, $resourceOperation, $rootOperation, $property, $depth);
×
345
            }
346

347
            if ($this->itemResolverFactory instanceof ResolverFactory) {
×
348
                if ($isStandardGraphqlType || $input) {
×
349
                    $resolve = null;
×
350
                } else {
351
                    $resolve = ($this->itemResolverFactory)($resourceClass, $rootResource, $resourceOperation);
×
352
                }
353
            } else {
354
                if ($isStandardGraphqlType || $input) {
×
355
                    $resolve = null;
×
356
                } elseif (($rootOperation instanceof Mutation || $rootOperation instanceof Subscription) && $depth <= 0) {
×
357
                    $resolve = $rootOperation instanceof Mutation ? ($this->itemMutationResolverFactory)($resourceClass, $rootResource, $resourceOperation) : ($this->itemSubscriptionResolverFactory)($resourceClass, $rootResource, $resourceOperation);
×
358
                } elseif ($this->typeBuilder->isCollection($type)) {
×
359
                    $resolve = ($this->collectionResolverFactory)($resourceClass, $rootResource, $resourceOperation);
×
360
                } else {
361
                    $resolve = ($this->itemResolverFactory)($resourceClass, $rootResource, $resourceOperation);
×
362
                }
363
            }
364

365
            return [
×
366
                'type' => $graphqlType,
×
367
                'description' => $fieldDescription,
×
368
                'args' => $args,
×
369
                'resolve' => $resolve,
×
370
                'deprecationReason' => $deprecationReason,
×
371
            ];
×
372
        } catch (InvalidTypeException) {
×
373
            // just ignore invalid types
374
        }
375

376
        return null;
×
377
    }
378

379
    private function getGraphQlPaginationArgs(Operation $queryOperation): array
380
    {
381
        $paginationType = $this->pagination->getGraphQlPaginationType($queryOperation);
×
382

383
        if ('cursor' === $paginationType) {
×
384
            return [
×
385
                'first' => [
×
386
                    'type' => GraphQLType::int(),
×
387
                    'description' => 'Returns the first n elements from the list.',
×
388
                ],
×
389
                'last' => [
×
390
                    'type' => GraphQLType::int(),
×
391
                    'description' => 'Returns the last n elements from the list.',
×
392
                ],
×
393
                'before' => [
×
394
                    'type' => GraphQLType::string(),
×
395
                    'description' => 'Returns the elements in the list that come before the specified cursor.',
×
396
                ],
×
397
                'after' => [
×
398
                    'type' => GraphQLType::string(),
×
399
                    'description' => 'Returns the elements in the list that come after the specified cursor.',
×
400
                ],
×
401
            ];
×
402
        }
403

404
        $paginationOptions = $this->pagination->getOptions();
×
405

406
        $args = [
×
407
            $paginationOptions['page_parameter_name'] => [
×
408
                'type' => GraphQLType::int(),
×
409
                'description' => 'Returns the current page.',
×
410
            ],
×
411
        ];
×
412

413
        if ($paginationOptions['client_items_per_page']) {
×
414
            $args[$paginationOptions['items_per_page_parameter_name']] = [
×
415
                'type' => GraphQLType::int(),
×
416
                'description' => 'Returns the number of items per page.',
×
417
            ];
×
418
        }
419

420
        return $args;
×
421
    }
422

423
    private function getFilterArgs(array $args, ?string $resourceClass, string $rootResource, Operation $resourceOperation, Operation $rootOperation, ?string $property, int $depth): array
424
    {
425
        if (null === $resourceClass) {
×
426
            return $args;
×
427
        }
428

429
        foreach ($resourceOperation->getFilters() ?? [] as $filterId) {
×
430
            if (!$this->filterLocator->has($filterId)) {
×
431
                continue;
×
432
            }
433

434
            $entityClass = $resourceClass;
×
435
            if ($options = $resourceOperation->getStateOptions()) {
×
436
                if ($options instanceof Options && $options->getEntityClass()) {
×
437
                    $entityClass = $options->getEntityClass();
×
438
                }
439

440
                if ($options instanceof ODMOptions && $options->getDocumentClass()) {
×
441
                    $entityClass = $options->getDocumentClass();
×
442
                }
443
            }
444

445
            foreach ($this->filterLocator->get($filterId)->getDescription($entityClass) as $key => $value) {
×
446
                $nullable = isset($value['required']) ? !$value['required'] : true;
×
447
                $filterType = \in_array($value['type'], Type::$builtinTypes, true) ? new Type($value['type'], $nullable) : new Type('object', $nullable, $value['type']);
×
448
                $graphqlFilterType = $this->convertType($filterType, false, $resourceOperation, $rootOperation, $resourceClass, $rootResource, $property, $depth);
×
449

450
                if (str_ends_with($key, '[]')) {
×
451
                    $graphqlFilterType = GraphQLType::listOf($graphqlFilterType);
×
452
                    $key = substr($key, 0, -2).'_list';
×
453
                }
454

455
                /** @var string $key */
456
                $key = str_replace('.', $this->nestingSeparator, $key);
×
457

458
                parse_str($key, $parsed);
×
459
                if (\array_key_exists($key, $parsed) && \is_array($parsed[$key])) {
×
460
                    $parsed = [$key => ''];
×
461
                }
462
                array_walk_recursive($parsed, static function (&$value) use ($graphqlFilterType): void {
×
463
                    $value = $graphqlFilterType;
×
464
                });
×
465
                $args = $this->mergeFilterArgs($args, $parsed, $resourceOperation, $key);
×
466
            }
467
        }
468

469
        return $this->convertFilterArgsToTypes($args);
×
470
    }
471

472
    private function mergeFilterArgs(array $args, array $parsed, Operation $operation = null, string $original = ''): array
473
    {
474
        foreach ($parsed as $key => $value) {
×
475
            // Never override keys that cannot be merged
476
            if (isset($args[$key]) && !\is_array($args[$key])) {
×
477
                continue;
×
478
            }
479

480
            if (\is_array($value)) {
×
481
                $value = $this->mergeFilterArgs($args[$key] ?? [], $value);
×
482
                if (!isset($value['#name'])) {
×
483
                    $name = (false === $pos = strrpos($original, '[')) ? $original : substr($original, 0, (int) $pos);
×
484
                    $value['#name'] = ($operation ? $operation->getShortName() : '').'Filter_'.strtr($name, ['[' => '_', ']' => '', '.' => '__']);
×
485
                }
486
            }
487

488
            $args[$key] = $value;
×
489
        }
490

491
        return $args;
×
492
    }
493

494
    private function convertFilterArgsToTypes(array $args): array
495
    {
496
        foreach ($args as $key => $value) {
×
497
            if (strpos($key, '.')) {
×
498
                // Declare relations/nested fields in a GraphQL compatible syntax.
499
                $args[str_replace('.', $this->nestingSeparator, $key)] = $value;
×
500
                unset($args[$key]);
×
501
            }
502
        }
503

504
        foreach ($args as $key => $value) {
×
505
            if (!\is_array($value) || !isset($value['#name'])) {
×
506
                continue;
×
507
            }
508

509
            $name = $value['#name'];
×
510

511
            if ($this->typesContainer->has($name)) {
×
512
                $args[$key] = $this->typesContainer->get($name);
×
513
                continue;
×
514
            }
515

516
            unset($value['#name']);
×
517

518
            $filterArgType = GraphQLType::listOf(new InputObjectType([
×
519
                'name' => $name,
×
520
                'fields' => $this->convertFilterArgsToTypes($value),
×
521
            ]));
×
522

523
            $this->typesContainer->set($name, $filterArgType);
×
524

525
            $args[$key] = $filterArgType;
×
526
        }
527

528
        return $args;
×
529
    }
530

531
    /**
532
     * Converts a built-in type to its GraphQL equivalent.
533
     *
534
     * @throws InvalidTypeException
535
     */
536
    private function convertType(Type $type, bool $input, Operation $resourceOperation, Operation $rootOperation, string $resourceClass, string $rootResource, ?string $property, int $depth, bool $forceNullable = false): GraphQLType|ListOfType|NonNull
537
    {
538
        $graphqlType = $this->typeConverter->convertType($type, $input, $rootOperation, $resourceClass, $rootResource, $property, $depth);
×
539

540
        if (null === $graphqlType) {
×
541
            throw new InvalidTypeException(sprintf('The type "%s" is not supported.', $type->getBuiltinType()));
×
542
        }
543

544
        if (\is_string($graphqlType)) {
×
545
            if (!$this->typesContainer->has($graphqlType)) {
×
546
                throw new InvalidTypeException(sprintf('The GraphQL type %s is not valid. Valid types are: %s. Have you registered this type by implementing %s?', $graphqlType, implode(', ', array_keys($this->typesContainer->all())), TypeInterface::class));
×
547
            }
548

549
            $graphqlType = $this->typesContainer->get($graphqlType);
×
550
        }
551

552
        if ($this->typeBuilder->isCollection($type)) {
×
553
            if (!$input && $this->pagination->isGraphQlEnabled($resourceOperation)) {
×
554
                // Deprecated path, to remove in API Platform 4.
555
                if ($this->typeBuilder instanceof TypeBuilderInterface) {
×
556
                    return $this->typeBuilder->getResourcePaginatedCollectionType($graphqlType, $resourceClass, $resourceOperation);
×
557
                }
558

559
                return $this->typeBuilder->getPaginatedCollectionType($graphqlType, $resourceOperation);
×
560
            }
561

562
            return GraphQLType::listOf($graphqlType);
×
563
        }
564

565
        return $forceNullable || !$graphqlType instanceof NullableType || $type->isNullable() || ($rootOperation instanceof Mutation && 'update' === $rootOperation->getName())
×
566
            ? $graphqlType
×
567
            : GraphQLType::nonNull($graphqlType);
×
568
    }
569

570
    private function normalizePropertyName(string $property, string $resourceClass): string
571
    {
572
        if (null === $this->nameConverter) {
×
573
            return $property;
×
574
        }
575
        if ($this->nameConverter instanceof AdvancedNameConverterInterface) {
×
576
            return $this->nameConverter->normalize($property, $resourceClass);
×
577
        }
578

579
        return $this->nameConverter->normalize($property);
×
580
    }
581
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc