2017-08-14 16:41:08 +03:00
|
|
|
<?php
|
|
|
|
|
2018-09-01 18:07:06 +03:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace GraphQL\Tests\Executor;
|
2017-08-14 16:41:08 +03:00
|
|
|
|
2017-08-14 19:52:17 +03:00
|
|
|
use GraphQL\Error\InvariantViolation;
|
2017-08-14 16:41:08 +03:00
|
|
|
use GraphQL\Error\Warning;
|
|
|
|
use GraphQL\Executor\ExecutionResult;
|
|
|
|
use GraphQL\Executor\Executor;
|
|
|
|
use GraphQL\Language\Parser;
|
2018-09-01 18:07:06 +03:00
|
|
|
use GraphQL\Tests\Executor\TestClasses\Cat;
|
|
|
|
use GraphQL\Tests\Executor\TestClasses\Dog;
|
2017-08-14 21:49:56 +03:00
|
|
|
use GraphQL\Type\Definition\CustomScalarType;
|
2018-09-01 18:07:06 +03:00
|
|
|
use GraphQL\Type\Definition\EnumType;
|
|
|
|
use GraphQL\Type\Definition\InputObjectType;
|
2017-08-14 16:41:08 +03:00
|
|
|
use GraphQL\Type\Definition\InterfaceType;
|
|
|
|
use GraphQL\Type\Definition\ObjectType;
|
2018-09-01 18:07:06 +03:00
|
|
|
use GraphQL\Type\Definition\ScalarType;
|
2017-08-14 16:41:08 +03:00
|
|
|
use GraphQL\Type\Definition\Type;
|
2017-08-14 21:49:56 +03:00
|
|
|
use GraphQL\Type\Definition\UnionType;
|
2017-08-14 16:41:08 +03:00
|
|
|
use GraphQL\Type\Schema;
|
2018-07-29 18:43:10 +03:00
|
|
|
use PHPUnit\Framework\Error\Error;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
2018-09-01 18:07:06 +03:00
|
|
|
use function count;
|
2017-08-14 16:41:08 +03:00
|
|
|
|
2018-07-29 18:43:10 +03:00
|
|
|
class ExecutorLazySchemaTest extends TestCase
|
2017-08-14 16:41:08 +03:00
|
|
|
{
|
2018-09-01 18:07:06 +03:00
|
|
|
/** @var ScalarType */
|
|
|
|
public $someScalarType;
|
2017-08-14 21:49:56 +03:00
|
|
|
|
2018-09-01 18:07:06 +03:00
|
|
|
/** @var ObjectType */
|
|
|
|
public $someObjectType;
|
2017-08-14 21:49:56 +03:00
|
|
|
|
2018-09-01 18:07:06 +03:00
|
|
|
/** @var ObjectType */
|
|
|
|
public $otherObjectType;
|
2017-08-14 21:49:56 +03:00
|
|
|
|
2018-09-01 18:07:06 +03:00
|
|
|
/** @var ObjectType */
|
|
|
|
public $deeperObjectType;
|
2017-08-14 21:49:56 +03:00
|
|
|
|
2018-09-01 18:07:06 +03:00
|
|
|
/** @var UnionType */
|
|
|
|
public $someUnionType;
|
2017-08-14 21:49:56 +03:00
|
|
|
|
2018-09-01 18:07:06 +03:00
|
|
|
/** @var InterfaceType */
|
|
|
|
public $someInterfaceType;
|
2017-08-14 21:49:56 +03:00
|
|
|
|
2018-09-01 18:07:06 +03:00
|
|
|
/** @var EnumType */
|
|
|
|
public $someEnumType;
|
2017-08-14 21:49:56 +03:00
|
|
|
|
2018-09-01 18:07:06 +03:00
|
|
|
/** @var InputObjectType */
|
|
|
|
public $someInputObjectType;
|
2017-08-14 21:49:56 +03:00
|
|
|
|
2018-09-01 18:07:06 +03:00
|
|
|
/** @var ObjectType */
|
|
|
|
public $queryType;
|
2017-08-14 21:49:56 +03:00
|
|
|
|
2018-09-01 18:07:06 +03:00
|
|
|
/** @var string[] */
|
2017-08-14 21:49:56 +03:00
|
|
|
public $calls = [];
|
|
|
|
|
2018-09-01 18:07:06 +03:00
|
|
|
/** @var bool[] */
|
2017-08-14 21:49:56 +03:00
|
|
|
public $loadedTypes = [];
|
|
|
|
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testWarnsAboutSlowIsTypeOfForLazySchema() : void
|
2017-08-14 16:41:08 +03:00
|
|
|
{
|
|
|
|
// isTypeOf used to resolve runtime type for Interface
|
|
|
|
$petType = new InterfaceType([
|
2018-09-01 18:07:06 +03:00
|
|
|
'name' => 'Pet',
|
2018-09-26 12:07:23 +03:00
|
|
|
'fields' => static function () {
|
2017-08-14 16:41:08 +03:00
|
|
|
return [
|
2018-09-01 18:07:06 +03:00
|
|
|
'name' => ['type' => Type::string()],
|
2017-08-14 16:41:08 +03:00
|
|
|
];
|
2018-09-01 18:07:06 +03:00
|
|
|
},
|
2017-08-14 16:41:08 +03:00
|
|
|
]);
|
|
|
|
|
|
|
|
// Added to interface type when defined
|
|
|
|
$dogType = new ObjectType([
|
2018-09-01 18:07:06 +03:00
|
|
|
'name' => 'Dog',
|
2017-08-14 16:41:08 +03:00
|
|
|
'interfaces' => [$petType],
|
2018-09-26 12:07:23 +03:00
|
|
|
'isTypeOf' => static function ($obj) {
|
2018-09-01 18:07:06 +03:00
|
|
|
return $obj instanceof Dog;
|
|
|
|
},
|
2018-09-26 12:07:23 +03:00
|
|
|
'fields' => static function () {
|
2017-08-14 16:41:08 +03:00
|
|
|
return [
|
2018-09-01 18:07:06 +03:00
|
|
|
'name' => ['type' => Type::string()],
|
|
|
|
'woofs' => ['type' => Type::boolean()],
|
2017-08-14 16:41:08 +03:00
|
|
|
];
|
2018-09-01 18:07:06 +03:00
|
|
|
},
|
2017-08-14 16:41:08 +03:00
|
|
|
]);
|
|
|
|
|
|
|
|
$catType = new ObjectType([
|
2018-09-01 18:07:06 +03:00
|
|
|
'name' => 'Cat',
|
2017-08-14 16:41:08 +03:00
|
|
|
'interfaces' => [$petType],
|
2018-09-26 12:07:23 +03:00
|
|
|
'isTypeOf' => static function ($obj) {
|
2017-08-14 16:41:08 +03:00
|
|
|
return $obj instanceof Cat;
|
|
|
|
},
|
2018-09-26 12:07:23 +03:00
|
|
|
'fields' => static function () {
|
2017-08-14 16:41:08 +03:00
|
|
|
return [
|
2018-09-01 18:07:06 +03:00
|
|
|
'name' => ['type' => Type::string()],
|
2017-08-14 16:41:08 +03:00
|
|
|
'meows' => ['type' => Type::boolean()],
|
|
|
|
];
|
2018-09-01 18:07:06 +03:00
|
|
|
},
|
2017-08-14 16:41:08 +03:00
|
|
|
]);
|
|
|
|
|
|
|
|
$schema = new Schema([
|
2018-09-01 18:07:06 +03:00
|
|
|
'query' => new ObjectType([
|
|
|
|
'name' => 'Query',
|
2017-08-14 16:41:08 +03:00
|
|
|
'fields' => [
|
|
|
|
'pets' => [
|
2018-09-01 18:07:06 +03:00
|
|
|
'type' => Type::listOf($petType),
|
2018-09-26 12:07:23 +03:00
|
|
|
'resolve' => static function () {
|
2017-08-14 16:41:08 +03:00
|
|
|
return [new Dog('Odie', true), new Cat('Garfield', false)];
|
2018-09-01 18:07:06 +03:00
|
|
|
},
|
|
|
|
],
|
|
|
|
],
|
2017-08-14 16:41:08 +03:00
|
|
|
]),
|
2018-09-01 18:07:06 +03:00
|
|
|
'types' => [$catType, $dogType],
|
2018-09-26 12:07:23 +03:00
|
|
|
'typeLoader' => static function ($name) use ($dogType, $petType, $catType) {
|
2017-08-14 16:41:08 +03:00
|
|
|
switch ($name) {
|
|
|
|
case 'Dog':
|
|
|
|
return $dogType;
|
|
|
|
case 'Pet':
|
|
|
|
return $petType;
|
|
|
|
case 'Cat':
|
|
|
|
return $catType;
|
|
|
|
}
|
2018-09-01 18:07:06 +03:00
|
|
|
},
|
2017-08-14 16:41:08 +03:00
|
|
|
]);
|
|
|
|
|
|
|
|
$query = '{
|
|
|
|
pets {
|
|
|
|
name
|
|
|
|
... on Dog {
|
|
|
|
woofs
|
|
|
|
}
|
|
|
|
... on Cat {
|
|
|
|
meows
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}';
|
|
|
|
|
|
|
|
$expected = new ExecutionResult([
|
|
|
|
'pets' => [
|
|
|
|
['name' => 'Odie', 'woofs' => true],
|
2018-09-01 18:07:06 +03:00
|
|
|
['name' => 'Garfield', 'meows' => false],
|
2017-08-14 16:41:08 +03:00
|
|
|
],
|
|
|
|
]);
|
|
|
|
|
2017-08-19 19:01:46 +03:00
|
|
|
Warning::suppress(Warning::WARNING_FULL_SCHEMA_SCAN);
|
2017-08-14 16:41:08 +03:00
|
|
|
$result = Executor::execute($schema, Parser::parse($query));
|
2018-09-19 18:12:09 +03:00
|
|
|
self::assertEquals($expected, $result);
|
2017-08-14 16:41:08 +03:00
|
|
|
|
2017-08-19 19:01:46 +03:00
|
|
|
Warning::enable(Warning::WARNING_FULL_SCHEMA_SCAN);
|
2017-08-14 16:41:08 +03:00
|
|
|
$result = Executor::execute($schema, Parser::parse($query));
|
2018-09-19 18:12:09 +03:00
|
|
|
self::assertEquals(1, count($result->errors));
|
|
|
|
self::assertInstanceOf(Error::class, $result->errors[0]->getPrevious());
|
2017-08-14 16:41:08 +03:00
|
|
|
|
2018-09-19 18:12:09 +03:00
|
|
|
self::assertEquals(
|
2018-09-01 18:07:06 +03:00
|
|
|
'GraphQL Interface Type `Pet` returned `null` from it`s `resolveType` function for value: instance of ' .
|
|
|
|
'GraphQL\Tests\Executor\TestClasses\Dog. Switching to slow resolution method using `isTypeOf` of all possible ' .
|
|
|
|
'implementations. It requires full schema scan and degrades query performance significantly. ' .
|
2017-08-14 16:41:08 +03:00
|
|
|
'Make sure your `resolveType` always returns valid implementation or throws.',
|
2018-09-01 18:07:06 +03:00
|
|
|
$result->errors[0]->getMessage()
|
|
|
|
);
|
2017-08-14 16:41:08 +03:00
|
|
|
}
|
2017-08-14 19:52:17 +03:00
|
|
|
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testHintsOnConflictingTypeInstancesInDefinitions() : void
|
2017-08-14 19:52:17 +03:00
|
|
|
{
|
2018-09-01 18:07:06 +03:00
|
|
|
$calls = [];
|
2018-09-26 12:07:23 +03:00
|
|
|
$typeLoader = static function ($name) use (&$calls) {
|
2017-08-14 19:52:17 +03:00
|
|
|
$calls[] = $name;
|
|
|
|
switch ($name) {
|
|
|
|
case 'Test':
|
|
|
|
return new ObjectType([
|
2018-09-01 18:07:06 +03:00
|
|
|
'name' => 'Test',
|
2018-09-26 12:07:23 +03:00
|
|
|
'fields' => static function () {
|
2017-08-14 19:52:17 +03:00
|
|
|
return [
|
|
|
|
'test' => Type::string(),
|
|
|
|
];
|
2018-09-01 18:07:06 +03:00
|
|
|
},
|
2017-08-14 19:52:17 +03:00
|
|
|
]);
|
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
};
|
2018-09-01 18:07:06 +03:00
|
|
|
|
2017-08-14 19:52:17 +03:00
|
|
|
$query = new ObjectType([
|
2018-09-01 18:07:06 +03:00
|
|
|
'name' => 'Query',
|
2018-09-26 12:07:23 +03:00
|
|
|
'fields' => static function () use ($typeLoader) {
|
2017-08-14 19:52:17 +03:00
|
|
|
return [
|
2018-09-01 18:07:06 +03:00
|
|
|
'test' => $typeLoader('Test'),
|
2017-08-14 19:52:17 +03:00
|
|
|
];
|
2018-09-01 18:07:06 +03:00
|
|
|
},
|
2017-08-14 19:52:17 +03:00
|
|
|
]);
|
2018-09-01 18:07:06 +03:00
|
|
|
|
2017-08-14 19:52:17 +03:00
|
|
|
$schema = new Schema([
|
2018-09-01 18:07:06 +03:00
|
|
|
'query' => $query,
|
|
|
|
'typeLoader' => $typeLoader,
|
2017-08-14 19:52:17 +03:00
|
|
|
]);
|
|
|
|
|
|
|
|
$query = '
|
|
|
|
{
|
|
|
|
test {
|
|
|
|
test
|
|
|
|
}
|
|
|
|
}
|
|
|
|
';
|
|
|
|
|
2018-09-19 18:12:09 +03:00
|
|
|
self::assertEquals([], $calls);
|
2017-08-14 19:52:17 +03:00
|
|
|
$result = Executor::execute($schema, Parser::parse($query), ['test' => ['test' => 'value']]);
|
2018-09-19 18:12:09 +03:00
|
|
|
self::assertEquals(['Test', 'Test'], $calls);
|
2017-08-14 19:52:17 +03:00
|
|
|
|
2018-09-19 18:12:09 +03:00
|
|
|
self::assertEquals(
|
2018-09-01 18:07:06 +03:00
|
|
|
'Schema must contain unique named types but contains multiple types named "Test". ' .
|
|
|
|
'Make sure that type loader returns the same instance as defined in Query.test ' .
|
2017-08-20 18:28:17 +03:00
|
|
|
'(see http://webonyx.github.io/graphql-php/type-system/#type-registry).',
|
2017-08-14 19:52:17 +03:00
|
|
|
$result->errors[0]->getMessage()
|
|
|
|
);
|
2018-09-19 18:12:09 +03:00
|
|
|
self::assertInstanceOf(
|
2017-08-14 19:52:17 +03:00
|
|
|
InvariantViolation::class,
|
|
|
|
$result->errors[0]->getPrevious()
|
|
|
|
);
|
|
|
|
}
|
2017-08-14 21:49:56 +03:00
|
|
|
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testSimpleQuery() : void
|
2017-08-14 21:49:56 +03:00
|
|
|
{
|
|
|
|
$schema = new Schema([
|
2018-09-01 18:07:06 +03:00
|
|
|
'query' => $this->loadType('Query'),
|
|
|
|
'typeLoader' => function ($name) {
|
2017-08-14 21:49:56 +03:00
|
|
|
return $this->loadType($name, true);
|
2018-09-01 18:07:06 +03:00
|
|
|
},
|
2017-08-14 21:49:56 +03:00
|
|
|
]);
|
|
|
|
|
2018-09-01 18:07:06 +03:00
|
|
|
$query = '{ object { string } }';
|
2017-08-14 21:49:56 +03:00
|
|
|
$result = Executor::execute(
|
|
|
|
$schema,
|
|
|
|
Parser::parse($query),
|
|
|
|
['object' => ['string' => 'test']]
|
|
|
|
);
|
|
|
|
|
2018-09-01 18:07:06 +03:00
|
|
|
$expected = [
|
2017-08-14 21:49:56 +03:00
|
|
|
'data' => ['object' => ['string' => 'test']],
|
|
|
|
];
|
|
|
|
$expectedExecutorCalls = [
|
|
|
|
'Query.fields',
|
|
|
|
'SomeObject',
|
2018-09-01 18:07:06 +03:00
|
|
|
'SomeObject.fields',
|
2017-08-14 21:49:56 +03:00
|
|
|
];
|
2018-09-19 18:12:09 +03:00
|
|
|
self::assertEquals($expected, $result->toArray(true));
|
|
|
|
self::assertEquals($expectedExecutorCalls, $this->calls);
|
2017-08-14 21:49:56 +03:00
|
|
|
}
|
|
|
|
|
2018-09-01 18:07:06 +03:00
|
|
|
public function loadType($name, $isExecutorCall = false)
|
|
|
|
{
|
|
|
|
if ($isExecutorCall) {
|
|
|
|
$this->calls[] = $name;
|
|
|
|
}
|
|
|
|
$this->loadedTypes[$name] = true;
|
|
|
|
|
|
|
|
switch ($name) {
|
|
|
|
case 'Query':
|
|
|
|
return $this->queryType ?: $this->queryType = new ObjectType([
|
|
|
|
'name' => 'Query',
|
|
|
|
'fields' => function () {
|
|
|
|
$this->calls[] = 'Query.fields';
|
|
|
|
|
|
|
|
return [
|
|
|
|
'object' => ['type' => $this->loadType('SomeObject')],
|
|
|
|
'other' => ['type' => $this->loadType('OtherObject')],
|
|
|
|
];
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
case 'SomeObject':
|
|
|
|
return $this->someObjectType ?: $this->someObjectType = new ObjectType([
|
|
|
|
'name' => 'SomeObject',
|
|
|
|
'fields' => function () {
|
|
|
|
$this->calls[] = 'SomeObject.fields';
|
|
|
|
|
|
|
|
return [
|
|
|
|
'string' => ['type' => Type::string()],
|
|
|
|
'object' => ['type' => $this->someObjectType],
|
|
|
|
];
|
|
|
|
},
|
|
|
|
'interfaces' => function () {
|
|
|
|
$this->calls[] = 'SomeObject.interfaces';
|
|
|
|
|
|
|
|
return [
|
|
|
|
$this->loadType('SomeInterface'),
|
|
|
|
];
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
case 'OtherObject':
|
|
|
|
return $this->otherObjectType ?: $this->otherObjectType = new ObjectType([
|
|
|
|
'name' => 'OtherObject',
|
|
|
|
'fields' => function () {
|
|
|
|
$this->calls[] = 'OtherObject.fields';
|
|
|
|
|
|
|
|
return [
|
|
|
|
'union' => ['type' => $this->loadType('SomeUnion')],
|
|
|
|
'iface' => ['type' => Type::nonNull($this->loadType('SomeInterface'))],
|
|
|
|
];
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
case 'DeeperObject':
|
|
|
|
return $this->deeperObjectType ?: $this->deeperObjectType = new ObjectType([
|
|
|
|
'name' => 'DeeperObject',
|
|
|
|
'fields' => function () {
|
|
|
|
return [
|
|
|
|
'scalar' => ['type' => $this->loadType('SomeScalar')],
|
|
|
|
];
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
case 'SomeScalar':
|
|
|
|
return $this->someScalarType ?: $this->someScalarType = new CustomScalarType([
|
|
|
|
'name' => 'SomeScalar',
|
2018-09-26 12:07:23 +03:00
|
|
|
'serialize' => static function ($value) {
|
2018-09-01 18:07:06 +03:00
|
|
|
return $value;
|
|
|
|
},
|
2018-09-26 12:07:23 +03:00
|
|
|
'parseValue' => static function ($value) {
|
2018-09-01 18:07:06 +03:00
|
|
|
return $value;
|
|
|
|
},
|
2018-09-26 12:07:23 +03:00
|
|
|
'parseLiteral' => static function () {
|
2018-09-01 18:07:06 +03:00
|
|
|
},
|
|
|
|
]);
|
|
|
|
case 'SomeUnion':
|
|
|
|
return $this->someUnionType ?: $this->someUnionType = new UnionType([
|
|
|
|
'name' => 'SomeUnion',
|
|
|
|
'resolveType' => function () {
|
|
|
|
$this->calls[] = 'SomeUnion.resolveType';
|
|
|
|
|
|
|
|
return $this->loadType('DeeperObject');
|
|
|
|
},
|
|
|
|
'types' => function () {
|
|
|
|
$this->calls[] = 'SomeUnion.types';
|
|
|
|
|
|
|
|
return [$this->loadType('DeeperObject')];
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
case 'SomeInterface':
|
|
|
|
return $this->someInterfaceType ?: $this->someInterfaceType = new InterfaceType([
|
|
|
|
'name' => 'SomeInterface',
|
|
|
|
'resolveType' => function () {
|
|
|
|
$this->calls[] = 'SomeInterface.resolveType';
|
|
|
|
|
|
|
|
return $this->loadType('SomeObject');
|
|
|
|
},
|
|
|
|
'fields' => function () {
|
|
|
|
$this->calls[] = 'SomeInterface.fields';
|
|
|
|
|
|
|
|
return [
|
|
|
|
'string' => ['type' => Type::string()],
|
|
|
|
];
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testDeepQuery() : void
|
2017-08-14 21:49:56 +03:00
|
|
|
{
|
|
|
|
$schema = new Schema([
|
2018-09-01 18:07:06 +03:00
|
|
|
'query' => $this->loadType('Query'),
|
|
|
|
'typeLoader' => function ($name) {
|
2017-08-14 21:49:56 +03:00
|
|
|
return $this->loadType($name, true);
|
2018-09-01 18:07:06 +03:00
|
|
|
},
|
2017-08-14 21:49:56 +03:00
|
|
|
]);
|
|
|
|
|
2018-09-01 18:07:06 +03:00
|
|
|
$query = '{ object { object { object { string } } } }';
|
2017-08-14 21:49:56 +03:00
|
|
|
$result = Executor::execute(
|
|
|
|
$schema,
|
|
|
|
Parser::parse($query),
|
|
|
|
['object' => ['object' => ['object' => ['string' => 'test']]]]
|
|
|
|
);
|
|
|
|
|
2018-09-01 18:07:06 +03:00
|
|
|
$expected = [
|
|
|
|
'data' => ['object' => ['object' => ['object' => ['string' => 'test']]]],
|
2017-08-14 21:49:56 +03:00
|
|
|
];
|
|
|
|
$expectedLoadedTypes = [
|
2018-09-01 18:07:06 +03:00
|
|
|
'Query' => true,
|
|
|
|
'SomeObject' => true,
|
|
|
|
'OtherObject' => true,
|
2017-08-14 21:49:56 +03:00
|
|
|
];
|
|
|
|
|
2018-09-19 18:12:09 +03:00
|
|
|
self::assertEquals($expected, $result->toArray(true));
|
|
|
|
self::assertEquals($expectedLoadedTypes, $this->loadedTypes);
|
2017-08-14 21:49:56 +03:00
|
|
|
|
|
|
|
$expectedExecutorCalls = [
|
|
|
|
'Query.fields',
|
|
|
|
'SomeObject',
|
2018-09-01 18:07:06 +03:00
|
|
|
'SomeObject.fields',
|
2017-08-14 21:49:56 +03:00
|
|
|
];
|
2018-09-19 18:12:09 +03:00
|
|
|
self::assertEquals($expectedExecutorCalls, $this->calls);
|
2017-08-14 21:49:56 +03:00
|
|
|
}
|
|
|
|
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testResolveUnion() : void
|
2017-08-14 21:49:56 +03:00
|
|
|
{
|
|
|
|
$schema = new Schema([
|
2018-09-01 18:07:06 +03:00
|
|
|
'query' => $this->loadType('Query'),
|
|
|
|
'typeLoader' => function ($name) {
|
2017-08-14 21:49:56 +03:00
|
|
|
return $this->loadType($name, true);
|
2018-09-01 18:07:06 +03:00
|
|
|
},
|
2017-08-14 21:49:56 +03:00
|
|
|
]);
|
|
|
|
|
2018-09-01 18:07:06 +03:00
|
|
|
$query = '
|
2017-08-14 21:49:56 +03:00
|
|
|
{
|
|
|
|
other {
|
|
|
|
union {
|
|
|
|
scalar
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
';
|
|
|
|
$result = Executor::execute(
|
|
|
|
$schema,
|
|
|
|
Parser::parse($query),
|
|
|
|
['other' => ['union' => ['scalar' => 'test']]]
|
|
|
|
);
|
|
|
|
|
2018-09-01 18:07:06 +03:00
|
|
|
$expected = [
|
2017-08-14 21:49:56 +03:00
|
|
|
'data' => ['other' => ['union' => ['scalar' => 'test']]],
|
|
|
|
];
|
|
|
|
$expectedLoadedTypes = [
|
2018-09-01 18:07:06 +03:00
|
|
|
'Query' => true,
|
|
|
|
'SomeObject' => true,
|
|
|
|
'OtherObject' => true,
|
|
|
|
'SomeUnion' => true,
|
2017-08-14 21:49:56 +03:00
|
|
|
'SomeInterface' => true,
|
2018-09-01 18:07:06 +03:00
|
|
|
'DeeperObject' => true,
|
|
|
|
'SomeScalar' => true,
|
2017-08-14 21:49:56 +03:00
|
|
|
];
|
|
|
|
|
2018-09-19 18:12:09 +03:00
|
|
|
self::assertEquals($expected, $result->toArray(true));
|
|
|
|
self::assertEquals($expectedLoadedTypes, $this->loadedTypes);
|
2017-08-14 21:49:56 +03:00
|
|
|
|
|
|
|
$expectedCalls = [
|
|
|
|
'Query.fields',
|
|
|
|
'OtherObject',
|
|
|
|
'OtherObject.fields',
|
|
|
|
'SomeUnion',
|
|
|
|
'SomeUnion.resolveType',
|
|
|
|
'SomeUnion.types',
|
|
|
|
'DeeperObject',
|
|
|
|
'SomeScalar',
|
|
|
|
];
|
2018-09-19 18:12:09 +03:00
|
|
|
self::assertEquals($expectedCalls, $this->calls);
|
2017-08-14 21:49:56 +03:00
|
|
|
}
|
2017-08-14 16:41:08 +03:00
|
|
|
}
|