Skip to content
This repository was archived by the owner on Feb 10, 2019. It is now read-only.

Commit 98127db

Browse files
author
sburba
committed
Verify that a type name is specified before overriding class's type name
Fixes #365
1 parent 171631a commit 98127db

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

src/Folklore/GraphQL/GraphQL.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function schema($schema = null)
6767
$this->typesInstances[$name] = $objectType;
6868
$types[] = $objectType;
6969

70-
$this->addType($type, $name);
70+
$this->addType($type, is_numeric($name) ? null : $name);
7171
}
7272
} else {
7373
foreach ($this->types as $name => $type) {

tests/GraphQLTest.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,21 @@ public function testSchemaWithArray()
7777
'updateExampleCustom' => UpdateExampleMutation::class
7878
],
7979
'types' => [
80-
CustomExampleType::class
80+
CustomExampleType::class,
81+
AnotherCustomExampleType::class
8182
]
8283
]);
83-
84+
85+
$graphql_types = GraphQL::getTypes();
86+
$schema_types = $schema->getTypeMap();
87+
8488
$this->assertGraphQLSchema($schema);
8589
$this->assertGraphQLSchemaHasQuery($schema, 'examplesCustom');
8690
$this->assertGraphQLSchemaHasMutation($schema, 'updateExampleCustom');
87-
$this->assertArrayHasKey('CustomExample', $schema->getTypeMap());
91+
$this->assertArrayHasKey('CustomExample', $schema_types);
92+
$this->assertArrayHasKey('AnotherCustomExample', $schema_types);
93+
$this->assertArrayHasKey('CustomExample', $graphql_types);
94+
$this->assertArrayHasKey('AnotherCustomExample', $graphql_types);
8895
}
8996

9097
/**
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
use GraphQL\Type\Definition\Type;
4+
use Folklore\GraphQL\Support\Type as GraphQLType;
5+
6+
class AnotherCustomExampleType extends GraphQLType
7+
{
8+
9+
protected $attributes = [
10+
'name' => 'AnotherCustomExample',
11+
'description' => 'An example'
12+
];
13+
14+
public function fields()
15+
{
16+
return [
17+
'test' => [
18+
'type' => Type::string(),
19+
'description' => 'A test field'
20+
]
21+
];
22+
}
23+
}

0 commit comments

Comments
 (0)