Skip to content

Commit ecf9fc0

Browse files
committed
Merge branch '6.0' of github.com:thecodingmachine/graphqlite-bundle into 6.0
2 parents 1b05b88 + 6ddc70d commit ecf9fc0

File tree

13 files changed

+39
-54
lines changed

13 files changed

+39
-54
lines changed

Command/DumpSchemaCommand.php

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
namespace TheCodingMachine\GraphQLite\Bundle\Command;
66

7-
use GraphQL\Type\Definition\TypeWithFields;
7+
use GraphQL\Type\Schema as TypeSchema;
88
use GraphQL\Utils\SchemaPrinter;
9+
use Symfony\Component\Console\Attribute\AsCommand;
910
use Symfony\Component\Console\Command\Command;
1011
use Symfony\Component\Console\Input\InputInterface;
1112
use Symfony\Component\Console\Input\InputOption;
@@ -16,10 +17,9 @@
1617
/**
1718
* Shamelessly stolen from Api Platform
1819
*/
20+
#[AsCommand('graphqlite:dump-schema')]
1921
class DumpSchemaCommand extends Command
2022
{
21-
protected static $defaultName = 'graphqlite:dump-schema';
22-
2323
/**
2424
* @var Schema
2525
*/
@@ -43,10 +43,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4343
{
4444
$io = new SymfonyStyle($input, $output);
4545

46-
// Trying to guarantee deterministic order
47-
$this->sortSchema();
48-
49-
$schemaExport = SchemaPrinter::doPrint($this->schema);
46+
$schemaExport = SchemaPrinterForGraphQLite::doPrint($this->schema, ['sortTypes' => true]);
5047

5148
$filename = $input->getOption('output');
5249
if (\is_string($filename)) {
@@ -58,24 +55,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5855

5956
return 0;
6057
}
58+
}
6159

62-
private function sortSchema(): void
63-
{
64-
$config = $this->schema->getConfig();
65-
66-
$refl = new \ReflectionProperty(TypeWithFields::class, 'fields');
67-
$refl->setAccessible(true);
68-
69-
if ($config->query) {
70-
$fields = $config->query->getFields();
71-
ksort($fields);
72-
$refl->setValue($config->query, $fields);
73-
}
60+
class SchemaPrinterForGraphQLite extends SchemaPrinter {
7461

75-
if ($config->mutation) {
76-
$fields = $config->mutation->getFields();
77-
ksort($fields);
78-
$refl->setValue($config->mutation, $fields);
79-
}
62+
protected static function hasDefaultRootOperationTypes(TypeSchema $schema): bool
63+
{
64+
return $schema->getQueryType() === $schema->getType('Query')
65+
&& $schema->getMutationType() === $schema->getType('Mutation')
66+
// Commenting this out because graphqlite cannot map Subscription type
67+
// && $schema->getSubscriptionType() === $schema->getType('Subscription');
68+
;
8069
}
81-
}
70+
}

Controller/GraphQLiteController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function handleRequest(Request $request): Response
7979
throw new \RuntimeException('Invalid JSON received in POST body: '.json_last_error_msg());
8080
}
8181
if (!is_array($parsedBody)){
82-
throw new \RuntimeException('Expecting associative array from request, got ' . gettype($content));
82+
throw new \RuntimeException('Expecting associative array from request, got ' . gettype($parsedBody));
8383
}
8484
$psr7Request = $psr7Request->withParsedBody($parsedBody);
8585
}

