diff --git a/src/Type/Definition/Directive.php b/src/Type/Definition/Directive.php index 0a6db42e5..f2c546f93 100644 --- a/src/Type/Definition/Directive.php +++ b/src/Type/Definition/Directive.php @@ -33,7 +33,7 @@ class Directive * * @var array */ - protected static array $internalDirectives; + protected static array $internalDirectives = []; public string $name; @@ -90,7 +90,11 @@ public static function includeDirective(): Directive */ public static function getInternalDirectives(): array { - return self::$internalDirectives ??= [ + if (self::$internalDirectives !== []) { + return self::$internalDirectives; + } + + return self::$internalDirectives = [ 'include' => new self([ 'name' => self::INCLUDE_NAME, 'description' => 'Directs the executor to include this field or fragment only when the `if` argument is true.', @@ -162,4 +166,9 @@ public static function isSpecifiedDirective(Directive $directive): bool { return \array_key_exists($directive->name, self::getInternalDirectives()); } + + public static function reset(): void + { + self::$internalDirectives = []; + } } diff --git a/src/Type/Definition/Type.php b/src/Type/Definition/Type.php index cd734b99c..e757e7d32 100644 --- a/src/Type/Definition/Type.php +++ b/src/Type/Definition/Type.php @@ -31,7 +31,7 @@ abstract class Type implements \JsonSerializable ]; /** @var array */ - protected static array $standardTypes; + protected static array $standardTypes = []; /** * @api @@ -261,4 +261,9 @@ public function jsonSerialize(): string { return $this->toString(); } + + public static function reset(): void + { + static::$standardTypes = []; + } } diff --git a/tests/Type/Definition/TypeTest.php b/tests/Type/Definition/TypeTest.php new file mode 100644 index 000000000..b123a26aa --- /dev/null +++ b/tests/Type/Definition/TypeTest.php @@ -0,0 +1,19 @@ +isDeprecated()); } + public function testReset(): void + { + $directives = Directive::getInternalDirectives(); + + Directive::reset(); + + self::assertNotSame($directives, Directive::getInternalDirectives()); + } + // TODO implement all of https://github.com/graphql/graphql-js/blob/master/src/type/__tests__/directive-test.js }