From 45bf573863aa6ee704813ecb92883b49ca6fe054 Mon Sep 17 00:00:00 2001 From: Karl Li Date: Mon, 26 Mar 2018 15:55:44 +0800 Subject: [PATCH 1/3] add InputMakeCommand --- .../GraphQL/Console/InputMakeCommand.php | 86 +++++++++++++++++++ src/Folklore/GraphQL/Console/stubs/input.stub | 22 +++++ 2 files changed, 108 insertions(+) create mode 100644 src/Folklore/GraphQL/Console/InputMakeCommand.php create mode 100644 src/Folklore/GraphQL/Console/stubs/input.stub 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 [ + + ]; + } +} From dae386e4fdddbe2a3211dd180cae30491cd7631a Mon Sep 17 00:00:00 2001 From: Karl Li Date: Mon, 26 Mar 2018 16:00:52 +0800 Subject: [PATCH 2/3] add InputMakeCommand into service provider --- src/Folklore/GraphQL/ServiceProvider.php | 1 + 1 file changed, 1 insertion(+) 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); } /** From 5a4896f2caf11a4d91800824edf886dffea03b5d Mon Sep 17 00:00:00 2001 From: Karl Li Date: Mon, 26 Mar 2018 17:13:01 +0800 Subject: [PATCH 3/3] add InputMakeCommandTest --- tests/Console/ExampleInput.php | 22 ++++++++++++++++++++++ tests/Console/InputMakeCommandTest.php | 25 +++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 tests/Console/ExampleInput.php create mode 100644 tests/Console/InputMakeCommandTest.php 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'); + } +}