Skip to content

Commit cf1a13b

Browse files
committed
Updated graphqlite to 5th version
1 parent 5b4787a commit cf1a13b

File tree

7 files changed

+111
-101
lines changed

7 files changed

+111
-101
lines changed

Command/DumpSchemaCommand.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace TheCodingMachine\Graphqlite\Bundle\Command;
66

7-
use GraphQL\Type\Definition\ObjectType;
7+
use GraphQL\Type\Definition\TypeWithFields;
88
use GraphQL\Utils\SchemaPrinter;
99
use Symfony\Component\Console\Command\Command;
1010
use Symfony\Component\Console\Input\InputInterface;
@@ -63,7 +63,7 @@ private function sortSchema(): void
6363
{
6464
$config = $this->schema->getConfig();
6565

66-
$refl = new \ReflectionProperty(ObjectType::class, 'fields');
66+
$refl = new \ReflectionProperty(TypeWithFields::class, 'fields');
6767
$refl->setAccessible(true);
6868

6969
$fields = $config->query->getFields();

Controller/GraphqliteController.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
use Symfony\Bridge\PsrHttpMessage\Factory\PsrHttpFactory;
1212
use TheCodingMachine\GraphQLite\Http\HttpCodeDecider;
1313
use function array_map;
14-
use GraphQL\Error\Debug;
1514
use GraphQL\Executor\ExecutionResult;
16-
use GraphQL\Executor\Promise\Promise;
1715
use GraphQL\Server\ServerConfig;
1816
use GraphQL\Server\StandardServer;
1917
use GraphQL\Upload\UploadMiddleware;
@@ -38,7 +36,7 @@ class GraphqliteController
3836
* @var HttpMessageFactoryInterface
3937
*/
4038
private $httpMessageFactory;
41-
/** @var bool|int */
39+
/** @var int */
4240
private $debug;
4341
/**
4442
* @var ServerConfig
@@ -49,7 +47,7 @@ public function __construct(ServerConfig $serverConfig, HttpMessageFactoryInterf
4947
{
5048
$this->serverConfig = $serverConfig;
5149
$this->httpMessageFactory = $httpMessageFactory ?: new PsrHttpFactory(new ServerRequestFactory(), new StreamFactory(), new UploadedFileFactory(), new ResponseFactory());
52-
$this->debug = $debug ?? $serverConfig->getDebug();
50+
$this->debug = $debug ?? $serverConfig->getDebugFlag();
5351
}
5452

5553
public function loadRoutes(): RouteCollection

DependencyInjection/GraphqliteExtension.php

+7-13
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,16 @@
44
namespace TheCodingMachine\Graphqlite\Bundle\DependencyInjection;
55

66

7+
use GraphQL\Error\DebugFlag;
78
use TheCodingMachine\GraphQLite\Mappers\Root\RootTypeMapperFactoryInterface;
89
use function array_map;
9-
use GraphQL\Error\Debug;
1010
use GraphQL\Server\ServerConfig;
1111
use GraphQL\Type\Definition\ObjectType;
12-
use function implode;
13-
use function is_dir;
14-
use Mouf\Composer\ClassNameMapper;
1512
use function rtrim;
1613
use Symfony\Component\Config\FileLocator;
1714
use Symfony\Component\DependencyInjection\ContainerBuilder;
18-
use Symfony\Component\DependencyInjection\Definition;
1915
use Symfony\Component\DependencyInjection\Extension\Extension;
2016
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
21-
use TheCodingMachine\GraphQLite\GraphQLRuntimeException as GraphQLException;
22-
use function var_dump;
2317

2418
class GraphqliteExtension extends Extension
2519
{
@@ -84,9 +78,9 @@ function($namespace): string {
8478
if (isset($config['debug'])) {
8579
$debugCode = $this->toDebugCode($config['debug']);
8680
} else {
87-
$debugCode = Debug::RETHROW_UNSAFE_EXCEPTIONS;
81+
$debugCode = DebugFlag::RETHROW_UNSAFE_EXCEPTIONS;
8882
}
89-
$definition->addMethodCall('setDebug', [$debugCode]);
83+
$definition->addMethodCall('setDebugFlag', [$debugCode]);
9084

9185
$container->registerForAutoconfiguration(ObjectType::class)
9286
->addTag('graphql.output_type');
@@ -101,10 +95,10 @@ function($namespace): string {
10195
private function toDebugCode(array $debug): int
10296
{
10397
$code = 0;
104-
$code |= ($debug['INCLUDE_DEBUG_MESSAGE'] ?? 0)*Debug::INCLUDE_DEBUG_MESSAGE;
105-
$code |= ($debug['INCLUDE_TRACE'] ?? 0)*Debug::INCLUDE_TRACE;
106-
$code |= ($debug['RETHROW_INTERNAL_EXCEPTIONS'] ?? 0)*Debug::RETHROW_INTERNAL_EXCEPTIONS;
107-
$code |= ($debug['RETHROW_UNSAFE_EXCEPTIONS'] ?? 0)*Debug::RETHROW_UNSAFE_EXCEPTIONS;
98+
$code |= ($debug['INCLUDE_DEBUG_MESSAGE'] ?? 0)*DebugFlag::INCLUDE_DEBUG_MESSAGE;
99+
$code |= ($debug['INCLUDE_TRACE'] ?? 0)*DebugFlag::INCLUDE_TRACE;
100+
$code |= ($debug['RETHROW_INTERNAL_EXCEPTIONS'] ?? 0)*DebugFlag::RETHROW_INTERNAL_EXCEPTIONS;
101+
$code |= ($debug['RETHROW_UNSAFE_EXCEPTIONS'] ?? 0)*DebugFlag::RETHROW_UNSAFE_EXCEPTIONS;
108102
return $code;
109103
}
110104
}

Resources/config/container/graphqlite.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
<tag name="graphql.parameter_middleware"/>
9393
</service>
9494

95-
<service id="TheCodingMachine\Graphqlite\Validator\Mappers\Parameters\AssertParameterMiddleware">
95+
<service id="TheCodingMachine\GraphQLite\Validator\Mappers\Parameters\AssertParameterMiddleware">
9696
<argument type="service" id="validator.validator_factory" />
9797
<tag name="graphql.parameter_middleware"/>
9898
</service>

Tests/Fixtures/Controller/TestGraphqlController.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
namespace TheCodingMachine\Graphqlite\Bundle\Tests\Fixtures\Controller;
55

66

7-
use GraphQL\Error\Error;
87
use Porpaginas\Arrays\ArrayResult;
98
use Symfony\Component\HttpFoundation\Request;
109
use Symfony\Component\Validator\Constraints as Assert;
@@ -17,8 +16,7 @@
1716
use TheCodingMachine\GraphQLite\Annotations\Query;
1817
use TheCodingMachine\GraphQLite\Exceptions\GraphQLAggregateException;
1918
use TheCodingMachine\GraphQLite\Exceptions\GraphQLException;
20-
use TheCodingMachine\Graphqlite\Validator\Annotations\Assertion;
21-
use TheCodingMachine\Graphqlite\Validator\Fixtures\Types\User;
19+
use TheCodingMachine\GraphQLite\Validator\Annotations\Assertion;
2220

2321
class TestGraphqlController
2422
{

Tests/FunctionalTest.php

+95-75
Original file line numberDiff line numberDiff line change
@@ -242,13 +242,16 @@ public function testLoginQuery(): void
242242
$container = $kernel->getContainer();
243243
$container->set('session', $session);
244244

245-
$request = Request::create('/graphql', 'POST', ['query' => '
246-
mutation login {
247-
login(userName: "foo", password: "bar") {
248-
userName
249-
roles
250-
}
251-
}']);
245+
$parameters = ['query' => '
246+
mutation login {
247+
login(userName: "foo", password: "bar") {
248+
userName
249+
roles
250+
}
251+
}
252+
'];
253+
254+
$request = Request::create('/graphql', 'POST', $parameters, [], [], ['CONTENT_TYPE' => 'application/json']);
252255

253256
$response = $kernel->handle($request);
254257

@@ -275,14 +278,16 @@ public function testMeQuery(): void
275278
$container = $kernel->getContainer();
276279
$container->set('session', $session);
277280

278-
$request = Request::create('/graphql', 'POST', ['query' => '
279-
{
280-
me {
281-
userName
282-
roles
283-
}
284-
}
285-
']);
281+
$parameters = ['query' => '
282+
{
283+
me {
284+
userName
285+
roles
286+
}
287+
}
288+
'];
289+
290+
$request = Request::create('/graphql', 'POST', $parameters, [], [], ['CONTENT_TYPE' => 'application/json']);
286291

287292
$response = $kernel->handle($request);
288293

@@ -301,12 +306,15 @@ public function testNoLoginNoSessionQuery(): void
301306
$kernel = new GraphqliteTestingKernel(false, 'off');
302307
$kernel->boot();
303308

304-
$request = Request::create('/graphql', 'POST', ['query' => '
305-
mutation login {
306-
login(userName: "foo", password: "bar") {
307-
userName
308-
}
309-
}']);
309+
$parameters = ['query' => '
310+
mutation login {
311+
login(userName: "foo", password: "bar") {
312+
userName
313+
}
314+
}
315+
'];
316+
317+
$request = Request::create('/graphql', 'POST', $parameters, [], [], ['CONTENT_TYPE' => 'application/json']);
310318

311319
$response = $kernel->handle($request);
312320

@@ -381,14 +389,16 @@ public function testAllOff(): void
381389
$container = $kernel->getContainer();
382390
$container->set('session', $session);
383391

384-
$request = Request::create('/graphql', 'POST', ['query' => '
385-
{
386-
me {
387-
userName
388-
roles
389-
}
390-
}
391-
']);
392+
$parameters = ['query' => '
393+
{
394+
me {
395+
userName
396+
roles
397+
}
398+
}
399+
'];
400+
401+
$request = Request::create('/graphql', 'POST', $parameters, [], [], ['CONTENT_TYPE' => 'application/json']);
392402

393403
$response = $kernel->handle($request);
394404

@@ -406,11 +416,13 @@ public function testValidation(): void
406416
$container = $kernel->getContainer();
407417
$container->set('session', $session);
408418

409-
$request = Request::create('/graphql', 'POST', ['query' => '
410-
{
411-
findByMail(email: "notvalid")
412-
}
413-
']);
419+
$parameters = ['query' => '
420+
{
421+
findByMail(email: "notvalid")
422+
}
423+
'];
424+
425+
$request = Request::create('/graphql', 'POST', $parameters, [], [], ['CONTENT_TYPE' => 'application/json']);
414426

415427
$response = $kernel->handle($request);
416428

@@ -427,15 +439,17 @@ public function testWithIntrospection(): void
427439
$kernel = new GraphqliteTestingKernel(true, null, true, null);
428440
$kernel->boot();
429441

430-
$request = Request::create('/graphql', 'POST', ['query' => '
431-
{
432-
__schema {
433-
queryType {
434-
name
442+
$parameters = ['query' => '
443+
{
444+
__schema {
445+
queryType {
446+
name
447+
}
448+
}
435449
}
436-
}
437-
}
438-
']);
450+
'];
451+
452+
$request = Request::create('/graphql', 'POST', $parameters, [], [], ['CONTENT_TYPE' => 'application/json']);
439453

440454
$response = $kernel->handle($request);
441455

@@ -450,15 +464,17 @@ public function testDisableIntrospection(): void
450464
$kernel = new GraphqliteTestingKernel(true, null, true, null, false, 2, 2);
451465
$kernel->boot();
452466

453-
$request = Request::create('/graphql', 'POST', ['query' => '
454-
{
455-
__schema {
456-
queryType {
457-
name
467+
$parameters = ['query' => '
468+
{
469+
__schema {
470+
queryType {
471+
name
472+
}
473+
}
458474
}
459-
}
460-
}
461-
']);
475+
'];
476+
477+
$request = Request::create('/graphql', 'POST', $parameters, [], [], ['CONTENT_TYPE' => 'application/json']);
462478

463479
$response = $kernel->handle($request);
464480

@@ -473,18 +489,20 @@ public function testMaxQueryComplexity(): void
473489
$kernel = new GraphqliteTestingKernel(true, null, true, null, false, 2, null);
474490
$kernel->boot();
475491

476-
$request = Request::create('/graphql', 'POST', ['query' => '
477-
{
478-
products
479-
{
480-
name,
481-
price,
482-
seller {
483-
name
492+
$parameters = ['query' => '
493+
{
494+
products
495+
{
496+
name,
497+
price,
498+
seller {
499+
name
500+
}
501+
}
484502
}
485-
}
486-
}
487-
']);
503+
'];
504+
505+
$request = Request::create('/graphql', 'POST', $parameters, [], [], ['CONTENT_TYPE' => 'application/json']);
488506

489507
$response = $kernel->handle($request);
490508

@@ -499,24 +517,26 @@ public function testMaxQueryDepth(): void
499517
$kernel = new GraphqliteTestingKernel(true, null, true, null, false, null, 1);
500518
$kernel->boot();
501519

502-
$request = Request::create('/graphql', 'POST', ['query' => '
503-
{
504-
products
505-
{
506-
name,
507-
price,
508-
seller {
509-
name
510-
manager {
511-
name
512-
manager {
520+
$parameters = ['query' => '
521+
{
522+
products
523+
{
524+
name,
525+
price,
526+
seller {
513527
name
528+
manager {
529+
name
530+
manager {
531+
name
532+
}
533+
}
514534
}
515535
}
516536
}
517-
}
518-
}
519-
']);
537+
'];
538+
539+
$request = Request::create('/graphql', 'POST', $parameters, [], [], ['CONTENT_TYPE' => 'application/json']);
520540

521541
$response = $kernel->handle($request);
522542

composer.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
"require" : {
1919
"php" : ">=7.2",
2020
"ext-json": "*",
21-
"thecodingmachine/graphqlite" : "^4.1.2",
22-
"thecodingmachine/graphqlite-symfony-validator-bridge" : "^4.1",
21+
"thecodingmachine/graphqlite" : "^5.0",
22+
"thecodingmachine/graphqlite-symfony-validator-bridge" : "^5.0",
2323
"symfony/framework-bundle": "^4.2 || ^5",
2424
"symfony/validator": "^4.2 || ^5",
2525
"symfony/translation": "^4.2 || ^5",
@@ -63,7 +63,7 @@
6363
},
6464
"extra": {
6565
"branch-alias": {
66-
"dev-master": "4.1.x-dev"
66+
"dev-master": "5.0.x-dev"
6767
}
6868
},
6969
"prefer-stable": true

0 commit comments

Comments
 (0)