Skip to content

Commit 99b540a

Browse files
PierreRebeilleausoyuka
PierreRebeilleau
authored andcommitted
chore(graphql): api-platform/graphql
1 parent 6644417 commit 99b540a

File tree

58 files changed

+6804
-23
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+6804
-23
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/composer.lock
2+
/vendor
3+
/.phpunit.result.cache

.php-cs-fixer.dist.php

+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
$header = <<<'HEADER'
6+
This file is part of the API Platform project.
7+
8+
(c) Kévin Dunglas <dunglas@gmail.com>
9+
10+
For the full copyright and license information, please view the LICENSE
11+
file that was distributed with this source code.
12+
HEADER;
13+
14+
$finder = PhpCsFixer\Finder::create()
15+
->in(__DIR__)
16+
->exclude([
17+
'src/Core/Bridge/Symfony/Maker/Resources/skeleton',
18+
'tests/Fixtures/app/var',
19+
'tests/Fixtures/Symfony/Maker',
20+
])
21+
->notPath('src/Symfony/Bundle/DependencyInjection/Configuration.php')
22+
->notPath('src/Annotation/ApiFilter.php') // temporary
23+
->notPath('src/Annotation/ApiProperty.php') // temporary
24+
->notPath('src/Annotation/ApiResource.php') // temporary
25+
->notPath('src/Annotation/ApiSubresource.php') // temporary
26+
->notPath('tests/Fixtures/TestBundle/Entity/DummyPhp8.php') // temporary
27+
->notPath('tests/Fixtures/TestBundle/Enum/EnumWithDescriptions.php') // PHPDoc on enum cases
28+
->notPath('tests/Fixtures/TestBundle/Enum/GamePlayMode.php') // PHPDoc on enum cases
29+
->notPath('tests/Fixtures/TestBundle/Enum/GenderTypeEnum.php') // PHPDoc on enum cases
30+
->append([
31+
'tests/Fixtures/app/console',
32+
]);
33+
34+
return (new PhpCsFixer\Config())
35+
->setRiskyAllowed(true)
36+
->setRules([
37+
'@DoctrineAnnotation' => true,
38+
'@PHP71Migration' => true,
39+
'@PHP71Migration:risky' => true,
40+
'@PHPUnit60Migration:risky' => true,
41+
'@Symfony' => true,
42+
'@Symfony:risky' => true,
43+
'align_multiline_comment' => [
44+
'comment_type' => 'phpdocs_like',
45+
],
46+
'array_indentation' => true,
47+
'compact_nullable_typehint' => true,
48+
'doctrine_annotation_array_assignment' => [
49+
'operator' => '=',
50+
],
51+
'doctrine_annotation_spaces' => [
52+
'after_array_assignments_equals' => false,
53+
'before_array_assignments_equals' => false,
54+
],
55+
'explicit_indirect_variable' => true,
56+
'fully_qualified_strict_types' => true,
57+
'header_comment' => [
58+
'header' => $header,
59+
'location' => 'after_open',
60+
],
61+
'logical_operators' => true,
62+
'multiline_comment_opening_closing' => true,
63+
'multiline_whitespace_before_semicolons' => [
64+
'strategy' => 'no_multi_line',
65+
],
66+
'no_alternative_syntax' => true,
67+
'no_extra_blank_lines' => [
68+
'tokens' => [
69+
'break',
70+
'continue',
71+
'curly_brace_block',
72+
'extra',
73+
'parenthesis_brace_block',
74+
'return',
75+
'square_brace_block',
76+
'throw',
77+
'use',
78+
],
79+
],
80+
'no_superfluous_elseif' => true,
81+
'no_superfluous_phpdoc_tags' => [
82+
'allow_mixed' => false,
83+
],
84+
'no_unset_cast' => true,
85+
'no_unset_on_property' => true,
86+
'no_useless_else' => true,
87+
'no_useless_return' => true,
88+
'ordered_imports' => [
89+
'imports_order' => [
90+
'class',
91+
'function',
92+
'const',
93+
],
94+
'sort_algorithm' => 'alpha',
95+
],
96+
'php_unit_method_casing' => [
97+
'case' => 'camel_case',
98+
],
99+
'php_unit_set_up_tear_down_visibility' => true,
100+
'php_unit_test_annotation' => [
101+
'style' => 'prefix',
102+
],
103+
'phpdoc_add_missing_param_annotation' => [
104+
'only_untyped' => true,
105+
],
106+
'phpdoc_no_alias_tag' => true,
107+
'phpdoc_order' => true,
108+
'phpdoc_trim_consecutive_blank_line_separation' => true,
109+
'phpdoc_var_annotation_correct_order' => true,
110+
'return_assignment' => true,
111+
'strict_param' => true,
112+
'visibility_required' => [
113+
'elements' => [
114+
'const',
115+
'method',
116+
'property',
117+
],
118+
],
119+
])
120+
->setFinder($finder);

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT license
2+
3+
Copyright (c) 2015-present Kévin Dunglas
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is furnished
10+
to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# API Platform - GraphQL
2+
3+
Build GraphQL API endpoints

