Skip to content

Commit 9551569

Browse files
committed
Merge branch 'lazy-types' into v0.10
# Conflicts: # src/Executor/Executor.php
2 parents 463d995 + ce9bf33 commit 9551569

File tree

15 files changed

+688
-195
lines changed

15 files changed

+688
-195
lines changed

benchmarks/HugeSchemaBench.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class HugeSchemaBench
2222
private $schemaBuilder;
2323

2424
/**
25-
* @var array
25+
* @var Schema\Descriptor
2626
*/
2727
private $descriptor;
2828

@@ -54,7 +54,9 @@ public function setUp()
5454
public function benchSchema()
5555
{
5656
$this->schemaBuilder
57-
->buildSchema();
57+
->buildSchema()
58+
->getTypeMap()
59+
;
5860
}
5961

6062
public function benchSchemaLazy()
@@ -75,16 +77,13 @@ public function benchSmallQueryLazy()
7577

7678
private function createLazySchema()
7779
{
78-
$strategy = new LazyResolution(
79-
$this->descriptor,
80-
function($name) {
81-
return $this->schemaBuilder->loadType($name);
82-
}
80+
return new Schema(
81+
Schema\Config::create()
82+
->setQuery($this->schemaBuilder->buildQueryType())
83+
// ->setDescriptor($this->descriptor)
84+
->setTypeLoader(function($name) {
85+
return $this->schemaBuilder->loadType($name);
86+
})
8387
);
84-
85-
return new Schema([
86-
'query' => $this->schemaBuilder->buildQueryType(),
87-
'typeResolution' => $strategy,
88-
]);
8988
}
9089
}

src/Executor/Executor.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use GraphQL\Error\InvariantViolation;
66
use GraphQL\Executor\Promise\Adapter\SyncPromiseAdapter;
77
use GraphQL\Executor\Promise\Promise;
8+
use GraphQL\GraphQL;
89
use GraphQL\Language\AST\DocumentNode;
910
use GraphQL\Language\AST\FieldNode;
1011
use GraphQL\Language\AST\FragmentDefinitionNode;
@@ -18,6 +19,7 @@
1819
use GraphQL\Type\Definition\AbstractType;
1920
use GraphQL\Type\Definition\Directive;
2021
use GraphQL\Type\Definition\FieldDefinition;
22+
use GraphQL\Type\Definition\InterfaceType;
2123
use GraphQL\Type\Definition\LeafType;
2224
use GraphQL\Type\Definition\ListOfType;
2325
use GraphQL\Type\Definition\NonNull;
@@ -1021,6 +1023,16 @@ private function completeAbstractValue(AbstractType $returnType, $fieldNodes, Re
10211023
$runtimeType = $returnType->resolveType($result, $exeContext->contextValue, $info);
10221024

10231025
if (null === $runtimeType) {
1026+
if ($returnType instanceof InterfaceType && !$exeContext->schema->getConfig()->descriptor &&
1027+
!GraphQL::isIgnoredError(GraphQL::WARNING_ON_IMPLEMENTATION_RESOLUTION)) {
1028+
trigger_error(
1029+
"GraphQL Interface Type `{$returnType->name}` returned `null` from it`s `resolveType` function ".
1030+
'for value: ' . Utils::printSafe($result) . '. Switching to slow resolution method using `isTypeOf` ' .
1031+
'of all possible implementations. It degrades query performance significantly. '.
1032+
' Make sure your `resolveType` always returns valid implementation or throws.',
1033+
E_USER_WARNING
1034+
);
1035+
}
10241036
$runtimeType = self::defaultTypeResolver($result, $exeContext->contextValue, $info, $returnType);
10251037
}
10261038

src/GraphQL.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@
1616

1717
class GraphQL
1818
{
19+
const WARNING_ON_IMPLEMENTATION_RESOLUTION = 1;
20+
21+
private static $ignoredErrors = [];
22+
23+
public static function setIgnoreError($errorCode, $set = true)
24+
{
25+
self::$ignoredErrors[$errorCode] = $set ? true : null;
26+
}
27+
28+
public static function isIgnoredError($errorCode)
29+
{
30+
return isset(self::$ignoredErrors[$errorCode]);
31+
}
32+
1933
/**
2034
* This is the primary entry point function for fulfilling GraphQL operations
2135
* by parsing, validating, and executing a GraphQL document along side a

0 commit comments

Comments
 (0)