Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
23 changes: 23 additions & 0 deletions src/Console/SchemaConfigMakeCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types = 1);
namespace Rebing\GraphQL\Console;

use Illuminate\Console\GeneratorCommand;

class SchemaConfigMakeCommand extends GeneratorCommand
{
protected $signature = 'make:graphql:schemaConfig {name}';
protected $description = 'Create a new GraphQL schema configuration class';
protected $type = 'Schema';

protected function getStub()
{
return __DIR__ . '/stubs/schemaConfig.stub';
}

protected function getDefaultNamespace($rootNamespace)
{
return $rootNamespace . '\GraphQL\Schemas';
}
}
25 changes: 25 additions & 0 deletions src/Console/stubs/schemaConfig.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace DummyNamespace;

use Rebing\GraphQL\Support\Contracts\ConfigConvertible;

class DummyClass implements ConfigConvertible
{
public function toConfig(): array
{
return [
'query' => [
// ExampleQuery::class,
],

'mutation' => [
// ExampleMutation::class,
],

'types' => [
// ExampleType::class,
],
];
}
}
2 changes: 2 additions & 0 deletions src/GraphQLServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
Expand Down
47 changes: 47 additions & 0 deletions tests/Unit/Console/SchemaConfigMakeCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types = 1);
namespace Rebing\GraphQL\Tests\Unit\Console;

use Rebing\GraphQL\Console\SchemaConfigMakeCommand;
use Rebing\GraphQL\Tests\Support\Traits\MakeCommandAssertionTrait;
use Rebing\GraphQL\Tests\TestCase;

class SchemaConfigMakeCommandTest extends TestCase
{
use MakeCommandAssertionTrait;

/**
* @dataProvider dataForMakeCommand
*/
public function testCommand(
string $inputName,
string $expectedFilename,
string $expectedClassDefinition,
): void {
$this->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',
],
];
}
}