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

api-platform / core / 14954769666

11 May 2025 10:14AM UTC coverage: 0.0% (-8.5%) from 8.457%
14954769666

Pull #7135

github

web-flow
Merge bf21e0bc7 into 4dd0cdfc4
Pull Request #7135: fix(symfony,laravel): InvalidUriVariableException status code (e400)

0 of 2 new or added lines in 2 files covered. (0.0%)

11040 existing lines in 370 files now uncovered.

0 of 48303 relevant lines covered (0.0%)

0.0 hits per line

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

0.0
/src/GraphQl/Type/SchemaBuilder.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\Metadata\CollectionOperationInterface;
17
use ApiPlatform\Metadata\GraphQl\Query;
18
use ApiPlatform\Metadata\GraphQl\Subscription;
19
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
20
use ApiPlatform\Metadata\Resource\Factory\ResourceNameCollectionFactoryInterface;
21
use GraphQL\Type\Definition\NamedType;
22
use GraphQL\Type\Definition\ObjectType;
23
use GraphQL\Type\Definition\Type;
24
use GraphQL\Type\Schema;
25

26
/**
27
 * Builds the GraphQL schema.
28
 *
29
 * @author Raoul Clais <raoul.clais@gmail.com>
30
 * @author Alan Poulain <contact@alanpoulain.eu>
31
 * @author Kévin Dunglas <dunglas@gmail.com>
32
 */
33
final class SchemaBuilder implements SchemaBuilderInterface
34
{
35
    public function __construct(private readonly ResourceNameCollectionFactoryInterface $resourceNameCollectionFactory, private readonly ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory, private readonly TypesFactoryInterface $typesFactory, private readonly TypesContainerInterface $typesContainer, private readonly FieldsBuilderEnumInterface $fieldsBuilder)
36
    {
UNCOV
37
    }
×
38

39
    public function getSchema(): Schema
40
    {
UNCOV
41
        $types = $this->typesFactory->getTypes();
×
UNCOV
42
        foreach ($types as $typeId => $type) {
×
UNCOV
43
            $this->typesContainer->set($typeId, $type);
×
44
        }
45

UNCOV
46
        $queryFields = ['node' => $this->fieldsBuilder->getNodeQueryFields()];
×
UNCOV
47
        $mutationFields = [];
×
UNCOV
48
        $subscriptionFields = [];
×
49

UNCOV
50
        foreach ($this->resourceNameCollectionFactory->create() as $resourceClass) {
×
UNCOV
51
            $resourceMetadataCollection = $this->resourceMetadataCollectionFactory->create($resourceClass);
×
UNCOV
52
            foreach ($resourceMetadataCollection as $resourceMetadata) {
×
UNCOV
53
                foreach ($resourceMetadata->getGraphQlOperations() ?? [] as $operation) {
×
UNCOV
54
                    $configuration = null !== $operation->getArgs() ? ['args' => $operation->getArgs()] : [];
×
55

UNCOV
56
                    if ($operation instanceof Query && $operation instanceof CollectionOperationInterface) {
×
UNCOV
57
                        $queryFields += $this->fieldsBuilder->getCollectionQueryFields($resourceClass, $operation, $configuration);
×
58

UNCOV
59
                        continue;
×
60
                    }
61

UNCOV
62
                    if ($operation instanceof Query) {
×
UNCOV
63
                        $queryFields += $this->fieldsBuilder->getItemQueryFields($resourceClass, $operation, $configuration);
×
64

UNCOV
65
                        continue;
×
66
                    }
67

UNCOV
68
                    if ($operation instanceof Subscription && $operation->getMercure()) {
×
69
                        $subscriptionFields += $this->fieldsBuilder->getSubscriptionFields($resourceClass, $operation);
×
70

71
                        continue;
×
72
                    }
73

UNCOV
74
                    $mutationFields += $this->fieldsBuilder->getMutationFields($resourceClass, $operation);
×
75
                }
76
            }
77
        }
78

UNCOV
79
        $queryType = new ObjectType([
×
UNCOV
80
            'name' => 'Query',
×
UNCOV
81
            'fields' => $queryFields,
×
UNCOV
82
        ]);
×
UNCOV
83
        $this->typesContainer->set('Query', $queryType);
×
84

UNCOV
85
        $schema = [
×
UNCOV
86
            'query' => $queryType,
×
UNCOV
87
            'typeLoader' => function (string $typeName): ?NamedType {
×
88
                try {
UNCOV
89
                    $type = $this->typesContainer->get($typeName);
×
90
                } catch (TypeNotFoundException) {
×
91
                    return null;
×
92
                }
93

UNCOV
94
                return Type::getNamedType($type);
×
UNCOV
95
            },
×
UNCOV
96
        ];
×
97

UNCOV
98
        if ($mutationFields) {
×
UNCOV
99
            $mutationType = new ObjectType([
×
UNCOV
100
                'name' => 'Mutation',
×
UNCOV
101
                'fields' => $mutationFields,
×
UNCOV
102
            ]);
×
UNCOV
103
            $this->typesContainer->set('Mutation', $mutationType);
×
104

UNCOV
105
            $schema['mutation'] = $mutationType;
×
106
        }
107

UNCOV
108
        if ($subscriptionFields) {
×
109
            $subscriptionType = new ObjectType([
×
110
                'name' => 'Subscription',
×
111
                'fields' => $subscriptionFields,
×
112
            ]);
×
113
            $this->typesContainer->set('Subscription', $subscriptionType);
×
114

115
            $schema['subscription'] = $subscriptionType;
×
116
        }
117

UNCOV
118
        return new Schema($schema);
×
119
    }
120
}
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

© 2025 Coveralls, Inc