-
-
Notifications
You must be signed in to change notification settings - Fork 270
Add command for schema class generation #830
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f64d442
create new command for schema creation
matsn0w 82104c9
add unit test for new command
matsn0w 7cab112
update readme
matsn0w c15e92a
update changelog
matsn0w e3e905e
remove unnecessary method
matsn0w 545274f
rename command to 'schemaConfig'
matsn0w cfc1e71
update unit test
matsn0w 230ae17
update command name
matsn0w File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
], | ||
]; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
], | ||
]; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.