DependencyInjection/Configuration.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
class Configuration implements ConfigurationInterface
1010
{
11+
/**
12+
* @return TreeBuilder
13+
*/
1114
public function getConfigTreeBuilder()
1215
{
1316
$treeBuilder = new TreeBuilder('graphqlite');

DependencyInjection/GraphQLiteCompilerPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public function process(ContainerBuilder $container): void
162162
// ServerConfig rules
163163
$serverConfigDefinition = $container->findDefinition(ServerConfig::class);
164164
$rulesDefinition = [];
165-
if ($container->getParameter('graphqlite.security.introspection') === false) {
165+
if ($container->getParameter('graphqlite.security.disableIntrospection')) {
166166
$rulesDefinition[] = $container->findDefinition(DisableIntrospection::class);
167167
}
168168

DependencyInjection/GraphQLiteExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function($namespace): string {
7272
$container->setParameter('graphqlite.namespace.types', $namespaceType);
7373
$container->setParameter('graphqlite.security.enable_login', $enableLogin);
7474
$container->setParameter('graphqlite.security.enable_me', $enableMe);
75-
$container->setParameter('graphqlite.security.introspection', $config['security']['introspection'] ?? true);
75+
$container->setParameter('graphqlite.security.disableIntrospection', !($config['security']['introspection'] ?? true));
7676
$container->setParameter('graphqlite.security.maximum_query_complexity', $config['security']['maximum_query_complexity'] ?? null);
7777
$container->setParameter('graphqlite.security.maximum_query_depth', $config['security']['maximum_query_depth'] ?? null);
7878
$container->setParameter('graphqlite.security.firewall_name', $config['security']['firewall_name'] ?? 'main');

GraphiQL/EndpointResolver.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ public function __construct(RequestStack $requestStack)
1919
$this->requestStack = $requestStack;
2020
}
2121

22+
/**
23+
* @return string
24+
*/
2225
public function getBySchema($name)
2326
{
2427
if ('default' === $name) {
@@ -31,6 +34,9 @@ public function getBySchema($name)
3134
throw GraphQLEndpointInvalidSchemaException::forSchemaAndResolver($name, self::class);
3235
}
3336

37+
/**
38+
* @return string
39+
*/
3440
public function getDefault()
3541
{
3642
return $this->getBySchema('default');

Mappers/RequestParameter.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@ class RequestParameter implements ParameterInterface
1515
/**
1616
* @param array<string, mixed> $args
1717
* @param mixed $context
18-
*
19-
* @return mixed
2018
*/
21-
public function resolve(?object $source, array $args, $context, ResolveInfo $info)
19+
public function resolve(?object $source, array $args, $context, ResolveInfo $info): mixed
2220
{
2321
if (!$context instanceof SymfonyRequestContextInterface) {
2422
throw new GraphQLException('Cannot type-hint on a Symfony Request object in your query/mutation/field. The request context must implement SymfonyRequestContextInterface.');

Resources/config/container/graphqlite.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@
7474
</call>
7575
</service>
7676

77-
<service id="GraphQL\Validator\Rules\DisableIntrospection" />
77+
<service id="GraphQL\Validator\Rules\DisableIntrospection">
78+
<argument key="$enabled">%graphqlite.security.disableIntrospection%</argument>
79+
</service>
7880

7981
<service id="GraphQL\Validator\Rules\QueryComplexity" />
8082

Server/ServerConfig.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@ class ServerConfig extends \GraphQL\Server\ServerConfig
2020
*
2121
* @param ValidationRule[]|callable $validationRules
2222
*
23-
* @return \GraphQL\Server\ServerConfig
24-
*
2523
* @api
2624
*/
27-
public function setValidationRules($validationRules)
25+
public function setValidationRules($validationRules): \GraphQL\Server\ServerConfig
2826
{
2927
parent::setValidationRules(
3028
function (OperationParams $params, DocumentNode $doc, string $operationType) use ($validationRules): array {

Tests/Fixtures/Controller/MyException.php

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,23 @@
44
namespace TheCodingMachine\GraphQLite\Bundle\Tests\Fixtures\Controller;
55

66

7-
use GraphQL\Error\ClientAware;
7+
use TheCodingMachine\GraphQLite\Exceptions\GraphQLExceptionInterface;
88

9-
class MyException extends \Exception implements ClientAware
9+
class MyException extends \Exception implements GraphQLExceptionInterface
1010
{
1111

1212
/**
1313
* Returns true when exception message is safe to be displayed to a client.
1414
*
15-
* @return bool
16-
*
1715
* @api
1816
*/
19-
public function isClientSafe()
17+
public function isClientSafe(): bool
2018
{
2119
return true;
2220
}
2321

24-
/**
25-
* Returns string describing a category of the error.
26-
*
27-
* Value "graphql" is reserved for errors produced by query parsing or validation, do not use it.
28-
*
29-
* @return string
30-
*
31-
* @api
32-
*/
33-
public function getCategory()
22+
public function getExtensions(): array
3423
{
35-
return 'foobar';
24+
return ['category' => 'foobar'];
3625
}
3726
}

Tests/Fixtures/Controller/TestGraphqlController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function triggerException(int $code = 0): string
8181
public function triggerAggregateException(): string
8282
{
8383
$exception1 = new GraphQLException('foo', 401);
84-
$exception2 = new GraphQLException('bar', 404, null, 'MyCat', ['field' => 'baz']);
84+
$exception2 = new GraphQLException('bar', 404, null, 'MyCat', ['field' => 'baz', 'category' => 'MyCat']);
8585
throw new GraphQLAggregateException([$exception1, $exception2]);
8686
}
8787

Tests/FunctionalTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ public function testWithIntrospection(): void
457457

458458
public function testDisableIntrospection(): void
459459
{
460-
$kernel = new GraphQLiteTestingKernel(true, null, true, null, false, 2, 2);
460+
$kernel = new GraphQLiteTestingKernel(true, null, true, null, false, 3, 2);
461461
$kernel->boot();
462462

463463
$parameters = ['query' => '

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"require-dev": {
3535
"symfony/security-bundle": "^6",
3636
"symfony/yaml": "^6",
37-
"beberlei/porpaginas": "^1.2",
37+
"beberlei/porpaginas": "^1.2 || ^2.0",
3838
"php-coveralls/php-coveralls": "^2.1.0",
3939
"symfony/phpunit-bridge": "^6",
4040
"phpstan/phpstan": "^1.8",

0 commit comments

Comments
 (0)