Skip to content

Commit 5ffa1d7

Browse files
committed
fix: dump schema cmd
for latest webonyx graphql pkg + Use built in sort types option + Fix for subscription error
1 parent c1bff25 commit 5ffa1d7

File tree

1 file changed

+12
-23
lines changed

1 file changed

+12
-23
lines changed

Command/DumpSchemaCommand.php

Lines changed: 12 additions & 23 deletions
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\TypeWithFields;
7+
use GraphQL\Type\Schema as TypeSchema;
88
use GraphQL\Utils\SchemaPrinter;
99
use Symfony\Component\Console\Attribute\AsCommand;
1010
use Symfony\Component\Console\Command\Command;
@@ -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);
60+
class SchemaPrinterForGraphQLite extends SchemaPrinter {
6861

69-
if ($config->query) {
70-
$fields = $config->query->getFields();
71-
ksort($fields);
72-
$refl->setValue($config->query, $fields);
73-
}
74-
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+
}

0 commit comments

Comments
 (0)