mirror of
https://github.com/retailcrm/graphql-php.git
synced 2025-02-06 07:49:24 +03:00
Merge pull request #33 from mcg-web/lazy_implementation_to_interfaces_loading
Optimized implementation to interfaces loading
This commit is contained in:
commit
0a0c8181ea
@ -33,6 +33,8 @@ class Schema
|
||||
$this->mutationSchema = $mutationSchema;
|
||||
$this->subscriptionSchema = $subscriptionSchema;
|
||||
|
||||
InterfaceType::loadImplementationToInterfaces();
|
||||
|
||||
// Build type map now to detect any errors within this schema.
|
||||
$map = [];
|
||||
foreach ([$this->getQueryType(), $this->getMutationType(), Introspection::_schema()] as $type) {
|
||||
|
@ -18,6 +18,11 @@ class InterfaceType extends Type implements AbstractType, OutputType, CompositeT
|
||||
*/
|
||||
private $_implementations = [];
|
||||
|
||||
/**
|
||||
* @var \Closure[]
|
||||
*/
|
||||
private static $_lazyLoadImplementations = [];
|
||||
|
||||
/**
|
||||
* @var {[typeName: string]: boolean}
|
||||
*/
|
||||
@ -34,19 +39,31 @@ class InterfaceType extends Type implements AbstractType, OutputType, CompositeT
|
||||
public $config;
|
||||
|
||||
/**
|
||||
* Update the interfaces to know about this implementation.
|
||||
* Queue the update of the interfaces to know about this implementation.
|
||||
* This is an rare and unfortunate use of mutation in the type definition
|
||||
* implementations, but avoids an expensive "getPossibleTypes"
|
||||
* implementation for Interface types.
|
||||
*
|
||||
* @param ObjectType $impl
|
||||
* @param InterfaceType[] $interfaces
|
||||
*/
|
||||
public static function addImplementationToInterfaces(ObjectType $impl)
|
||||
{
|
||||
self::$_lazyLoadImplementations[] = function() use ($impl) {
|
||||
foreach ($impl->getInterfaces() as $interface) {
|
||||
$interface->_implementations[] = $impl;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Process ImplementationToInterfaces Queue
|
||||
*/
|
||||
public static function loadImplementationToInterfaces()
|
||||
{
|
||||
foreach (self::$_lazyLoadImplementations as $i => &$lazyLoadImplementation) {
|
||||
call_user_func($lazyLoadImplementation);
|
||||
unset(self::$_lazyLoadImplementations[$i]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -98,7 +98,7 @@ GraphQLNonNull;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Type
|
||||
* @return Type[]
|
||||
*/
|
||||
public static function getInternalTypes()
|
||||
{
|
||||
|
@ -29,7 +29,7 @@ class UnionType extends Type implements AbstractType, OutputType, CompositeType
|
||||
{
|
||||
Config::validate($config, [
|
||||
'name' => Config::STRING | Config::REQUIRED,
|
||||
'types' => Config::arrayOf(Config::OBJECT_TYPE, Config::REQUIRED),
|
||||
'types' => Config::arrayOf(Config::OBJECT_TYPE, Config::MAYBE_THUNK | Config::REQUIRED),
|
||||
'resolveType' => Config::CALLBACK, // function($value, ResolveInfo $info) => ObjectType
|
||||
'description' => Config::STRING
|
||||
]);
|
||||
|
@ -1,9 +0,0 @@
|
||||
<?php
|
||||
namespace GraphQL;
|
||||
|
||||
class Types
|
||||
{
|
||||
public static function Int()
|
||||
{
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user