From 98127dbade96fe4b7d01fe8757677a59178dc10f Mon Sep 17 00:00:00 2001 From: sburba Date: Wed, 1 Aug 2018 10:45:10 -0400 Subject: [PATCH] Verify that a type name is specified before overriding class's type name Fixes #365 --- src/Folklore/GraphQL/GraphQL.php | 2 +- tests/GraphQLTest.php | 13 +++++++++--- tests/Objects/AnotherCustomExampleType.php | 23 ++++++++++++++++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 tests/Objects/AnotherCustomExampleType.php diff --git a/src/Folklore/GraphQL/GraphQL.php b/src/Folklore/GraphQL/GraphQL.php index 53cfb98c..b66aec22 100644 --- a/src/Folklore/GraphQL/GraphQL.php +++ b/src/Folklore/GraphQL/GraphQL.php @@ -67,7 +67,7 @@ public function schema($schema = null) $this->typesInstances[$name] = $objectType; $types[] = $objectType; - $this->addType($type, $name); + $this->addType($type, is_numeric($name) ? null : $name); } } else { foreach ($this->types as $name => $type) { diff --git a/tests/GraphQLTest.php b/tests/GraphQLTest.php index 143d6580..4860ccd7 100644 --- a/tests/GraphQLTest.php +++ b/tests/GraphQLTest.php @@ -77,14 +77,21 @@ public function testSchemaWithArray() 'updateExampleCustom' => UpdateExampleMutation::class ], 'types' => [ - CustomExampleType::class + CustomExampleType::class, + AnotherCustomExampleType::class ] ]); - + + $graphql_types = GraphQL::getTypes(); + $schema_types = $schema->getTypeMap(); + $this->assertGraphQLSchema($schema); $this->assertGraphQLSchemaHasQuery($schema, 'examplesCustom'); $this->assertGraphQLSchemaHasMutation($schema, 'updateExampleCustom'); - $this->assertArrayHasKey('CustomExample', $schema->getTypeMap()); + $this->assertArrayHasKey('CustomExample', $schema_types); + $this->assertArrayHasKey('AnotherCustomExample', $schema_types); + $this->assertArrayHasKey('CustomExample', $graphql_types); + $this->assertArrayHasKey('AnotherCustomExample', $graphql_types); } /** diff --git a/tests/Objects/AnotherCustomExampleType.php b/tests/Objects/AnotherCustomExampleType.php new file mode 100644 index 00000000..720c12d6 --- /dev/null +++ b/tests/Objects/AnotherCustomExampleType.php @@ -0,0 +1,23 @@ + 'AnotherCustomExample', + 'description' => 'An example' + ]; + + public function fields() + { + return [ + 'test' => [ + 'type' => Type::string(), + 'description' => 'A test field' + ] + ]; + } +}