Skip to content

Commit 5705eb0

Browse files
authored
Merge pull request #265 from andrew-demb/symfony-8
✨ Allow Symfony 8
2 parents 70bde9d + f5a70a8 commit 5705eb0

File tree

12 files changed

+180
-154
lines changed

12 files changed

+180
-154
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@
66

77
Symfony bundle for the `thecodingmachine/graphqlite` package.
88

9+
Bundle docs: https://graphqlite.thecodingmachine.io/docs/symfony-bundle
10+
911
See [thecodingmachine/graphqlite](https://github.com/thecodingmachine/graphqlite).

composer.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,22 @@
2020
"ext-json": "*",
2121
"thecodingmachine/graphqlite" : "^8",
2222
"thecodingmachine/graphqlite-symfony-validator-bridge": "^7.1.1",
23-
"symfony/config": "^6.4 || ^7",
24-
"symfony/console": "^6.4 || ^7",
25-
"symfony/framework-bundle": "^6.4 || ^7",
26-
"symfony/validator": "^6.4 || ^7",
27-
"symfony/translation": "^6.4 || ^7",
28-
"symfony/psr-http-message-bridge": "^2.0 || ^7.0",
23+
"symfony/config": "^6.4 || ^7.0 || ^8.0",
24+
"symfony/console": "^6.4 || ^7.0 || ^8.0",
25+
"symfony/framework-bundle": "^6.4 || ^7.0 || ^8.0",
26+
"symfony/validator": "^6.4 || ^7.0 || ^8.0",
27+
"symfony/translation": "^6.4 || ^7.0 || ^8.0",
28+
"symfony/psr-http-message-bridge": "^2.0 || ^7.0 || ^8.0",
2929
"nyholm/psr7": "^1.1",
3030
"laminas/laminas-diactoros": "^2.2.2 || ^3",
3131
"overblog/graphiql-bundle": "^0.2 || ^0.3 || ^1",
3232
"thecodingmachine/cache-utils": "^1"
3333
},
3434
"require-dev": {
35-
"symfony/security-bundle": "^6.4 || ^7",
36-
"symfony/yaml": "^6.4 || ^7",
35+
"symfony/security-bundle": "^6.4 || ^7.0 || ^8.0",
36+
"symfony/yaml": "^6.4 || ^7.0 || ^8.0",
3737
"beberlei/porpaginas": "^1.2 || ^2.0",
38-
"symfony/phpunit-bridge": "^6.4 || ^7",
38+
"symfony/phpunit-bridge": "^6.4 || ^7 || ^8.0",
3939
"phpstan/phpstan": "^2",
4040
"phpstan/phpstan-symfony": "^2.0",
4141
"composer/package-versions-deprecated": "^1.8",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
graphqlite_bundle:
2-
resource: '@GraphQLiteBundle/Resources/config/routes.xml'
2+
resource: '@GraphQLiteBundle/Resources/config/routes.php'

phpstan.neon

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ parameters:
2323
reportUnmatchedIgnoredErrors: false
2424
ignoreErrors:
2525
# Wrong return type hint in Symfony's TreeBuilder
26-
- '#Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\NodeDefinition::\w+\(\).#'
26+
- message: '#Call to method arrayNode\(\) on an unknown class#'
27+
path: src/DependencyInjection/Configuration.php
28+
- message: '#Cannot call method \w+\(\) on mixed#'
29+
path: src/DependencyInjection/Configuration.php
2730
# PhpStan doesn't know bundle resolved config structure and it's pretty complex to describe it
28-
- '#Parameter \#2 \$value of method Symfony\\Component\\DependencyInjection\\Container::setParameter\(\) expects array\|bool\|float\|int\|string\|UnitEnum\|null, mixed given\.#'
31+
- message: '#Parameter \#2 \$value of method Symfony\\Component\\DependencyInjection\\Container::setParameter\(\) expects array\|bool\|float\|int\|string\|UnitEnum\|null, mixed given\.#'
32+
path: src/DependencyInjection/GraphQLiteExtension.php

src/DependencyInjection/Configuration.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88

99
class Configuration implements ConfigurationInterface
1010
{
11+
/** @return TreeBuilder<'array'> */
1112
public function getConfigTreeBuilder(): TreeBuilder
1213
{
14+
/** @var TreeBuilder<'array'> $treeBuilder */
1315
$treeBuilder = new TreeBuilder('graphqlite');
1416
$rootNode = $treeBuilder->getRootNode();
1517

src/DependencyInjection/GraphQLiteExtension.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use Symfony\Component\Config\FileLocator;
1111
use Symfony\Component\DependencyInjection\ContainerBuilder;
1212
use Symfony\Component\DependencyInjection\Extension\Extension;
13-
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
13+
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
1414
use TheCodingMachine\GraphQLite\Mappers\Root\RootTypeMapperFactoryInterface;
1515
use function array_map;
1616
use function rtrim;
@@ -34,7 +34,7 @@ public function load(array $configs, ContainerBuilder $container): void
3434
$configuration = new Configuration();
3535
$config = $this->processConfiguration($configuration, $configs);
3636

37-
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config/container'));
37+
$loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../Resources/config/container'));
3838

3939
if (!isset($config['namespace'])) {
4040
$config['namespace'] = [];
@@ -92,7 +92,7 @@ function($namespace): string {
9292
$container->setParameter('graphqlite.security.maximum_query_depth', $config['security']['maximum_query_depth'] ?? null);
9393
$container->setParameter('graphqlite.security.firewall_name', $config['security']['firewall_name'] ?? 'main');
9494

95-
$loader->load('graphqlite.xml');
95+
$loader->load('graphqlite.php');
9696

9797
$definition = $container->getDefinition(ServerConfig::class);
9898
if (isset($config['debug']) && \is_array($config['debug'])) {
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
<?php
2+
3+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
4+
5+
return static function (ContainerConfigurator $container) {
6+
$services = $container->services();
7+
8+
$services->defaults()
9+
->private()
10+
->autowire()
11+
->autoconfigure();
12+
13+
$services->set(\TheCodingMachine\GraphQLite\SchemaFactory::class)
14+
->args(
15+
[
16+
service('graphqlite.psr16cache'),
17+
service('service_container'),
18+
],
19+
)
20+
->call(
21+
'setAuthenticationService',
22+
[service(\TheCodingMachine\GraphQLite\Security\AuthenticationServiceInterface::class)],
23+
)
24+
->call(
25+
'setAuthorizationService',
26+
[service(\TheCodingMachine\GraphQLite\Security\AuthorizationServiceInterface::class)],
27+
);
28+
29+
$services->set(\TheCodingMachine\GraphQLite\Schema::class)
30+
->public()
31+
->factory([service(\TheCodingMachine\GraphQLite\SchemaFactory::class), 'createSchema']);
32+
33+
$services->set(\TheCodingMachine\GraphQLite\AggregateControllerQueryProviderFactory::class)
34+
->args(
35+
[
36+
[],
37+
service_locator([]),
38+
],
39+
)
40+
->tag('graphql.queryprovider_factory');
41+
42+
$services->alias(\GraphQL\Type\Schema::class, \TheCodingMachine\GraphQLite\Schema::class);
43+
44+
$services->set(\TheCodingMachine\GraphQLite\AnnotationReader::class);
45+
46+
$services->set(\TheCodingMachine\GraphQLite\Bundle\Security\AuthenticationService::class)
47+
->args([service('security.token_storage')->nullOnInvalid()]);
48+
49+
$services->alias(
50+
\TheCodingMachine\GraphQLite\Security\AuthenticationServiceInterface::class,
51+
\TheCodingMachine\GraphQLite\Bundle\Security\AuthenticationService::class,
52+
);
53+
54+
$services->set(\TheCodingMachine\GraphQLite\Bundle\Security\AuthorizationService::class)
55+
->args([service('security.authorization_checker')->nullOnInvalid()]);
56+
57+
$services->alias(
58+
\TheCodingMachine\GraphQLite\Security\AuthorizationServiceInterface::class,
59+
\TheCodingMachine\GraphQLite\Bundle\Security\AuthorizationService::class,
60+
);
61+
62+
$services->set(\GraphQL\Server\ServerConfig::class, \TheCodingMachine\GraphQLite\Bundle\Server\ServerConfig::class)
63+
->call('setSchema', [service(\TheCodingMachine\GraphQLite\Schema::class)])
64+
->call(
65+
'setErrorFormatter',
66+
[
67+
[
68+
\TheCodingMachine\GraphQLite\Exceptions\WebonyxErrorHandler::class,
69+
'errorFormatter',
70+
],
71+
],
72+
)
73+
->call(
74+
'setErrorsHandler',
75+
[
76+
[
77+
\TheCodingMachine\GraphQLite\Exceptions\WebonyxErrorHandler::class,
78+
'errorHandler',
79+
],
80+
],
81+
);
82+
83+
$services->set(\GraphQL\Validator\Rules\DisableIntrospection::class)
84+
->args(['$enabled' => '%graphqlite.security.disableIntrospection%']);
85+
86+
$services->set(\GraphQL\Validator\Rules\QueryComplexity::class);
87+
88+
$services->set(\GraphQL\Validator\Rules\QueryDepth::class);
89+
90+
$services->set(\TheCodingMachine\GraphQLite\Bundle\Controller\GraphQLiteController::class)
91+
->public()
92+
->tag('routing.route_loader');
93+
94+
$services->set(\TheCodingMachine\GraphQLite\Bundle\Mappers\RequestParameterMiddleware::class)
95+
->tag('graphql.parameter_middleware');
96+
97+
$services->set(\TheCodingMachine\GraphQLite\Validator\Mappers\Parameters\AssertParameterMiddleware::class)
98+
->args([service('validator.validator_factory')])
99+
->tag('graphql.parameter_middleware');
100+
101+
$services->set(\TheCodingMachine\GraphQLite\Bundle\Controller\GraphQL\LoginController::class)
102+
->public()
103+
->args(['$firewallName' => '%graphqlite.security.firewall_name%']);
104+
105+
$services->set(\TheCodingMachine\GraphQLite\Bundle\Controller\GraphQL\MeController::class)
106+
->public();
107+
108+
$services->set(\TheCodingMachine\GraphQLite\Bundle\Types\SymfonyUserInterfaceType::class)
109+
->public();
110+
111+
$services->set(\TheCodingMachine\GraphQLite\Mappers\StaticClassListTypeMapperFactory::class)
112+
->args([[]])
113+
->tag('graphql.type_mapper_factory');
114+
115+
$services->set('graphqlite.phpfilescache', \Symfony\Component\Cache\Adapter\PhpFilesAdapter::class)
116+
->args(
117+
[
118+
'graphqlite',
119+
0,
120+
'%kernel.cache_dir%',
121+
],
122+
);
123+
124+
$services->set('graphqlite.apcucache', \Symfony\Component\Cache\Adapter\ApcuAdapter::class)
125+
->args(['graphqlite']);
126+
127+
$services->set('graphqlite.psr16cache', \Symfony\Component\Cache\Psr16Cache::class)
128+
->args([service('graphqlite.cache')]);
129+
130+
$services->set('graphqlite.cacheclearer', \Symfony\Component\HttpKernel\CacheClearer\Psr6CacheClearer::class)
131+
->args([[service('graphqlite.cache')]])
132+
->tag('kernel.cache_clearer');
133+
134+
$services->set(\TheCodingMachine\GraphQLite\Bundle\Command\DumpSchemaCommand::class);
135+
};

src/Resources/config/container/graphqlite.xml

Lines changed: 0 additions & 132 deletions
This file was deleted.

src/Resources/config/routes.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
4+
use TheCodingMachine\GraphQLite\Bundle\Controller\GraphQLiteController;
5+
6+
return function (RoutingConfigurator $routes): void {
7+
$routes->import(
8+
\sprintf('%s::loadRoutes', GraphQLiteController::class),
9+
'service',
10+
);
11+
};

tests/Fixtures/Entities/Contact.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ public function getName(): string
3030
#[Field]
3131
public function injectService(
3232
#[Autowire]
33-
TestGraphqlController $testService = null,
33+
?TestGraphqlController $testService = null,
3434
#[Autowire(identifier: 'someService')]
35-
stdClass $someService = null,
35+
?stdClass $someService = null,
3636
#[Autowire(identifier: 'someAlias')]
37-
stdClass $someAlias = null,
37+
?stdClass $someAlias = null,
3838
): string {
3939
if (!$testService instanceof TestGraphqlController || $someService === null || $someAlias === null) {
4040
return 'KO';
@@ -52,7 +52,7 @@ public function injectServicePrefetch($prefetchData): string
5252
public function prefetchData(
5353
iterable $iterable,
5454
#[Autowire(identifier: 'someOtherService')]
55-
stdClass $someOtherService = null,
55+
?stdClass $someOtherService = null,
5656
) {
5757
if ($someOtherService === null) {
5858
return 'KO';

0 commit comments

Comments
 (0)