From dca0a1d5c009333a6c864c309015115176c1ef0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Tue, 9 May 2023 12:00:32 +0200 Subject: [PATCH] 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 https://github.com/webonyx/graphql-php/pull/1380 is merged. --- .../Commands/GraphqliteExportSchema.php | 2 +- src/Providers/GraphQLiteServiceProvider.php | 8 -------- src/Utils/SchemaPrinter.php | 18 ++++++++++++++++++ 3 files changed, 19 insertions(+), 9 deletions(-) create mode 100644 src/Utils/SchemaPrinter.php diff --git a/src/Console/Commands/GraphqliteExportSchema.php b/src/Console/Commands/GraphqliteExportSchema.php index 13ae9a5..aa72f54 100644 --- a/src/Console/Commands/GraphqliteExportSchema.php +++ b/src/Console/Commands/GraphqliteExportSchema.php @@ -2,8 +2,8 @@ namespace TheCodingMachine\GraphQLite\Laravel\Console\Commands; -use GraphQL\Utils\SchemaPrinter; use Illuminate\Console\Command; +use TheCodingMachine\GraphQLite\Laravel\Utils\SchemaPrinter; use TheCodingMachine\GraphQLite\Schema; /** diff --git a/src/Providers/GraphQLiteServiceProvider.php b/src/Providers/GraphQLiteServiceProvider.php index f92f5d9..d5fbe2c 100644 --- a/src/Providers/GraphQLiteServiceProvider.php +++ b/src/Providers/GraphQLiteServiceProvider.php @@ -153,14 +153,6 @@ public function register() $service->addTypeMapperFactory($app[PaginatorTypeMapperFactory::class]); - // We need to configure an empty Subscription type to avoid an exception in the generate-schema command. - $config = SchemaConfig::create(); - $config->setSubscription(new ObjectType([ - 'name' => 'Subscription', - 'fields' => [], - ])); - $service->setSchemaConfig($config); - $controllers = config('graphqlite.controllers', 'App\\Http\\Controllers'); if (!is_iterable($controllers)) { $controllers = [ $controllers ]; diff --git a/src/Utils/SchemaPrinter.php b/src/Utils/SchemaPrinter.php new file mode 100644 index 0000000..a470849 --- /dev/null +++ b/src/Utils/SchemaPrinter.php @@ -0,0 +1,18 @@ +getQueryType() && $schema->getQueryType() === $schema->getType('Query') + && $schema->getMutationType() && $schema->getMutationType() === $schema->getType('Mutation'); + } +} \ No newline at end of file