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

Verify that a type name is specified before overriding class's type name #366

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Folklore/GraphQL/GraphQL.php
Original file line number Diff line number Diff line change
@@ -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) {
13 changes: 10 additions & 3 deletions tests/GraphQLTest.php
Original file line number Diff line number Diff line change
@@ -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);
}

/**
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'
]
];
}
}