Skip to content

Commit e84ac64

Browse files
committed
Overriding SchemaPrinter to bypass check on Subscriptions.
In Webonyx, the getType() function can return null. In GraphQLite, it throws an error. This makes using the SchemaPrinter impossible. We override the SchemaPrinter to stop searching for the "Subscription" type. Note: this can only work if webonyx/graphql-php#1380 is merged.
1 parent 2057763 commit e84ac64

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

src/Console/Commands/GraphqliteExportSchema.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace TheCodingMachine\GraphQLite\Laravel\Console\Commands;
44

5-
use GraphQL\Utils\SchemaPrinter;
65
use Illuminate\Console\Command;
6+
use TheCodingMachine\GraphQLite\Laravel\Utils\SchemaPrinter;
77
use TheCodingMachine\GraphQLite\Schema;
88

99
/**

src/Providers/GraphQLiteServiceProvider.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,6 @@ public function register()
153153

154154
$service->addTypeMapperFactory($app[PaginatorTypeMapperFactory::class]);
155155

156-
// We need to configure an empty Subscription type to avoid an exception in the generate-schema command.
157-
$config = SchemaConfig::create();
158-
$config->setSubscription(new ObjectType([
159-
'name' => 'Subscription',
160-
'fields' => [],
161-
]));
162-
$service->setSchemaConfig($config);
163-
164156
$controllers = config('graphqlite.controllers', 'App\\Http\\Controllers');
165157
if (!is_iterable($controllers)) {
166158
$controllers = [ $controllers ];

src/Utils/SchemaPrinter.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace TheCodingMachine\GraphQLite\Laravel\Utils;
4+
5+
use GraphQL\Type\Schema;
6+
7+
class SchemaPrinter extends \GraphQL\Utils\SchemaPrinter
8+
{
9+
/**
10+
* In GraphQLite, getType throws an exception if not found. The "Subscription" type is never present.
11+
* So it throws always. We reimplement this method to avoid throwing.
12+
*/
13+
protected static function hasDefaultRootOperationTypes(Schema $schema): bool
14+
{
15+
return $schema->getQueryType() && $schema->getQueryType() === $schema->getType('Query')
16+
&& $schema->getMutationType() && $schema->getMutationType() === $schema->getType('Mutation');
17+
}
18+
}

0 commit comments

Comments
 (0)