4
4
5
5
namespace TheCodingMachine \GraphQLite \Bundle \Command ;
6
6
7
- use GraphQL \Type \Definition \ TypeWithFields ;
7
+ use GraphQL \Type \Schema as TypeSchema ;
8
8
use GraphQL \Utils \SchemaPrinter ;
9
9
use Symfony \Component \Console \Attribute \AsCommand ;
10
10
use Symfony \Component \Console \Command \Command ;
@@ -43,10 +43,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
43
43
{
44
44
$ io = new SymfonyStyle ($ input , $ output );
45
45
46
- // Trying to guarantee deterministic order
47
- $ this ->sortSchema ();
48
-
49
- $ schemaExport = SchemaPrinter::doPrint ($ this ->schema );
46
+ $ schemaExport = SchemaPrinterForGraphQLite::doPrint ($ this ->schema , ['sortTypes ' => true ]);
50
47
51
48
$ filename = $ input ->getOption ('output ' );
52
49
if (\is_string ($ filename )) {
@@ -58,24 +55,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int
58
55
59
56
return 0 ;
60
57
}
58
+ }
61
59
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 {
68
61
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
+ ;
80
69
}
81
- }
70
+ }
0 commit comments