Skip to content

Commit

Permalink
Verify that a type name is specified before overriding class's type name
Browse files Browse the repository at this point in the history
  • Loading branch information
sburba committed Aug 1, 2018
1 parent 171631a commit 98127db
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Folklore/GraphQL/GraphQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
13 changes: 10 additions & 3 deletions tests/GraphQLTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
23 changes: 23 additions & 0 deletions tests/Objects/AnotherCustomExampleType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

use GraphQL\Type\Definition\Type;
use Folklore\GraphQL\Support\Type as GraphQLType;

class AnotherCustomExampleType extends GraphQLType
{

protected $attributes = [
'name' => 'AnotherCustomExample',
'description' => 'An example'
];

public function fields()
{
return [
'test' => [
'type' => Type::string(),
'description' => 'A test field'
]
];
}
}

0 comments on commit 98127db

Please sign in to comment.