Resolver/Factory/CollectionResolverFactory.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
use ApiPlatform\GraphQl\Resolver\Stage\SecurityStageInterface;
2020
use ApiPlatform\GraphQl\Resolver\Stage\SerializeStageInterface;
2121
use ApiPlatform\Metadata\GraphQl\Operation;
22-
use ApiPlatform\Util\CloneTrait;
22+
use ApiPlatform\Metadata\Util\CloneTrait;
2323
use GraphQL\Type\Definition\ResolveInfo;
2424
use Psr\Container\ContainerInterface;
2525

Resolver/Factory/ItemMutationResolverFactory.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
use ApiPlatform\Metadata\DeleteOperationInterface;
2626
use ApiPlatform\Metadata\GraphQl\Operation;
2727
use ApiPlatform\Metadata\Util\ClassInfoTrait;
28-
use ApiPlatform\Util\CloneTrait;
28+
use ApiPlatform\Metadata\Util\CloneTrait;
2929
use GraphQL\Type\Definition\ResolveInfo;
3030
use Psr\Container\ContainerInterface;
3131

Resolver/Factory/ItemResolverFactory.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
use ApiPlatform\Metadata\GraphQl\Operation;
2222
use ApiPlatform\Metadata\GraphQl\Query;
2323
use ApiPlatform\Metadata\Util\ClassInfoTrait;
24-
use ApiPlatform\Util\CloneTrait;
24+
use ApiPlatform\Metadata\Util\CloneTrait;
2525
use GraphQL\Type\Definition\ResolveInfo;
2626
use Psr\Container\ContainerInterface;
2727

Resolver/Factory/ItemSubscriptionResolverFactory.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
use ApiPlatform\GraphQl\Subscription\SubscriptionManagerInterface;
2121
use ApiPlatform\Metadata\GraphQl\Operation;
2222
use ApiPlatform\Metadata\Util\ClassInfoTrait;
23-
use ApiPlatform\Util\CloneTrait;
23+
use ApiPlatform\Metadata\Util\CloneTrait;
2424
use GraphQL\Type\Definition\ResolveInfo;
2525

