diff --git a/CHANGELOG.md b/CHANGELOG.md index fff1d411..408cead0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -110,6 +110,7 @@ CHANGELOG - `$getSelectFields` closure no longer takes a depth parameter ### Added - Command to make an execution middleware [\#772 / mfn](https://github.com/rebing/graphql-laravel/pull/772) +- Command to make a schema configuration [\#830 / matsn0w](https://github.com/rebing/graphql-laravel/pull/830) - The primary execution of the GraphQL request is now piped through middlewares [\#762 / crissi and mfn](https://github.com/rebing/graphql-laravel/pull/762)\ This allows greater flexibility for enabling/disabling certain functionality as well as bringing in new features without having to open up the library. diff --git a/README.md b/README.md index 6768a83a..3f2dbd09 100644 --- a/README.md +++ b/README.md @@ -341,6 +341,8 @@ class DefaultSchema implements ConfigConvertible } ``` +You can use the `php artisan make:graphql:schemaConfig` command to create a new schema configuration class automatically. + ### Creating a query First you usually create a type you want to return from the query. The Eloquent `'model'` is only required if specifying relations. diff --git a/src/Console/SchemaConfigMakeCommand.php b/src/Console/SchemaConfigMakeCommand.php new file mode 100644 index 00000000..8377ef2a --- /dev/null +++ b/src/Console/SchemaConfigMakeCommand.php @@ -0,0 +1,23 @@ + [ + // ExampleQuery::class, + ], + + 'mutation' => [ + // ExampleMutation::class, + ], + + 'types' => [ + // ExampleType::class, + ], + ]; + } +} diff --git a/src/GraphQLServiceProvider.php b/src/GraphQLServiceProvider.php index 80f42f7b..34f54d1a 100644 --- a/src/GraphQLServiceProvider.php +++ b/src/GraphQLServiceProvider.php @@ -18,6 +18,7 @@ use Rebing\GraphQL\Console\MutationMakeCommand; use Rebing\GraphQL\Console\QueryMakeCommand; use Rebing\GraphQL\Console\ScalarMakeCommand; +use Rebing\GraphQL\Console\SchemaConfigMakeCommand; use Rebing\GraphQL\Console\TypeMakeCommand; use Rebing\GraphQL\Console\UnionMakeCommand; @@ -141,6 +142,7 @@ public function registerConsole(): void $this->commands(MutationMakeCommand::class); $this->commands(QueryMakeCommand::class); $this->commands(ScalarMakeCommand::class); + $this->commands(SchemaConfigMakeCommand::class); $this->commands(TypeMakeCommand::class); $this->commands(UnionMakeCommand::class); } diff --git a/tests/Unit/Console/SchemaConfigMakeCommandTest.php b/tests/Unit/Console/SchemaConfigMakeCommandTest.php new file mode 100644 index 00000000..e9fa6d6f --- /dev/null +++ b/tests/Unit/Console/SchemaConfigMakeCommandTest.php @@ -0,0 +1,47 @@ +assertMakeCommand( + 'Schema', + SchemaConfigMakeCommand::class, + $inputName, + $expectedFilename, + 'App\\\\GraphQL\\\\Schemas', + $expectedClassDefinition, + ); + } + + public function dataForMakeCommand(): array + { + return [ + 'Example' => [ + 'inputName' => 'Example', + 'expectedFilename' => 'GraphQL/Schemas/Example.php', + 'expectedClassDefinition' => 'Example implements ConfigConvertible', + ], + 'ExampleSchema' => [ + 'inputName' => 'ExampleSchema', + 'expectedFilename' => 'GraphQL/Schemas/ExampleSchema.php', + 'expectedClassDefinition' => 'ExampleSchema implements ConfigConvertible', + ], + ]; + } +}