Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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:schema` 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
42 changes: 42 additions & 0 deletions src/Console/SchemaMakeCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

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

use Illuminate\Console\GeneratorCommand;

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

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

protected function getDefaultNamespace($rootNamespace)
{
return $rootNamespace . '\GraphQL\Schemas';
}

protected function buildClass($name)
{
$stub = parent::buildClass($name);

return $this->replaceGraphqlName($stub);
}

protected function replaceGraphqlName(string $stub): string
{
$graphqlName = lcfirst($this->getNameInput());
$graphqlName = preg_replace('/Schema$/', '', $graphqlName);

return str_replace(
'DummyGraphqlName',
$graphqlName,
$stub
);
}
}
25 changes: 25 additions & 0 deletions src/Console/stubs/schema.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\SchemaMakeCommand;
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(SchemaMakeCommand::class);
$this->commands(TypeMakeCommand::class);
$this->commands(UnionMakeCommand::class);
}
Expand Down
47 changes: 47 additions & 0 deletions tests/Unit/Console/SchemaMakeCommandTest.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\SchemaMakeCommand;
use Rebing\GraphQL\Tests\Support\Traits\MakeCommandAssertionTrait;
use Rebing\GraphQL\Tests\TestCase;

class SchemaMakeCommandTest extends TestCase
{
use MakeCommandAssertionTrait;

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