2626
/**

Resolver/ResourceFieldResolver.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313

1414
namespace ApiPlatform\GraphQl\Resolver;
1515

16-
use ApiPlatform\Api\IriConverterInterface;
17-
use ApiPlatform\Api\UrlGeneratorInterface;
1816
use ApiPlatform\GraphQl\Serializer\ItemNormalizer;
17+
use ApiPlatform\Metadata\IriConverterInterface;
18+
use ApiPlatform\Metadata\UrlGeneratorInterface;
1919
use ApiPlatform\Metadata\Util\ClassInfoTrait;
2020
use GraphQL\Type\Definition\ResolveInfo;
2121

Resolver/Stage/ReadStage.php

+60-6
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,13 @@
1313

1414
namespace ApiPlatform\GraphQl\Resolver\Stage;
1515

16-
use ApiPlatform\Api\IriConverterInterface;
17-
use ApiPlatform\Exception\ItemNotFoundException;
1816
use ApiPlatform\GraphQl\Resolver\Util\IdentifierTrait;
1917
use ApiPlatform\GraphQl\Serializer\ItemNormalizer;
2018
use ApiPlatform\GraphQl\Serializer\SerializerContextBuilderInterface;
19+
use ApiPlatform\Metadata\Exception\ItemNotFoundException;
2120
use ApiPlatform\Metadata\GraphQl\Operation;
22-
use ApiPlatform\Metadata\Util\ClassInfoTrait;
21+
use ApiPlatform\Metadata\IriConverterInterface;
2322
use ApiPlatform\State\ProviderInterface;
24-
use ApiPlatform\Util\ArrayTrait;
2523
use GraphQL\Type\Definition\ResolveInfo;
2624
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
2725

@@ -32,8 +30,6 @@
3230
*/
3331
final class ReadStage implements ReadStageInterface
3432
{
35-
use ArrayTrait;
36-
use ClassInfoTrait;
3733
use IdentifierTrait;
3834

3935
public function __construct(private readonly IriConverterInterface $iriConverter, private readonly ProviderInterface $provider, private readonly SerializerContextBuilderInterface $serializerContextBuilder, private readonly string $nestingSeparator)
@@ -133,4 +129,62 @@ private function getNormalizedFilters(array $args): array
133129

134130
return $filters;
135131
}
132+
133+
public function isSequentialArrayOfArrays(array $array): bool
134+
{
135+
if (!$this->isSequentialArray($array)) {
136+
return false;
137+
}
138+
139+
return $this->arrayContainsOnly($array, 'array');
140+
}
141+
142+
public function isSequentialArray(array $array): bool
143+
{
144+
if ([] === $array) {
145+
return false;
146+
}
147+
148+
return array_is_list($array);
149+
}
150+
151+
public function arrayContainsOnly(array $array, string $type): bool
152+
{
153+
return $array === array_filter($array, static fn ($item): bool => $type === \gettype($item));
154+
}
155+
156+
/**
157+
* Get class name of the given object.
158+
*/
159+
private function getObjectClass(object $object): string
160+
{
161+
return $this->getRealClassName($object::class);
162+
}
163+
164+
/**
165+
* Get the real class name of a class name that could be a proxy.
166+
*/
167+
private function getRealClassName(string $className): string
168+
{
169+
// __CG__: Doctrine Common Marker for Proxy (ODM < 2.0 and ORM < 3.0)
170+
// __PM__: Ocramius Proxy Manager (ODM >= 2.0)
171+
$positionCg = strrpos($className, '\\__CG__\\');
172+
$positionPm = strrpos($className, '\\__PM__\\');
173+
174+
if (false === $positionCg && false === $positionPm) {
175+
return $className;
176+
}
177+
178+
if (false !== $positionCg) {
179+
return substr($className, $positionCg + 8);
180+
}
181+
182+
$className = ltrim($className, '\\');
183+
184+
return substr(
185+
$className,
186+
8 + $positionPm,
187+
strrpos($className, '\\') - ($positionPm + 8)
188+
);
189+
}
136190
}

Serializer/ItemNormalizer.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
namespace ApiPlatform\GraphQl\Serializer;
1515

1616
use ApiPlatform\Api\IdentifiersExtractorInterface;
17-
use ApiPlatform\Api\IriConverterInterface;
18-
use ApiPlatform\Api\ResourceClassResolverInterface;
1917
use ApiPlatform\Metadata\ApiProperty;
18+
use ApiPlatform\Metadata\IriConverterInterface;
2019
use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
2120
use ApiPlatform\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface;
2221
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
22+
use ApiPlatform\Metadata\ResourceClassResolverInterface;
2323
use ApiPlatform\Metadata\Util\ClassInfoTrait;
2424
use ApiPlatform\Serializer\ItemNormalizer as BaseItemNormalizer;
2525
use ApiPlatform\Symfony\Security\ResourceAccessCheckerInterface;

Serializer/ObjectNormalizer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
namespace ApiPlatform\GraphQl\Serializer;
1515

1616
use ApiPlatform\Api\IdentifiersExtractorInterface;
17-
use ApiPlatform\Api\IriConverterInterface;
17+
use ApiPlatform\Metadata\IriConverterInterface;
1818
use ApiPlatform\Metadata\Util\ClassInfoTrait;
1919
use ApiPlatform\Serializer\CacheableSupportsMethodInterface;
2020
use Symfony\Component\Serializer\Exception\UnexpectedValueException;

Subscription/SubscriptionManager.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313

1414
namespace ApiPlatform\GraphQl\Subscription;
1515

16-
use ApiPlatform\Api\IriConverterInterface;
1716
use ApiPlatform\GraphQl\Resolver\Stage\SerializeStageInterface;
1817
use ApiPlatform\GraphQl\Resolver\Util\IdentifierTrait;
1918
use ApiPlatform\Metadata\GraphQl\Operation;
2019
use ApiPlatform\Metadata\GraphQl\Subscription;
20+
use ApiPlatform\Metadata\IriConverterInterface;
2121
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
2222
use ApiPlatform\Metadata\Util\ResourceClassInfoTrait;
23-
use ApiPlatform\Util\SortTrait;
23+
use ApiPlatform\Metadata\Util\SortTrait;
2424
use GraphQL\Type\Definition\ResolveInfo;
2525
use Psr\Cache\CacheItemPoolInterface;
2626

0 commit comments

Comments
 (0)