Merge pull request #901 from limingxinleo/1.1-graphql

Optimized code for graphql.
This commit is contained in:
李铭昕 2019-11-11 10:02:30 +08:00 committed by GitHub
commit 7bf1ac4fbc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 41 additions and 6 deletions

View File

@ -9,10 +9,11 @@
## Fixed
- [#897](https://github.com/hyperf/hyperf/pull/897) Fixed connection pool of `Hyperf\Nats\Annotation\Consumer` does not works as expected.
- [#901](https://github.com/hyperf/hyperf/pull/901) Fixed Annotation `Factory` does not works for GraphQL.
- [#903](https://github.com/hyperf/hyperf/pull/903) Fixed execute `init-proxy` command can not stop when `hyperf/rpc-client` component exists.
- [#904](https://github.com/hyperf/hyperf/pull/904) Fixed the hooked I/O request does not works in the listener that listening `Hyperf\Framework\Event\BeforeMainServerStart` event.
- [#906](https://github.com/hyperf/hyperf/pull/906) Fixed `port` property of URI of `Hyperf\HttpMessage\Server\Request`.
.
# v1.1.5 - 2019-11-07
## Added

View File

@ -14,6 +14,7 @@ namespace Hyperf\GraphQL\Annotation;
use Hyperf\Di\Annotation\AnnotationCollector;
use Hyperf\Di\ReflectionManager;
use Hyperf\GraphQL\ClassCollector;
use ReflectionProperty;
trait AnnotationTrait
@ -31,16 +32,19 @@ trait AnnotationTrait
public function collectClass(string $className): void
{
AnnotationCollector::collectClass($className, static::class, $this);
ClassCollector::collect($className);
}
public function collectMethod(string $className, ?string $target): void
{
AnnotationCollector::collectMethod($className, $target, static::class, $this);
ClassCollector::collect($className);
}
public function collectProperty(string $className, ?string $target): void
{
AnnotationCollector::collectProperty($className, $target, static::class, $this);
ClassCollector::collect($className);
}
protected function bindMainProperty(string $key, array $value)

View File

@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://doc.hyperf.io
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\GraphQL;
class ClassCollector
{
private static $classes = [];
public static function collect(string $class)
{
if (! in_array($class, self::$classes)) {
self::$classes[] = $class;
}
}
public static function getClasses()
{
return self::$classes;
}
}

View File

@ -18,12 +18,13 @@ use TheCodingMachine\GraphQLite\GraphQLException;
use TheCodingMachine\GraphQLite\Mappers\RecursiveTypeMapperInterface;
use TheCodingMachine\GraphQLite\Types\ArgumentResolver;
use TheCodingMachine\GraphQLite\Types\ResolvableInputInterface;
use TheCodingMachine\GraphQLite\Types\ResolvableInputObjectType as TheCodingMachineResolvableInputObjectType;
use function get_class;
/**
* A GraphQL input object that can be resolved using a factory.
*/
class ResolvableInputObjectType extends InputObjectType implements ResolvableInputInterface
class ResolvableInputObjectType extends TheCodingMachineResolvableInputObjectType implements ResolvableInputInterface
{
/**
* @var ArgumentResolver
@ -59,7 +60,7 @@ class ResolvableInputObjectType extends InputObjectType implements ResolvableInp
}
$config += $additionalConfig;
parent::__construct($config);
InputObjectType::__construct($config);
}
/**

View File

@ -14,7 +14,6 @@ namespace Hyperf\GraphQL;
use GraphQL\Type\Definition\InputObjectType;
use GraphQL\Type\Definition\OutputType;
use Hyperf\Di\Annotation\AnnotationCollector;
use Hyperf\GraphQL\Annotation\Type;
use Psr\Container\ContainerInterface;
use Psr\SimpleCache\CacheInterface;
@ -544,8 +543,8 @@ class TypeMapper implements TypeMapperInterface
{
if ($this->classes === null) {
$this->classes = [];
$classes = AnnotationCollector::getClassByAnnotation(Type::class);
foreach (array_keys($classes) as $className) {
$classes = ClassCollector::getClasses();
foreach ($classes as $className) {
if (! \class_exists($className)) {
continue;
}