diff --git a/packages/graphql/src/Builder/Contracts/TypeSource.php b/packages/graphql/src/Builder/Contracts/TypeSource.php index 30d4c3744..e1ca1a83b 100644 --- a/packages/graphql/src/Builder/Contracts/TypeSource.php +++ b/packages/graphql/src/Builder/Contracts/TypeSource.php @@ -2,19 +2,17 @@ namespace LastDragon_ru\LaraASP\GraphQL\Builder\Contracts; -use GraphQL\Language\AST\ListTypeNode; -use GraphQL\Language\AST\NamedTypeNode; use GraphQL\Language\AST\Node; -use GraphQL\Language\AST\NonNullTypeNode; use GraphQL\Language\AST\TypeDefinitionNode; +use GraphQL\Language\AST\TypeNode; use GraphQL\Type\Definition\Type; use Stringable; interface TypeSource extends Stringable { /** - * @return (TypeDefinitionNode&Node)|NamedTypeNode|ListTypeNode|NonNullTypeNode|Type + * @return (TypeDefinitionNode&Node)|(TypeNode&Node)|Type */ - public function getType(): TypeDefinitionNode|NamedTypeNode|ListTypeNode|NonNullTypeNode|Type; + public function getType(): TypeDefinitionNode|TypeNode|Type; public function getTypeName(): string; diff --git a/packages/graphql/src/Builder/Sources/InputFieldSource.php b/packages/graphql/src/Builder/Sources/InputFieldSource.php index da67a2721..b1a460420 100644 --- a/packages/graphql/src/Builder/Sources/InputFieldSource.php +++ b/packages/graphql/src/Builder/Sources/InputFieldSource.php @@ -6,9 +6,8 @@ use GraphQL\Language\AST\ArgumentNode; use GraphQL\Language\AST\InputObjectTypeDefinitionNode; use GraphQL\Language\AST\InputValueDefinitionNode; -use GraphQL\Language\AST\ListTypeNode; -use GraphQL\Language\AST\NamedTypeNode; -use GraphQL\Language\AST\NonNullTypeNode; +use GraphQL\Language\AST\Node; +use GraphQL\Language\AST\TypeNode; use GraphQL\Type\Definition\Argument; use GraphQL\Type\Definition\InputObjectField; use GraphQL\Type\Definition\InputObjectType; @@ -17,19 +16,23 @@ use LastDragon_ru\LaraASP\GraphQL\Utils\AstManipulator; /** - * @extends Source + * @extends Source<(TypeNode&Node)|Type, InputSource> */ class InputFieldSource extends Source { use Field; + /** + * @param (TypeNode&Node)|Type|null $type + */ public function __construct( AstManipulator $manipulator, InputSource $parent, private InputValueDefinitionNode|InputObjectField $field, + TypeNode|Type|null $type = null, ) { parent::__construct( $manipulator, - $field instanceof InputObjectField ? $field->getType() : $field->type, + $type ?? ($field instanceof InputObjectField ? $field->getType() : $field->type), $parent, ); } diff --git a/packages/graphql/src/Builder/Sources/InputSource.php b/packages/graphql/src/Builder/Sources/InputSource.php index 233267c34..d682b1a08 100644 --- a/packages/graphql/src/Builder/Sources/InputSource.php +++ b/packages/graphql/src/Builder/Sources/InputSource.php @@ -4,14 +4,23 @@ use GraphQL\Language\AST\InputObjectTypeDefinitionNode; use GraphQL\Language\AST\InputValueDefinitionNode; +use GraphQL\Language\AST\Node; +use GraphQL\Language\AST\TypeNode; use GraphQL\Type\Definition\InputObjectField; use GraphQL\Type\Definition\InputObjectType; +use GraphQL\Type\Definition\Type; /** * @extends Source */ class InputSource extends Source { - public function getField(InputValueDefinitionNode|InputObjectField $field): InputFieldSource { - return new InputFieldSource($this->getManipulator(), $this, $field); + /** + * @param (TypeNode&Node)|Type|null $type + */ + public function getField( + InputValueDefinitionNode|InputObjectField $field, + TypeNode|Type $type = null, + ): InputFieldSource { + return new InputFieldSource($this->getManipulator(), $this, $field, $type); } } diff --git a/packages/graphql/src/Builder/Sources/InterfaceFieldArgumentSource.php b/packages/graphql/src/Builder/Sources/InterfaceFieldArgumentSource.php index 5eda800cd..1b9a8c12b 100644 --- a/packages/graphql/src/Builder/Sources/InterfaceFieldArgumentSource.php +++ b/packages/graphql/src/Builder/Sources/InterfaceFieldArgumentSource.php @@ -5,9 +5,8 @@ use GraphQL\Language\AST\FieldDefinitionNode; use GraphQL\Language\AST\InputValueDefinitionNode; use GraphQL\Language\AST\InterfaceTypeDefinitionNode; -use GraphQL\Language\AST\ListTypeNode; -use GraphQL\Language\AST\NamedTypeNode; -use GraphQL\Language\AST\NonNullTypeNode; +use GraphQL\Language\AST\Node; +use GraphQL\Language\AST\TypeNode; use GraphQL\Type\Definition\Argument; use GraphQL\Type\Definition\FieldDefinition; use GraphQL\Type\Definition\InterfaceType; @@ -16,19 +15,23 @@ use LastDragon_ru\LaraASP\GraphQL\Utils\AstManipulator; /** - * @extends Source + * @extends Source<(TypeNode&Node)|Type, InterfaceFieldSource> */ class InterfaceFieldArgumentSource extends Source { use FieldArgument; + /** + * @param (TypeNode&Node)|Type|null $type + */ public function __construct( AstManipulator $manipulator, InterfaceFieldSource $parent, private InputValueDefinitionNode|Argument $argument, + TypeNode|Type|null $type = null, ) { parent::__construct( $manipulator, - $argument instanceof Argument ? $argument->getType() : $argument->type, + $type ?? ($argument instanceof Argument ? $argument->getType() : $argument->type), $parent, ); } diff --git a/packages/graphql/src/Builder/Sources/InterfaceFieldSource.php b/packages/graphql/src/Builder/Sources/InterfaceFieldSource.php index 1e10a7dd9..9672aaca4 100644 --- a/packages/graphql/src/Builder/Sources/InterfaceFieldSource.php +++ b/packages/graphql/src/Builder/Sources/InterfaceFieldSource.php @@ -5,9 +5,8 @@ use GraphQL\Language\AST\FieldDefinitionNode; use GraphQL\Language\AST\InputValueDefinitionNode; use GraphQL\Language\AST\InterfaceTypeDefinitionNode; -use GraphQL\Language\AST\ListTypeNode; -use GraphQL\Language\AST\NamedTypeNode; -use GraphQL\Language\AST\NonNullTypeNode; +use GraphQL\Language\AST\Node; +use GraphQL\Language\AST\TypeNode; use GraphQL\Type\Definition\Argument; use GraphQL\Type\Definition\FieldDefinition; use GraphQL\Type\Definition\InterfaceType; @@ -16,19 +15,23 @@ use LastDragon_ru\LaraASP\GraphQL\Utils\AstManipulator; /** - * @extends Source + * @extends Source<(TypeNode&Node)|Type, InterfaceSource> */ class InterfaceFieldSource extends Source { use Field; + /** + * @param (TypeNode&Node)|Type|null $type + */ public function __construct( AstManipulator $manipulator, InterfaceSource $parent, private FieldDefinitionNode|FieldDefinition $field, + TypeNode|Type|null $type, ) { parent::__construct( $manipulator, - $field instanceof FieldDefinition ? $field->getType() : $field->type, + $type ?? ($field instanceof FieldDefinition ? $field->getType() : $field->type), $parent, ); } @@ -46,8 +49,14 @@ public function getField(): FieldDefinition|FieldDefinitionNode { // // ================================================================================================================= - public function getArgument(InputValueDefinitionNode|Argument $argument): InterfaceFieldArgumentSource { - return new InterfaceFieldArgumentSource($this->getManipulator(), $this, $argument); + /** + * @param (TypeNode&Node)|Type|null $type + */ + public function getArgument( + InputValueDefinitionNode|Argument $argument, + TypeNode|Type $type = null, + ): InterfaceFieldArgumentSource { + return new InterfaceFieldArgumentSource($this->getManipulator(), $this, $argument, $type); } // } diff --git a/packages/graphql/src/Builder/Sources/InterfaceSource.php b/packages/graphql/src/Builder/Sources/InterfaceSource.php index dae936201..d38d5ed21 100644 --- a/packages/graphql/src/Builder/Sources/InterfaceSource.php +++ b/packages/graphql/src/Builder/Sources/InterfaceSource.php @@ -4,14 +4,23 @@ use GraphQL\Language\AST\FieldDefinitionNode; use GraphQL\Language\AST\InterfaceTypeDefinitionNode; +use GraphQL\Language\AST\Node; +use GraphQL\Language\AST\TypeNode; use GraphQL\Type\Definition\FieldDefinition; use GraphQL\Type\Definition\InterfaceType; +use GraphQL\Type\Definition\Type; /** * @extends Source */ class InterfaceSource extends Source { - public function getField(FieldDefinitionNode|FieldDefinition $field): InterfaceFieldSource { - return new InterfaceFieldSource($this->getManipulator(), $this, $field); + /** + * @param (TypeNode&Node)|Type|null $type + */ + public function getField( + FieldDefinitionNode|FieldDefinition $field, + TypeNode|Type $type = null, + ): InterfaceFieldSource { + return new InterfaceFieldSource($this->getManipulator(), $this, $field, $type); } } diff --git a/packages/graphql/src/Builder/Sources/ObjectFieldArgumentSource.php b/packages/graphql/src/Builder/Sources/ObjectFieldArgumentSource.php index f6f4f8f49..e7dcce0a6 100644 --- a/packages/graphql/src/Builder/Sources/ObjectFieldArgumentSource.php +++ b/packages/graphql/src/Builder/Sources/ObjectFieldArgumentSource.php @@ -4,10 +4,9 @@ use GraphQL\Language\AST\FieldDefinitionNode; use GraphQL\Language\AST\InputValueDefinitionNode; -use GraphQL\Language\AST\ListTypeNode; -use GraphQL\Language\AST\NamedTypeNode; -use GraphQL\Language\AST\NonNullTypeNode; +use GraphQL\Language\AST\Node; use GraphQL\Language\AST\ObjectTypeDefinitionNode; +use GraphQL\Language\AST\TypeNode; use GraphQL\Type\Definition\Argument; use GraphQL\Type\Definition\FieldDefinition; use GraphQL\Type\Definition\ObjectType; @@ -16,19 +15,23 @@ use LastDragon_ru\LaraASP\GraphQL\Utils\AstManipulator; /** - * @extends Source + * @extends Source<(TypeNode&Node)|Type, ObjectFieldSource> */ class ObjectFieldArgumentSource extends Source { use FieldArgument; + /** + * @param (TypeNode&Node)|Type|null $type + */ public function __construct( AstManipulator $manipulator, ObjectFieldSource $parent, private InputValueDefinitionNode|Argument $argument, + TypeNode|Type|null $type = null, ) { parent::__construct( $manipulator, - $argument instanceof Argument ? $argument->getType() : $argument->type, + $type ?? ($argument instanceof Argument ? $argument->getType() : $argument->type), $parent, ); } diff --git a/packages/graphql/src/Builder/Sources/ObjectFieldSource.php b/packages/graphql/src/Builder/Sources/ObjectFieldSource.php index e5c22b09f..34d139cf3 100644 --- a/packages/graphql/src/Builder/Sources/ObjectFieldSource.php +++ b/packages/graphql/src/Builder/Sources/ObjectFieldSource.php @@ -4,10 +4,9 @@ use GraphQL\Language\AST\FieldDefinitionNode; use GraphQL\Language\AST\InputValueDefinitionNode; -use GraphQL\Language\AST\ListTypeNode; -use GraphQL\Language\AST\NamedTypeNode; -use GraphQL\Language\AST\NonNullTypeNode; +use GraphQL\Language\AST\Node; use GraphQL\Language\AST\ObjectTypeDefinitionNode; +use GraphQL\Language\AST\TypeNode; use GraphQL\Type\Definition\Argument; use GraphQL\Type\Definition\FieldDefinition; use GraphQL\Type\Definition\ObjectType; @@ -16,19 +15,23 @@ use LastDragon_ru\LaraASP\GraphQL\Utils\AstManipulator; /** - * @extends Source + * @extends Source<(TypeNode&Node)|Type, ObjectSource> */ class ObjectFieldSource extends Source { use Field; + /** + * @param (TypeNode&Node)|Type|null $type + */ public function __construct( AstManipulator $manipulator, ObjectSource $parent, private FieldDefinitionNode|FieldDefinition $field, + TypeNode|Type|null $type = null, ) { parent::__construct( $manipulator, - $field instanceof FieldDefinition ? $field->getType() : $field->type, + $type ?? ($field instanceof FieldDefinition ? $field->getType() : $field->type), $parent, ); } @@ -46,8 +49,14 @@ public function getField(): FieldDefinition|FieldDefinitionNode { // // ================================================================================================================= - public function getArgument(InputValueDefinitionNode|Argument $argument): ObjectFieldArgumentSource { - return new ObjectFieldArgumentSource($this->getManipulator(), $this, $argument); + /** + * @param (TypeNode&Node)|Type|null $type + */ + public function getArgument( + InputValueDefinitionNode|Argument $argument, + TypeNode|Type $type = null, + ): ObjectFieldArgumentSource { + return new ObjectFieldArgumentSource($this->getManipulator(), $this, $argument, $type); } // } diff --git a/packages/graphql/src/Builder/Sources/ObjectSource.php b/packages/graphql/src/Builder/Sources/ObjectSource.php index dfcbaebf6..8bc080d45 100644 --- a/packages/graphql/src/Builder/Sources/ObjectSource.php +++ b/packages/graphql/src/Builder/Sources/ObjectSource.php @@ -3,15 +3,24 @@ namespace LastDragon_ru\LaraASP\GraphQL\Builder\Sources; use GraphQL\Language\AST\FieldDefinitionNode; +use GraphQL\Language\AST\Node; use GraphQL\Language\AST\ObjectTypeDefinitionNode; +use GraphQL\Language\AST\TypeNode; use GraphQL\Type\Definition\FieldDefinition; use GraphQL\Type\Definition\ObjectType; +use GraphQL\Type\Definition\Type; /** * @extends Source */ class ObjectSource extends Source { - public function getField(FieldDefinitionNode|FieldDefinition $field): ObjectFieldSource { - return new ObjectFieldSource($this->getManipulator(), $this, $field); + /** + * @param (TypeNode&Node)|Type|null $type + */ + public function getField( + FieldDefinitionNode|FieldDefinition $field, + TypeNode|Type $type = null, + ): ObjectFieldSource { + return new ObjectFieldSource($this->getManipulator(), $this, $field, $type); } } diff --git a/packages/graphql/src/Builder/Sources/Source.php b/packages/graphql/src/Builder/Sources/Source.php index be989267a..44342a89a 100644 --- a/packages/graphql/src/Builder/Sources/Source.php +++ b/packages/graphql/src/Builder/Sources/Source.php @@ -2,18 +2,16 @@ namespace LastDragon_ru\LaraASP\GraphQL\Builder\Sources; -use GraphQL\Language\AST\ListTypeNode; -use GraphQL\Language\AST\NamedTypeNode; use GraphQL\Language\AST\Node; -use GraphQL\Language\AST\NonNullTypeNode; use GraphQL\Language\AST\TypeDefinitionNode; +use GraphQL\Language\AST\TypeNode; use GraphQL\Type\Definition\Type; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\TypeSource; use LastDragon_ru\LaraASP\GraphQL\Utils\AstManipulator; use Override; /** - * @template TType of (TypeDefinitionNode&Node)|NamedTypeNode|ListTypeNode|NonNullTypeNode|Type + * @template TType of (TypeDefinitionNode&Node)|(TypeNode&Node)|Type * @template TParent of TypeSource|null */ class Source implements TypeSource { @@ -23,7 +21,7 @@ class Source implements TypeSource { */ public function __construct( private AstManipulator $manipulator, - private TypeDefinitionNode|Node|Type $type, + private TypeDefinitionNode|TypeNode|Type $type, private TypeSource|null $parent = null, ) { // empty @@ -49,7 +47,7 @@ public function getParent(): ?TypeSource { * @return TType */ #[Override] - public function getType(): TypeDefinitionNode|NamedTypeNode|ListTypeNode|NonNullTypeNode|Type { + public function getType(): TypeDefinitionNode|TypeNode|Type { return $this->type; }