diff --git a/src/Folklore/GraphQL/Console/InputMakeCommand.php b/src/Folklore/GraphQL/Console/InputMakeCommand.php new file mode 100644 index 00000000..fd0bf5ff --- /dev/null +++ b/src/Folklore/GraphQL/Console/InputMakeCommand.php @@ -0,0 +1,86 @@ +replaceType($stub, $name); + } + + /** + * Replace the namespace for the given stub. + * + * @param string $stub + * @param string $name + * + * @return $this + */ + protected function replaceType($stub, $name) + { + preg_match('/([^\\\]+)$/', $name, $matches); + $stub = str_replace( + 'DummyType', + $matches[1], + $stub + ); + + return $stub; + } +} diff --git a/src/Folklore/GraphQL/Console/stubs/input.stub b/src/Folklore/GraphQL/Console/stubs/input.stub new file mode 100644 index 00000000..50952c33 --- /dev/null +++ b/src/Folklore/GraphQL/Console/stubs/input.stub @@ -0,0 +1,22 @@ + 'DummyType', + 'description' => 'An input' + ]; + + public function fields() + { + return [ + + ]; + } +} diff --git a/src/Folklore/GraphQL/ServiceProvider.php b/src/Folklore/GraphQL/ServiceProvider.php index b4692c29..edb783e8 100644 --- a/src/Folklore/GraphQL/ServiceProvider.php +++ b/src/Folklore/GraphQL/ServiceProvider.php @@ -205,6 +205,7 @@ protected function registerConsole() $this->commands(Console\FieldMakeCommand::class); $this->commands(Console\InterfaceMakeCommand::class); $this->commands(Console\ScalarMakeCommand::class); + $this->commands(Console\InputMakeCommand::class); } /** diff --git a/tests/Console/ExampleInput.php b/tests/Console/ExampleInput.php new file mode 100644 index 00000000..b7cda475 --- /dev/null +++ b/tests/Console/ExampleInput.php @@ -0,0 +1,22 @@ + 'ExampleInput', + 'description' => 'An input' + ]; + + public function fields() + { + return [ + + ]; + } +} diff --git a/tests/Console/InputMakeCommandTest.php b/tests/Console/InputMakeCommandTest.php new file mode 100644 index 00000000..0dec4662 --- /dev/null +++ b/tests/Console/InputMakeCommandTest.php @@ -0,0 +1,25 @@ +artisan('make:graphql:input', [ + 'name' => 'ExampleInput', + ]); + + $this->assertFileExists(app_path('GraphQL/Inputs') . '/ExampleInput.php'); + $this->assertFileEquals(app_path('GraphQL/Inputs') . '/ExampleInput.php', __DIR__ . '/ExampleInput.php'); + } +}