From d3cbfe84932c8df341a6119969cb05fa413aac3d Mon Sep 17 00:00:00 2001 From: Justin van Elst Date: Mon, 25 Feb 2019 11:23:04 +0100 Subject: [PATCH 1/3] Update GraphQL.php --- src/Rebing/GraphQL/GraphQL.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Rebing/GraphQL/GraphQL.php b/src/Rebing/GraphQL/GraphQL.php index 6ac5da0b..3bcf282d 100644 --- a/src/Rebing/GraphQL/GraphQL.php +++ b/src/Rebing/GraphQL/GraphQL.php @@ -210,8 +210,18 @@ protected function buildObjectTypeFromFields($fields, $opts = []) } public function addSchema($name, $schema) + { + $this->mergeSchemas($name, $schema); + } + + public function mergeSchemas($name, $schema) { - $this->schemas[$name] = $schema; + if (isset($this->schemas[$name]) && $this->schemas[$name]) { + $this->schemas[$name] = array_merge_recursive($this->schemas[$name], $schema); + } + else { + $this->schemas[$name] = $schema; + } } public function clearType($name) From a47b5f07bf59b85b82aee208eeed19c65930cbb5 Mon Sep 17 00:00:00 2001 From: Justin van Elst Date: Tue, 26 Feb 2019 09:10:19 +0100 Subject: [PATCH 2/3] add Merge schema test --- tests/GraphQLTest.php | 49 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/tests/GraphQLTest.php b/tests/GraphQLTest.php index cb7057dd..8f4234b3 100644 --- a/tests/GraphQLTest.php +++ b/tests/GraphQLTest.php @@ -270,6 +270,41 @@ public function testGetTypes() public function testAddSchema() { GraphQL::addSchema('custom_add', [ + 'query' => [ + 'examplesCustom' => ExamplesQuery::class + ], + 'mutation' => [ + 'updateExampleCustom' => UpdateExampleMutation::class + ], + 'types' => [ + CustomExampleType::class + ] + ]); + + $schemas = GraphQL::getSchemas(); + $this->assertArrayHasKey('custom_add', $schemas); + } + + /** + * Test merge schema + * + * @test + */ + public function testMergeSchema() + { + GraphQL::addSchema('custom_add', [ + 'query' => [ + 'examplesCustom' => ExamplesQuery::class + ], + 'mutation' => [ + 'updateExampleCustom' => UpdateExampleMutation::class + ], + 'types' => [ + CustomExampleType::class + ] + ]); + + GraphQL::addSchema('custom_add_another', [ 'query' => [ 'examplesCustom' => ExamplesQuery::class ], @@ -283,6 +318,20 @@ public function testAddSchema() $schemas = GraphQL::getSchemas(); $this->assertArrayHasKey('custom_add', $schemas); + $this->assertArrayHasKey('custom_add_another', $schemas); + + GraphQL::addSchema('custom_add_another', [ + 'query' => [ + 'examplesCustomAnother' => ExamplesQuery::class + ] + ]); + + $schemas = GraphQL::getSchemas(); + $this->assertArrayHasKey('custom_add_another', $schemas); + + $querys = $schemas['custom_add_another']; + $this->assertArrayHasKey('examplesCustoms', $querys); + $this->assertArrayHasKey('examplesCustomAnother', $querys); } /** From 943ea67cdb0107711058af0f0befa601ce8ea9ef Mon Sep 17 00:00:00 2001 From: Justin van Elst Date: Tue, 26 Feb 2019 11:48:20 +0100 Subject: [PATCH 3/3] Test implemented incorrectly --- tests/GraphQLTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/GraphQLTest.php b/tests/GraphQLTest.php index 8f4234b3..c0308b95 100644 --- a/tests/GraphQLTest.php +++ b/tests/GraphQLTest.php @@ -329,8 +329,8 @@ public function testMergeSchema() $schemas = GraphQL::getSchemas(); $this->assertArrayHasKey('custom_add_another', $schemas); - $querys = $schemas['custom_add_another']; - $this->assertArrayHasKey('examplesCustoms', $querys); + $querys = $schemas['custom_add_another']['query']; + $this->assertArrayHasKey('examplesCustom', $querys); $this->assertArrayHasKey('examplesCustomAnother', $querys); }