diff --git a/packages/graphql/README.md b/packages/graphql/README.md index e31e7f3d1..18a9ab970 100644 --- a/packages/graphql/README.md +++ b/packages/graphql/README.md @@ -124,16 +124,16 @@ For Implicit type, the following rules are applied (in this order; concrete dire * Otherwise - include * Ignored (if supported)? - exclude -# Builder property name +# Builder field/column name -By default `@searchBy`/`@sortBy` will convert nested/related properties into dot string: eg `{user: {name: asc}}` will be converted into `user.name`. You can redefine this behavior by [`BuilderPropertyResolver`](./src/Builder/Contracts/BuilderPropertyResolver.php): +By default `@searchBy`/`@sortBy` will convert nested/related fields into dot string: eg `{user: {name: asc}}` will be converted into `user.name`. You can redefine this behavior by [`BuilderFieldResolver`](./src/Builder/Contracts/BuilderFieldResolver.php): ```php // AppProvider $this->app->bind( - LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\BuilderPropertyResolver::class, - MyBuilderPropertyResolver::class, + LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\BuilderFieldResolver::class, + MyBuilderFieldResolver::class, ); ``` @@ -349,7 +349,7 @@ on | SCALAR """ -Available conditions for `type User` (only one property allowed at a time). +Available conditions for `type User` (only one field allowed at a time). """ input SearchByConditionUser { """ diff --git a/packages/graphql/UPGRADE.md b/packages/graphql/UPGRADE.md index 95348e260..54ea3bdc6 100644 --- a/packages/graphql/UPGRADE.md +++ b/packages/graphql/UPGRADE.md @@ -91,7 +91,7 @@ Please also see [changelog](https://github.com/LastDragon-ru/lara-asp/releases) * [ ] If you are testing generated queries, you need to update `sort_by_*` alias to `lara_asp_graphql__sort_by__*`. -* [ ] If you are overriding Extra operators, you may need to add `SortByOperators::Extra` to use new built-in: +* [ ] If you are overriding Extra operators, you should to add `SortByOperators::Extra` to use new built-in: ```php $settings = [ @@ -106,7 +106,7 @@ Please also see [changelog](https://github.com/LastDragon-ru/lara-asp/releases) ]; ``` -* [ ] If you are using `LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Scout\FieldResolver`, use `LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\BuilderPropertyResolver` instead. 🤝 +* [ ] If you are using `LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Scout\FieldResolver`, use `LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\BuilderFieldResolver` instead. 🤝 * [ ] Added the root type that will contain only extra operators and newly added `field` operator (always present and cannot be removed). The new query syntax is: @@ -133,6 +133,8 @@ Please also see [changelog](https://github.com/LastDragon-ru/lara-asp/releases) ); ``` +* [ ] `@sortByOperatorRandom` cannot be added to `FIELD_DEFINITION` anymore. + ## API This section is actual only if you are extending the package. Please review and update (listed the most significant changes only): @@ -147,19 +149,23 @@ This section is actual only if you are extending the package. Please review and * [ ] `LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\TypeSource` +* [ ] `LastDragon_ru\LaraASP\GraphQL\Builder\Exceptions\Client\ConditionTooManyProperties` => `LastDragon_ru\LaraASP\GraphQL\Builder\Exceptions\Client\ConditionTooManyFields` + +* [ ] `LastDragon_ru\LaraASP\GraphQL\Builder\Property` => `LastDragon_ru\LaraASP\GraphQL\Builder\Field` + * [ ] `LastDragon_ru\LaraASP\GraphQL\Builder\Manipulator` - * [ ] Removed `BuilderInfo`. To get `BuilderInfo` instance within Operator the `LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Context` should be used instead + * [ ] `BuilderInfo` removed. To get `BuilderInfo` instance within Operator the `LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Context` should be used instead ```php $context->get(LastDragon_ru\LaraASP\GraphQL\Builder\Context\HandlerContextBuilderInfo::class)?->value ``` - * [ ] Removed `getPlaceholderTypeDefinitionNode()` => `LastDragon_ru\LaraASP\GraphQL\Utils\AstManipulator::getOriginType()` + * [ ] `getPlaceholderTypeDefinitionNode()` removed => `LastDragon_ru\LaraASP\GraphQL\Utils\AstManipulator::getOriginType()` * [ ] `LastDragon_ru\LaraASP\GraphQL\Builder\Directives\HandlerDirective` -* [ ] Removed `LastDragon_ru\LaraASP\GraphQL\Builder\Directives\PropertyDirective` +* [ ] `LastDragon_ru\LaraASP\GraphQL\Builder\Directives\PropertyDirective` removed * [ ] `LastDragon_ru\LaraASP\GraphQL\Builder\Sources\*` diff --git a/packages/graphql/src/Builder/Contracts/BuilderFieldResolver.php b/packages/graphql/src/Builder/Contracts/BuilderFieldResolver.php new file mode 100644 index 000000000..7ccde9144 --- /dev/null +++ b/packages/graphql/src/Builder/Contracts/BuilderFieldResolver.php @@ -0,0 +1,12 @@ +resolver - ? $this->resolver->getField($builder->model, $property) - : implode('.', $property->getPath()); + ? $this->resolver->getField($builder->model, new Property(...$field->getPath())) + : implode('.', $field->getPath()); } } diff --git a/packages/graphql/src/Builder/Directives/HandlerDirective.php b/packages/graphql/src/Builder/Directives/HandlerDirective.php index f1dcf7529..b319c41fd 100644 --- a/packages/graphql/src/Builder/Directives/HandlerDirective.php +++ b/packages/graphql/src/Builder/Directives/HandlerDirective.php @@ -24,11 +24,11 @@ use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Operator; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Scope; use LastDragon_ru\LaraASP\GraphQL\Builder\Exceptions\Client\ConditionEmpty; +use LastDragon_ru\LaraASP\GraphQL\Builder\Exceptions\Client\ConditionTooManyFields; use LastDragon_ru\LaraASP\GraphQL\Builder\Exceptions\Client\ConditionTooManyOperators; -use LastDragon_ru\LaraASP\GraphQL\Builder\Exceptions\Client\ConditionTooManyProperties; use LastDragon_ru\LaraASP\GraphQL\Builder\Exceptions\HandlerInvalidConditions; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\Builder\Manipulator; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; use LastDragon_ru\LaraASP\GraphQL\Builder\Sources\InterfaceFieldArgumentSource; use LastDragon_ru\LaraASP\GraphQL\Builder\Sources\ObjectFieldArgumentSource; use LastDragon_ru\LaraASP\GraphQL\Builder\Traits\WithManipulator; @@ -107,7 +107,7 @@ protected function handleAnyBuilder(object $builder, mixed $value, ContextContra foreach ($conditions as $condition) { if ($condition instanceof ArgumentSet) { - $builder = $this->handle($builder, new Property(), $condition, $context ?? new Context()); + $builder = $this->handle($builder, new Field(), $condition, $context ?? new Context()); } else { throw new HandlerInvalidConditions($this); } @@ -127,7 +127,7 @@ protected function handleAnyBuilder(object $builder, mixed $value, ContextContra #[Override] public function handle( object $builder, - Property $property, + Field $field, ArgumentSet $conditions, ContextContract $context, ): object { @@ -138,13 +138,13 @@ public function handle( // Valid? if (count($conditions->arguments) !== 1) { - throw new ConditionTooManyProperties( + throw new ConditionTooManyFields( ArgumentFactory::getArgumentsNames($conditions), ); } // Call - return $this->call($builder, $property, $conditions, $context); + return $this->call($builder, $field, $conditions, $context); } /** @@ -156,7 +156,7 @@ public function handle( */ protected function call( object $builder, - Property $property, + Field $field, ArgumentSet $operator, ContextContract $context, ): object { @@ -180,9 +180,9 @@ protected function call( } } - $property = $property->getChild($name); - $value = $argument; - $op = reset($operators); + $field = $field->getChild($name); + $value = $argument; + $op = reset($operators); if (count($operators) > 1) { throw new ConditionTooManyOperators( @@ -202,7 +202,7 @@ static function (Operator $operator): string { } // Return - return $op->call($this, $builder, $property, $value, $context); + return $op->call($this, $builder, $field, $value, $context); } // @@ -264,10 +264,9 @@ protected function getArgumentTypeDefinitionNode( string $operator, ): ListTypeNode|NamedTypeNode|NonNullTypeNode|null { // Supported? - $operator = $manipulator->getOperator(static::getScope(), $operator); - $builder = $context->get(HandlerContextBuilderInfo::class)?->value->getBuilder(); + $operator = $manipulator->getOperator($operator, static::getScope(), $argument, $context); - if (!$builder || !$operator->isAvailable($builder, $context)) { + if (!$operator) { return null; } @@ -277,7 +276,7 @@ protected function getArgumentTypeDefinitionNode( : $argument->getTypeDefinition(); $source = $manipulator->getTypeSource($definition); $type = $operator->getFieldType($manipulator, $source, $context); - $type = Parser::typeReference($type); + $type = $type ? Parser::typeReference($type) : null; return $type; } diff --git a/packages/graphql/src/Builder/Directives/OperatorDirective.php b/packages/graphql/src/Builder/Directives/OperatorDirective.php index 62cfff346..2bc0a40c9 100644 --- a/packages/graphql/src/Builder/Directives/OperatorDirective.php +++ b/packages/graphql/src/Builder/Directives/OperatorDirective.php @@ -3,19 +3,23 @@ namespace LastDragon_ru\LaraASP\GraphQL\Builder\Directives; use GraphQL\Language\DirectiveLocation; -use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\BuilderPropertyResolver; +use LastDragon_ru\LaraASP\GraphQL\Builder\Context\HandlerContextBuilderInfo; +use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\BuilderFieldResolver; +use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Context; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Operator; -use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Scope; +use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\TypeProvider; +use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\TypeSource; use Nuwave\Lighthouse\Schema\DirectiveLocator; use Nuwave\Lighthouse\Schema\Directives\BaseDirective; use Override; +use function array_merge; +use function array_unique; use function implode; -use function is_a; abstract class OperatorDirective extends BaseDirective implements Operator { public function __construct( - protected readonly BuilderPropertyResolver $resolver, + protected readonly BuilderFieldResolver $resolver, ) { // empty } @@ -23,7 +27,18 @@ public function __construct( #[Override] public static function definition(): string { $name = '@'.DirectiveLocator::directiveName(static::class); - $locations = implode('|', static::getDirectiveLocations()); + $locations = implode( + ' | ', + array_unique( + array_merge( + static::getDirectiveLocations(), + [ + // Location is mandatory to be able to call the operator + DirectiveLocation::INPUT_FIELD_DEFINITION, + ], + ), + ), + ); return << */ protected static function getDirectiveLocations(): array { - $locations = [ - DirectiveLocation::INPUT_FIELD_DEFINITION, + return [ + // Locations are required to be able to add operators inside the schema + DirectiveLocation::SCALAR, + DirectiveLocation::ENUM, ]; + } + + #[Override] + public function isAvailable(TypeProvider $provider, TypeSource $source, Context $context): bool { + // Builder? + $builder = $context->get(HandlerContextBuilderInfo::class)?->value->getBuilder(); - if (is_a(static::class, Scope::class, true)) { - $locations[] = DirectiveLocation::SCALAR; - $locations[] = DirectiveLocation::ENUM; + if (!$builder || !$this->isBuilderSupported($builder)) { + return false; } - return $locations; + // Ok + return true; } + + /** + * @param class-string $builder + */ + abstract protected function isBuilderSupported(string $builder): bool; } diff --git a/packages/graphql/src/Builder/Directives/OperatorsDirective.php b/packages/graphql/src/Builder/Directives/OperatorsDirective.php index 7abdbfe60..8a45007cf 100644 --- a/packages/graphql/src/Builder/Directives/OperatorsDirective.php +++ b/packages/graphql/src/Builder/Directives/OperatorsDirective.php @@ -7,6 +7,7 @@ use Nuwave\Lighthouse\Schema\Directives\BaseDirective; use Override; +use function array_unique; use function assert; use function implode; use function is_string; @@ -19,7 +20,7 @@ public function __construct() { #[Override] public static function definition(): string { $name = DirectiveLocator::directiveName(static::class); - $locations = implode(' | ', static::getDirectiveLocations()); + $locations = implode(' | ', array_unique(static::getDirectiveLocations())); return << $fields + */ + public function __construct( + protected readonly array $fields, + Throwable $previous = null, + ) { + parent::__construct( + sprintf( + 'Only one field allowed, found: `%s`.', + implode('`, `', Arr::sort($this->getFields())), + ), + $previous, + ); + } + + /** + * @return list + */ + public function getFields(): array { + return $this->fields; + } +} diff --git a/packages/graphql/src/Builder/Exceptions/Client/ConditionTooManyOperators.php b/packages/graphql/src/Builder/Exceptions/Client/ConditionTooManyOperators.php index 51c409f99..60cad713d 100644 --- a/packages/graphql/src/Builder/Exceptions/Client/ConditionTooManyOperators.php +++ b/packages/graphql/src/Builder/Exceptions/Client/ConditionTooManyOperators.php @@ -2,6 +2,7 @@ namespace LastDragon_ru\LaraASP\GraphQL\Builder\Exceptions\Client; +use Illuminate\Support\Arr; use Throwable; use function implode; @@ -15,10 +16,13 @@ public function __construct( protected array $operators, Throwable $previous = null, ) { - parent::__construct(sprintf( - 'Only one operator allowed, found: `%s`.', - implode('`, `', $this->getOperators()), - ), $previous); + parent::__construct( + sprintf( + 'Only one operator allowed, found: `%s`.', + implode('`, `', Arr::sort($this->getOperators())), + ), + $previous, + ); } /** diff --git a/packages/graphql/src/Builder/Exceptions/Client/ConditionTooManyProperties.php b/packages/graphql/src/Builder/Exceptions/Client/ConditionTooManyProperties.php deleted file mode 100644 index e0348b4ad..000000000 --- a/packages/graphql/src/Builder/Exceptions/Client/ConditionTooManyProperties.php +++ /dev/null @@ -1,30 +0,0 @@ - $properties - */ - public function __construct( - protected array $properties, - Throwable $previous = null, - ) { - parent::__construct(sprintf( - 'Only one property allowed, found: `%s`.', - implode('`, `', $this->getProperties()), - ), $previous); - } - - /** - * @return list - */ - public function getProperties(): array { - return $this->properties; - } -} diff --git a/packages/graphql/src/Builder/Exceptions/OperatorImpossibleToCreateField.php b/packages/graphql/src/Builder/Exceptions/OperatorImpossibleToCreateField.php new file mode 100644 index 000000000..d8d13434a --- /dev/null +++ b/packages/graphql/src/Builder/Exceptions/OperatorImpossibleToCreateField.php @@ -0,0 +1,40 @@ +operator::class, + $this->source, + ), + $previous, + ); + } + + public function getOperator(): Operator { + return $this->operator; + } + + public function getSource(): Stringable|string { + return $this->source; + } + + public function getContext(): Context { + return $this->context; + } +} diff --git a/packages/graphql/src/Builder/Field.php b/packages/graphql/src/Builder/Field.php new file mode 100644 index 000000000..c35aeb109 --- /dev/null +++ b/packages/graphql/src/Builder/Field.php @@ -0,0 +1,42 @@ + + */ + protected array $path; + + final public function __construct( + string ...$path, + ) { + $this->path = array_values($path); + } + + public function getName(): string { + return end($this->path) ?: ''; + } + + /** + * @return array + */ + public function getPath(): array { + return $this->path; + } + + public function getChild(string $name): static { + return new static(...$this->path, ...[$name]); + } + + public function getParent(): static { + $path = array_slice($this->path, 0, -1); + $parent = new static(...$path); + + return $parent; + } +} diff --git a/packages/graphql/src/Builder/Manipulator.php b/packages/graphql/src/Builder/Manipulator.php index 11a3cda9f..1d85cd319 100644 --- a/packages/graphql/src/Builder/Manipulator.php +++ b/packages/graphql/src/Builder/Manipulator.php @@ -5,11 +5,9 @@ use GraphQL\Language\AST\DirectiveNode; use GraphQL\Language\AST\InputObjectTypeDefinitionNode; use GraphQL\Language\AST\InterfaceTypeDefinitionNode; -use GraphQL\Language\AST\ListTypeNode; -use GraphQL\Language\AST\NamedTypeNode; -use GraphQL\Language\AST\NonNullTypeNode; use GraphQL\Language\AST\ObjectTypeDefinitionNode; use GraphQL\Language\AST\TypeDefinitionNode; +use GraphQL\Language\AST\TypeNode; use GraphQL\Language\BlockString; use GraphQL\Language\Parser; use GraphQL\Language\Printer; @@ -18,8 +16,8 @@ use GraphQL\Type\Definition\ObjectType; use GraphQL\Type\Definition\Type; use Illuminate\Container\Container; -use LastDragon_ru\LaraASP\GraphQL\Builder\Context\HandlerContextBuilderInfo; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Context; +use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Ignored; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Operator; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Scope; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\TypeProvider; @@ -27,6 +25,7 @@ use LastDragon_ru\LaraASP\GraphQL\Builder\Directives\OperatorsDirective; use LastDragon_ru\LaraASP\GraphQL\Builder\Exceptions\FakeTypeDefinitionIsNotFake; use LastDragon_ru\LaraASP\GraphQL\Builder\Exceptions\FakeTypeDefinitionUnknown; +use LastDragon_ru\LaraASP\GraphQL\Builder\Exceptions\OperatorImpossibleToCreateField; use LastDragon_ru\LaraASP\GraphQL\Builder\Exceptions\TypeDefinitionImpossibleToCreateType; use LastDragon_ru\LaraASP\GraphQL\Builder\Exceptions\TypeDefinitionInvalidTypeName; use LastDragon_ru\LaraASP\GraphQL\Builder\Sources\InputSource; @@ -85,9 +84,7 @@ public function getType(string $definition, TypeSource $source, Context $context } #[Override] - public function getTypeSource( - TypeDefinitionNode|NamedTypeNode|ListTypeNode|NonNullTypeNode|Type $type, - ): TypeSource { + public function getTypeSource(TypeDefinitionNode|TypeNode|Type $type): TypeSource { $source = null; if ($type instanceof InputObjectTypeDefinitionNode || $type instanceof InputObjectType) { @@ -115,13 +112,28 @@ public function addOperators(Operators $operators): static { /** * @template T of Operator * - * @param class-string $scope * @param class-string $operator + * @param class-string $scope * - * @return T + * @return T|null */ - public function getOperator(string $scope, string $operator): Operator { - return Container::getInstance()->make($operator); + public function getOperator(string $operator, string $scope, TypeSource $source, Context $context): ?Operator { + // Provider? + $provider = $this->operators[$scope] ?? null; + + if (!$provider) { + return null; + } + + // Available? + $operator = $provider->getOperator($operator); + + if (!$operator->isAvailable($this, $source, $context)) { + return null; + } + + // Return + return $operator; } /** @@ -129,7 +141,13 @@ public function getOperator(string $scope, string $operator): Operator { * * @return list */ - public function getTypeOperators(string $scope, string $type, Context $context, string ...$extras): array { + public function getTypeOperators( + string $type, + string $scope, + TypeSource $source, + Context $context, + string ...$extras, + ): array { // Provider? $provider = $this->operators[$scope] ?? null; @@ -137,40 +155,8 @@ public function getTypeOperators(string $scope, string $type, Context $context, return []; } - // Builder? - $builder = $context->get(HandlerContextBuilderInfo::class)?->value->getBuilder(); - - if (!$builder) { - return []; - } - // Operators - $operators = []; - - if ($this->isTypeDefinitionExists($type)) { - $node = $this->getTypeDefinition($type); - $directives = $this->getDirectives($node, $scope); - - foreach ($directives as $directive) { - if ($directive instanceof OperatorsDirective) { - $directiveType = $directive->getType(); - - if ($type !== $directiveType) { - array_push($operators, ...$this->getTypeOperators($scope, $directiveType, $context)); - } else { - array_push($operators, ...$provider->getOperators($type)); - } - } elseif ($directive instanceof Operator) { - $operators[] = $directive; - } else { - // empty - } - } - } - - if (!$operators && $provider->hasOperators($type)) { - array_push($operators, ...$provider->getOperators($type)); - } + $operators = $this->getOperators($provider, $scope, $type); if (!$operators) { return []; @@ -178,7 +164,7 @@ public function getTypeOperators(string $scope, string $type, Context $context, // Extra foreach ($extras as $extra) { - array_push($operators, ...$this->getTypeOperators($scope, $extra, $context)); + array_push($operators, ...$this->getOperators($provider, $scope, $extra)); } // Unique @@ -189,7 +175,7 @@ public function getTypeOperators(string $scope, string $type, Context $context, continue; } - if (!$operator->isAvailable($builder, $context)) { + if (!$operator->isAvailable($this, $source, $context)) { continue; } @@ -228,8 +214,14 @@ public function getOperatorField( array_unshift($directives, Parser::directive('@'.DirectiveLocator::directiveName($operator::class))); } + // Type? + $type = $operator->getFieldType($this, $source, $context); + + if (!$type) { + throw new OperatorImpossibleToCreateField($operator, $source, $context); + } + // Definition - $type = $operator->getFieldType($this, $source, $context); $field = $field ?: $operator::getName(); $directives = implode( "\n", @@ -239,7 +231,7 @@ public function getOperatorField( ), ); $description = $description ?: $operator->getFieldDescription(); - $description = BlockString::print($description); + $description = BlockString::print((string) $description); return <<removeTypeDefinition($name); } + + /** + * @param class-string $scope + * + * @return array + */ + private function getOperators(Operators $provider, string $scope, string $type): array { + $ignored = false; + $operators = []; + + if ($this->isTypeDefinitionExists($type)) { + $node = $this->getTypeDefinition($type); + $directives = $this->getDirectives($node); + + foreach ($directives as $directive) { + if (!($directive instanceof $scope)) { + continue; + } + + if ($directive instanceof OperatorsDirective) { + $directiveType = $directive->getType(); + + if ($type !== $directiveType) { + array_push($operators, ...$this->getOperators($provider, $scope, $directiveType)); + } else { + array_push($operators, ...$provider->getOperators($type)); + } + } elseif ($directive instanceof Operator) { + $operators[] = $directive; + } elseif ($directive instanceof Ignored) { + $ignored = true; + $operators = []; + break; + } else { + // empty + } + } + } + + if (!$operators && !$ignored && $provider->hasOperators($type)) { + array_push($operators, ...$provider->getOperators($type)); + } + + return $operators; + } // } diff --git a/packages/graphql/src/Builder/ManipulatorTest.php b/packages/graphql/src/Builder/ManipulatorTest.php index 6efb9437d..01ecc03a2 100644 --- a/packages/graphql/src/Builder/ManipulatorTest.php +++ b/packages/graphql/src/Builder/ManipulatorTest.php @@ -7,6 +7,7 @@ use LastDragon_ru\LaraASP\GraphQL\Builder\Context\HandlerContextBuilderInfo; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Context as ContextContract; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Handler; +use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Ignored; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Operator; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Scope; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\TypeProvider; @@ -14,9 +15,11 @@ use LastDragon_ru\LaraASP\GraphQL\Builder\Directives\OperatorDirective; use LastDragon_ru\LaraASP\GraphQL\Builder\Directives\OperatorsDirective; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\TestCase; +use Mockery; use Nuwave\Lighthouse\Execution\Arguments\Argument; use Nuwave\Lighthouse\Schema\AST\ASTBuilder; use Nuwave\Lighthouse\Schema\DirectiveLocator; +use Nuwave\Lighthouse\Schema\Directives\BaseDirective; use Nuwave\Lighthouse\Schema\TypeRegistry; use Override; use PHPUnit\Framework\Attributes\CoversClass; @@ -64,6 +67,7 @@ public function testGetTypeOperators(): void { // Directives $directives = Container::getInstance()->make(DirectiveLocator::class); + $directives->setResolved('ignored', ManipulatorTest_Ignored::class); $directives->setResolved('operators', ManipulatorTest_Operators::class); $directives->setResolved('aOperator', $aOperator); $directives->setResolved('bOperator', $bOperator); @@ -77,6 +81,10 @@ public function testGetTypeOperators(): void { @bOperator @cOperator + scalar TestIgnored + @aOperator + @ignored + scalar TestOperators @operators(type: "TestScalar") @@ -123,6 +131,7 @@ public function getScope(): string { }; // Manipulator + $source = Mockery::mock(TypeSource::class); $context = (new Context())->override([ HandlerContextBuilderInfo::class => new HandlerContextBuilderInfo( new BuilderInfo($builder::class, $builder::class), @@ -144,7 +153,7 @@ public function getScope(): string { [ $aOperator, ], - array_map($map, $manipulator->getTypeOperators($operators->getScope(), Operators::ID, $context)), + array_map($map, $manipulator->getTypeOperators(Operators::ID, $operators->getScope(), $source, $context)), ); self::assertEquals( [ @@ -153,33 +162,60 @@ public function getScope(): string { ], array_map( $map, - $manipulator->getTypeOperators($operators->getScope(), Operators::ID, $context, Operators::Int), + $manipulator->getTypeOperators( + Operators::ID, + $operators->getScope(), + $source, + $context, + Operators::Int, + ), ), ); self::assertEquals( [ // empty (another scope) ], - array_map($map, $manipulator->getTypeOperators($scope::class, Operators::ID, $context)), + array_map($map, $manipulator->getTypeOperators(Operators::ID, $scope::class, $source, $context)), ); self::assertEquals( [ $aOperator, ], - array_map($map, $manipulator->getTypeOperators($operators->getScope(), 'TestScalar', $context)), + array_map($map, $manipulator->getTypeOperators('TestScalar', $operators->getScope(), $source, $context)), ); self::assertEquals( [ $aOperator, ], - array_map($map, $manipulator->getTypeOperators($operators->getScope(), 'TestOperators', $context)), + array_map($map, $manipulator->getTypeOperators('TestOperators', $operators->getScope(), $source, $context)), ); self::assertEquals( [ $cOperator, $aOperator, ], - array_map($map, $manipulator->getTypeOperators($operators->getScope(), 'TestBuiltinOperators', $context)), + array_map( + $map, + $manipulator->getTypeOperators('TestBuiltinOperators', $operators->getScope(), $source, $context), + ), + ); + self::assertEquals( + [ + // empty + ], + array_map( + $map, + $manipulator->getTypeOperators('Unknown', $operators->getScope(), $source, $context, Operators::ID), + ), + ); + self::assertEquals( + [ + // empty + ], + array_map( + $map, + $manipulator->getTypeOperators('TestIgnored', $operators->getScope(), $source, $context), + ), ); } // @@ -207,17 +243,17 @@ public static function getName(): string { } #[Override] - public function getFieldType(TypeProvider $provider, TypeSource $source, ContextContract $context): string { + public function getFieldType(TypeProvider $provider, TypeSource $source, ContextContract $context): ?string { return $source->getTypeName(); } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return ''; } #[Override] - public function isAvailable(string $builder, ContextContract $context): bool { + protected function isBuilderSupported(string $builder): bool { return is_a($builder, stdClass::class, true); } @@ -225,7 +261,7 @@ public function isAvailable(string $builder, ContextContract $context): bool { public function call( Handler $handler, object $builder, - Property $property, + Field $field, Argument $argument, ContextContract $context, ): object { @@ -244,17 +280,17 @@ public static function getName(): string { } #[Override] - public function getFieldType(TypeProvider $provider, TypeSource $source, ContextContract $context): string { + public function getFieldType(TypeProvider $provider, TypeSource $source, ContextContract $context): ?string { return $source->getTypeName(); } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return ''; } #[Override] - public function isAvailable(string $builder, ContextContract $context): bool { + protected function isBuilderSupported(string $builder): bool { return false; } @@ -262,7 +298,7 @@ public function isAvailable(string $builder, ContextContract $context): bool { public function call( Handler $handler, object $builder, - Property $property, + Field $field, Argument $argument, ContextContract $context, ): object { @@ -281,17 +317,17 @@ public static function getName(): string { } #[Override] - public function getFieldType(TypeProvider $provider, TypeSource $source, ContextContract $context): string { + public function getFieldType(TypeProvider $provider, TypeSource $source, ContextContract $context): ?string { return $source->getTypeName(); } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return ''; } #[Override] - public function isAvailable(string $builder, ContextContract $context): bool { + protected function isBuilderSupported(string $builder): bool { return is_a($builder, stdClass::class, true); } @@ -299,10 +335,23 @@ public function isAvailable(string $builder, ContextContract $context): bool { public function call( Handler $handler, object $builder, - Property $property, + Field $field, Argument $argument, ContextContract $context, ): object { return $builder; } } + +/** + * @internal + * @noinspection PhpMultipleClassesDeclarationsInOneFile + */ +class ManipulatorTest_Ignored extends BaseDirective implements Ignored, Scope { + #[Override] + public static function definition(): string { + return <<<'GRAPHQL' + directive @ignored on SCALAR + GRAPHQL; + } +} diff --git a/packages/graphql/src/Builder/OperatorsTest.php b/packages/graphql/src/Builder/OperatorsTest.php index d8d00832b..886f9fd2b 100644 --- a/packages/graphql/src/Builder/OperatorsTest.php +++ b/packages/graphql/src/Builder/OperatorsTest.php @@ -169,17 +169,17 @@ public static function getName(): string { } #[Override] - public function getFieldType(TypeProvider $provider, TypeSource $source, Context $context): string { + public function isAvailable(TypeProvider $provider, TypeSource $source, Context $context): bool { throw new Exception('Should not be called'); } #[Override] - public function getFieldDescription(): string { + public function getFieldType(TypeProvider $provider, TypeSource $source, Context $context): ?string { throw new Exception('Should not be called'); } #[Override] - public function isAvailable(string $builder, Context $context): bool { + public function getFieldDescription(): ?string { throw new Exception('Should not be called'); } @@ -187,7 +187,7 @@ public function isAvailable(string $builder, Context $context): bool { public function call( Handler $handler, object $builder, - Property $property, + Field $field, Argument $argument, Context $context, ): object { diff --git a/packages/graphql/src/Builder/Property.php b/packages/graphql/src/Builder/Property.php index ab3e7b132..7a1685eb5 100644 --- a/packages/graphql/src/Builder/Property.php +++ b/packages/graphql/src/Builder/Property.php @@ -2,41 +2,9 @@ namespace LastDragon_ru\LaraASP\GraphQL\Builder; -use function array_slice; -use function array_values; -use function end; - -class Property { - /** - * @var list - */ - protected array $path; - - final public function __construct( - string ...$path, - ) { - $this->path = array_values($path); - } - - public function getName(): string { - return end($this->path) ?: ''; - } - - /** - * @return array - */ - public function getPath(): array { - return $this->path; - } - - public function getChild(string $name): static { - return new static(...$this->path, ...[$name]); - } - - public function getParent(): static { - $path = array_slice($this->path, 0, -1); - $parent = new static(...$path); - - return $parent; - } +/** + * @deprecated 5.5.0 Please use {@see Field} instead. + */ +class Property extends Field { + // empty } diff --git a/packages/graphql/src/Builder/Traits/HandlerOperator.php b/packages/graphql/src/Builder/Traits/HandlerOperator.php index 36cc6b9a3..7751fec0d 100644 --- a/packages/graphql/src/Builder/Traits/HandlerOperator.php +++ b/packages/graphql/src/Builder/Traits/HandlerOperator.php @@ -6,10 +6,8 @@ use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Handler; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Operator; use LastDragon_ru\LaraASP\GraphQL\Builder\Exceptions\Client\ConditionEmpty; -use LastDragon_ru\LaraASP\GraphQL\Builder\Exceptions\Client\ConditionTooManyOperators; use LastDragon_ru\LaraASP\GraphQL\Builder\Exceptions\HandlerInvalidConditions; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; -use LastDragon_ru\LaraASP\GraphQL\Utils\ArgumentFactory; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use Nuwave\Lighthouse\Execution\Arguments\Argument; use Nuwave\Lighthouse\Execution\Arguments\ArgumentSet; use Override; @@ -24,11 +22,11 @@ trait HandlerOperator { public function call( Handler $handler, object $builder, - Property $property, + Field $field, Argument $argument, Context $context, ): object { - return $this->handle($handler, $builder, $property, $argument, $context); + return $this->handle($handler, $builder, $field, $argument, $context); } /** @@ -41,10 +39,11 @@ public function call( private function handle( Handler $handler, object $builder, - Property $property, + Field $field, Argument $argument, Context $context, ): object { + // Valid? if (!($argument->value instanceof ArgumentSet)) { throw new HandlerInvalidConditions($handler); } @@ -54,14 +53,7 @@ private function handle( throw new ConditionEmpty(); } - // Valid? - if (count($argument->value->arguments) > 1) { - throw new ConditionTooManyOperators( - ArgumentFactory::getArgumentsNames($argument->value), - ); - } - // Apply - return $handler->handle($builder, $property, $argument->value, $context); + return $handler->handle($builder, $field, $argument->value, $context); } } diff --git a/packages/graphql/src/Builder/Traits/WithScoutSupport.php b/packages/graphql/src/Builder/Traits/WithScoutSupport.php index d474a3cd4..9109f339f 100644 --- a/packages/graphql/src/Builder/Traits/WithScoutSupport.php +++ b/packages/graphql/src/Builder/Traits/WithScoutSupport.php @@ -5,19 +5,18 @@ use Composer\InstalledVersions; use Composer\Semver\VersionParser; use Laravel\Scout\Builder as ScoutBuilder; -use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Context; -use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Operator; +use LastDragon_ru\LaraASP\GraphQL\Builder\Directives\OperatorDirective; use Override; use function is_a; /** - * @mixin Operator + * @phpstan-require-extends OperatorDirective */ trait WithScoutSupport { #[Override] - public function isAvailable(string $builder, Context $context): bool { - return parent::isAvailable($builder, $context) + protected function isBuilderSupported(string $builder): bool { + return parent::isBuilderSupported($builder) || (is_a($builder, ScoutBuilder::class, true) && $this->isScoutSupported()); } diff --git a/packages/graphql/src/Builder/Types/InputObject.php b/packages/graphql/src/Builder/Types/InputObject.php index 30087014e..e0c517273 100644 --- a/packages/graphql/src/Builder/Types/InputObject.php +++ b/packages/graphql/src/Builder/Types/InputObject.php @@ -12,9 +12,9 @@ use GraphQL\Type\Definition\FieldDefinition; use GraphQL\Type\Definition\InputObjectField; use GraphQL\Type\Definition\Type; -use LastDragon_ru\LaraASP\GraphQL\Builder\Context\HandlerContextBuilderInfo; use LastDragon_ru\LaraASP\GraphQL\Builder\Context\HandlerContextImplicit; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Context; +use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Ignored; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Operator; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Scope; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\TypeDefinition; @@ -65,6 +65,8 @@ public function getTypeDefinition( string $name, ): TypeDefinitionNode|Type|null { // Source? + $source = $manipulator->getTypeSource($source->getTypeDefinition()); + if ( !($source instanceof InterfaceSource || $source instanceof ObjectSource || $source instanceof InputSource) ) { @@ -137,7 +139,7 @@ protected function getOperators( ): array { $type = $this->getTypeForOperators(); $operators = $type - ? $manipulator->getTypeOperators($this->getScope(), $type, $context) + ? $manipulator->getTypeOperators($type, $this->getScope(), $source, $context) : []; return $operators; @@ -289,7 +291,7 @@ abstract protected function getFieldMarkerOperator(): string; /** * @see self::isFieldConvertableIgnored() * - * @return class-string|null + * @return class-string|null */ protected function getFieldMarkerIgnored(): ?string { return null; @@ -300,31 +302,20 @@ protected function getFieldDefinition( InputFieldSource|ObjectFieldSource|InterfaceFieldSource $field, Context $context, ): ?InputValueDefinitionNode { - // Builder? - $builder = $context->get(HandlerContextBuilderInfo::class)?->value->getBuilder(); - - if (!$builder) { - return null; - } - // Operator? - [$operator, $type] = $this->getFieldOperator($manipulator, $field, $context) ?? [null, null]; + $operator = $this->getFieldOperator($manipulator, $field, $context); - if ($operator === null || !$operator->isAvailable($builder, $context)) { + if ($operator === null || !$operator->isAvailable($manipulator, $field, $context)) { return null; } - if ($type === null) { - $type = $manipulator->getTypeSource($field->getTypeDefinition()); - } - // Field $fieldName = $manipulator->getName($field->getField()); $fieldDesc = $this->getFieldDescription($manipulator, $field, $context); $fieldDirectives = $this->getFieldDirectives($manipulator, $field, $context); $fieldDefinition = $manipulator->getOperatorField( $operator, - $type, + $field, $context, $fieldName, $fieldDesc, @@ -334,28 +325,23 @@ protected function getFieldDefinition( return Parser::inputValueDefinition($fieldDefinition); } - /** - * @return array{Operator, ?TypeSource}|null - */ protected function getFieldOperator( Manipulator $manipulator, InputFieldSource|ObjectFieldSource|InterfaceFieldSource $field, Context $context, - ): ?array { + ): ?Operator { $operator = $this->getFieldOperatorDirective($manipulator, $field, $context, $this->getFieldMarkerOperator()); if (!$operator) { $type = $this->getTypeForFieldOperator(); if ($type) { - $operators = $manipulator->getTypeOperators($this->getScope(), $type, $context); + $operators = $manipulator->getTypeOperators($type, $this->getScope(), $field, $context); $operator = reset($operators) ?: null; } } - return $operator - ? [$operator, null] - : null; + return $operator; } /** @@ -371,13 +357,6 @@ protected function getFieldOperatorDirective( Context $context, string $directive, ): ?Operator { - // Builder? - $builder = $context->get(HandlerContextBuilderInfo::class)?->value->getBuilder(); - - if (!$builder) { - return null; - } - // Directive? $operator = null; $nodes = [$field->getField(), $field->getTypeDefinition()]; @@ -386,8 +365,8 @@ protected function getFieldOperatorDirective( $operator = $manipulator->getDirective( $node, $directive, - static function (Operator $operator) use ($builder, $context): bool { - return $operator->isAvailable($builder, $context); + static function (Operator $operator) use ($manipulator, $field, $context): bool { + return $operator->isAvailable($manipulator, $field, $context); }, ); diff --git a/packages/graphql/src/Provider.php b/packages/graphql/src/Provider.php index ed53a39a9..7c261ced6 100644 --- a/packages/graphql/src/Provider.php +++ b/packages/graphql/src/Provider.php @@ -6,8 +6,8 @@ use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Support\ServiceProvider; use LastDragon_ru\LaraASP\Core\Provider\WithConfig; -use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\BuilderPropertyResolver as BuilderPropertyResolverContract; -use LastDragon_ru\LaraASP\GraphQL\Builder\Defaults\BuilderPropertyResolver; +use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\BuilderFieldResolver as BuilderFieldResolverContract; +use LastDragon_ru\LaraASP\GraphQL\Builder\Defaults\BuilderFieldResolver; use LastDragon_ru\LaraASP\GraphQL\Builder\Manipulator; use LastDragon_ru\LaraASP\GraphQL\Printer\DirectiveResolver; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Definitions\SearchByDirective; @@ -67,7 +67,7 @@ static function (): array { protected function registerBindings(): void { $this->app->scopedIf(SorterFactoryContract::class, SorterFactory::class); $this->app->scopedIf(StreamFactoryContract::class, StreamFactory::class); - $this->app->scopedIf(BuilderPropertyResolverContract::class, BuilderPropertyResolver::class); + $this->app->scopedIf(BuilderFieldResolverContract::class, BuilderFieldResolver::class); } protected function registerOperators(): void { diff --git a/packages/graphql/src/SearchBy/Contracts/Ignored.php b/packages/graphql/src/SearchBy/Contracts/Ignored.php index 6d2a5a047..8e527a5e7 100644 --- a/packages/graphql/src/SearchBy/Contracts/Ignored.php +++ b/packages/graphql/src/SearchBy/Contracts/Ignored.php @@ -2,9 +2,11 @@ namespace LastDragon_ru\LaraASP\GraphQL\SearchBy\Contracts; +use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Ignored as IgnoredContract; + /** * Marks that field/definition should be excluded from search. */ -interface Ignored { +interface Ignored extends IgnoredContract, Scope { // empty } diff --git a/packages/graphql/src/SearchBy/Directives/Directive.php b/packages/graphql/src/SearchBy/Directives/Directive.php index fb15a774b..6cb6a47fc 100644 --- a/packages/graphql/src/SearchBy/Directives/Directive.php +++ b/packages/graphql/src/SearchBy/Directives/Directive.php @@ -8,8 +8,8 @@ use Illuminate\Database\Eloquent\Builder as EloquentBuilder; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Context; use LastDragon_ru\LaraASP\GraphQL\Builder\Directives\HandlerDirective; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\Builder\Manipulator; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; use LastDragon_ru\LaraASP\GraphQL\Builder\Sources\InterfaceFieldArgumentSource; use LastDragon_ru\LaraASP\GraphQL\Builder\Sources\ObjectFieldArgumentSource; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Contracts\Scope; @@ -75,16 +75,16 @@ protected function getArgDefinitionType( // // ========================================================================= #[Override] - public function handle(object $builder, Property $property, ArgumentSet $conditions, Context $context): object { + public function handle(object $builder, Field $field, ArgumentSet $conditions, Context $context): object { // Some relations (eg `HasManyThrough`) require a table name prefix to // avoid "SQLSTATE[23000]: Integrity constraint violation: 1052 Column // 'xxx' in where clause is ambiguous" error. - if ($builder instanceof EloquentBuilder && $property->getPath() === []) { - $property = $property->getChild($builder->getModel()->getTable()); + if ($builder instanceof EloquentBuilder && $field->getPath() === []) { + $field = $field->getChild($builder->getModel()->getTable()); } // Return - return parent::handle($builder, $property, $conditions, $context); + return parent::handle($builder, $field, $conditions, $context); } // } diff --git a/packages/graphql/src/SearchBy/Directives/DirectiveTest.php b/packages/graphql/src/SearchBy/Directives/DirectiveTest.php index 60cc3b694..85abf1a4f 100644 --- a/packages/graphql/src/SearchBy/Directives/DirectiveTest.php +++ b/packages/graphql/src/SearchBy/Directives/DirectiveTest.php @@ -16,7 +16,7 @@ use Illuminate\Database\Query\Builder as QueryBuilder; use Illuminate\Support\Str; use Laravel\Scout\Builder as ScoutBuilder; -use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\BuilderPropertyResolver; +use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\BuilderFieldResolver; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Context; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Handler; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Scout\FieldResolver; @@ -24,8 +24,8 @@ use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\TypeProvider; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\TypeSource; use LastDragon_ru\LaraASP\GraphQL\Builder\Exceptions\Client\ConditionEmpty; -use LastDragon_ru\LaraASP\GraphQL\Builder\Exceptions\Client\ConditionTooManyOperators; -use LastDragon_ru\LaraASP\GraphQL\Builder\Exceptions\Client\ConditionTooManyProperties; +use LastDragon_ru\LaraASP\GraphQL\Builder\Exceptions\Client\ConditionTooManyFields; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\Builder\Manipulator; use LastDragon_ru\LaraASP\GraphQL\Builder\Property; use LastDragon_ru\LaraASP\GraphQL\Exceptions\TypeDefinitionUnknown; @@ -33,6 +33,7 @@ use LastDragon_ru\LaraASP\GraphQL\SearchBy\Contracts\Ignored; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Definitions\SearchByOperatorBetweenDirective; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Definitions\SearchByOperatorEqualDirective; +use LastDragon_ru\LaraASP\GraphQL\SearchBy\Definitions\SearchByOperatorFieldDirective; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Definitions\SearchByOperatorNotInDirective; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Operators; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Operators\Operator; @@ -413,10 +414,10 @@ public function testHandleBuilderV5Compat( /** * @dataProvider dataProviderHandleScoutBuilder * - * @param array|Exception $expected - * @param Closure(static): ScoutBuilder $builderFactory - * @param Closure(object, Property): string|null $resolver - * @param Closure():FieldResolver|null $fieldResolver + * @param array|Exception $expected + * @param Closure(static): ScoutBuilder $builderFactory + * @param Closure(object, Field): string|null $resolver + * @param Closure():FieldResolver|null $fieldResolver */ #[RequiresLaravelScout] public function testHandleScoutBuilder( @@ -434,10 +435,10 @@ public function testHandleScoutBuilder( if ($resolver) { $this->override( - BuilderPropertyResolver::class, + BuilderFieldResolver::class, static function (MockInterface $mock) use ($resolver): void { $mock - ->shouldReceive('getProperty') + ->shouldReceive('getField') ->atLeast() ->once() ->andReturnUsing($resolver); @@ -489,10 +490,10 @@ static function (MockInterface $mock) use ($resolver): void { * * @dataProvider dataProviderHandleScoutBuilderV5Compat * - * @param array|Exception $expected - * @param Closure(static): ScoutBuilder $builderFactory - * @param Closure(object, Property): string|null $resolver - * @param Closure():FieldResolver|null $fieldResolver + * @param array|Exception $expected + * @param Closure(static): ScoutBuilder $builderFactory + * @param Closure(object, Field): string|null $resolver + * @param Closure():FieldResolver|null $fieldResolver */ #[RequiresLaravelScout] public function testHandleScoutBuilderV5Compat( @@ -513,10 +514,10 @@ public function testHandleScoutBuilderV5Compat( if ($resolver) { $this->override( - BuilderPropertyResolver::class, + BuilderFieldResolver::class, static function (MockInterface $mock) use ($resolver): void { $mock - ->shouldReceive('getProperty') + ->shouldReceive('getField') ->atLeast() ->once() ->andReturnUsing($resolver); @@ -598,9 +599,9 @@ static function (): void { $enum = new EnumType([ 'name' => 'TestEnum', 'values' => [ - 'property' => [ + 'a' => [ 'value' => 123, - 'description' => 'test property', + 'description' => 'description', ], ], ]); @@ -663,7 +664,7 @@ static function (): void { 'CustomComplexOperator.schema.graphql', static function (): void { $locator = Container::getInstance()->make(DirectiveLocator::class); - $resolver = Container::getInstance()->make(BuilderPropertyResolver::class); + $resolver = Container::getInstance()->make(BuilderFieldResolver::class); $directive = new DirectiveTest__CustomComplexOperator($resolver); $locator->setResolved('customComplexOperator', $directive::class); @@ -678,7 +679,7 @@ static function (): void { SearchByOperatorEqualDirective::class, ], Package::Name.'.search_by.operators.'.Operators::Extra => [ - // empty + SearchByOperatorFieldDirective::class, ], ]); }, @@ -692,7 +693,7 @@ static function (): void { SearchByOperatorEqualDirective::class, ], Package::Name.'.search_by.operators.'.Operators::Extra => [ - // empty + SearchByOperatorFieldDirective::class, ], ]); @@ -731,7 +732,7 @@ static function (): void { SearchByOperatorEqualDirective::class, ], Package::Name.'.search_by.operators.'.Operators::Extra => [ - // empty + SearchByOperatorFieldDirective::class, ], ]); }, @@ -781,7 +782,7 @@ public static function dataProviderHandleBuilder(): array { ], ], 'too many fields (operators)' => [ - new ConditionTooManyOperators(['equal', 'notEqual']), + new ConditionTooManyFields(['equal', 'notEqual']), [ 'field' => [ 'id' => [ @@ -792,7 +793,7 @@ public static function dataProviderHandleBuilder(): array { ], ], 'too many fields (fields)' => [ - new ConditionTooManyOperators(['id', 'value']), + new ConditionTooManyFields(['id', 'value']), [ 'field' => [ 'id' => [ @@ -980,7 +981,7 @@ public static function dataProviderHandleBuilderV5Compat(): array { ], ], 'too many properties' => [ - new ConditionTooManyProperties(['id', 'value']), + new ConditionTooManyFields(['id', 'value']), [ 'id' => [ 'notEqual' => 1, @@ -991,7 +992,7 @@ public static function dataProviderHandleBuilderV5Compat(): array { ], ], 'too many operators' => [ - new ConditionTooManyOperators(['equal', 'notEqual']), + new ConditionTooManyFields(['equal', 'notEqual']), [ 'id' => [ 'equal' => 1, @@ -1159,7 +1160,7 @@ public static function dataProviderHandleScoutBuilder(): array { null, ], 'too many fields (operators)' => [ - new ConditionTooManyOperators(['equal', 'in']), + new ConditionTooManyFields(['equal', 'in']), [ 'field' => [ 'a' => [ @@ -1172,7 +1173,7 @@ public static function dataProviderHandleScoutBuilder(): array { null, ], 'too many fields (fields)' => [ - new ConditionTooManyOperators(['a', 'b']), + new ConditionTooManyFields(['a', 'b']), [ 'field' => [ 'a' => [ @@ -1330,8 +1331,8 @@ public function getField( ], ], ], - static function (object $builder, Property $property): string { - return implode('__', $property->getPath()); + static function (object $builder, Field $field): string { + return implode('__', $field->getPath()); }, null, ], @@ -1369,7 +1370,7 @@ public static function dataProviderHandleScoutBuilderV5Compat(): array { null, ], 'too many properties' => [ - new ConditionTooManyProperties(['a', 'b']), + new ConditionTooManyFields(['a', 'b']), [ 'a' => [ 'equal' => 1, @@ -1382,7 +1383,7 @@ public static function dataProviderHandleScoutBuilderV5Compat(): array { null, ], 'too many operators' => [ - new ConditionTooManyOperators(['equal', 'in']), + new ConditionTooManyFields(['equal', 'in']), [ 'a' => [ 'equal' => 1, @@ -1512,8 +1513,8 @@ public function getField( ], ], ], - static function (object $builder, Property $property): string { - return implode('__', $property->getPath()); + static function (object $builder, Field $field): string { + return implode('__', $field->getPath()); }, null, ], @@ -1561,12 +1562,12 @@ public function getFieldType( TypeProvider $provider, TypeSource $source, Context $context, - ): string { + ): ?string { return $provider->getType(static::class, $provider->getTypeSource(Type::int()), $context); } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Custom condition.'; } @@ -1581,7 +1582,7 @@ public static function definition(): string { public function call( Handler $handler, object $builder, - Property $property, + Field $field, Argument $argument, Context $context, ): object { diff --git a/packages/graphql/src/SearchBy/Directives/DirectiveTest/AllowedDirectives.expected.graphql b/packages/graphql/src/SearchBy/Directives/DirectiveTest/AllowedDirectives.expected.graphql index 223fc827e..aec045de3 100644 --- a/packages/graphql/src/SearchBy/Directives/DirectiveTest/AllowedDirectives.expected.graphql +++ b/packages/graphql/src/SearchBy/Directives/DirectiveTest/AllowedDirectives.expected.graphql @@ -24,7 +24,7 @@ on | SCALAR """ -Available conditions for `type A` (only one property allowed at a time). +Available conditions for `type A` (only one field allowed at a time). """ input SearchByConditionA { """ @@ -38,7 +38,7 @@ input SearchByConditionA { } """ -Available conditions for `interface B` (only one property allowed at a time). +Available conditions for `interface B` (only one field allowed at a time). """ input SearchByConditionB { """ @@ -52,7 +52,7 @@ input SearchByConditionB { } """ -Available conditions for `type A` (only one property allowed at a time). +Available conditions for `type A` (only one field allowed at a time). """ input SearchByRootA { """ @@ -63,7 +63,7 @@ input SearchByRootA { } """ -Available conditions for `interface B` (only one property allowed at a time). +Available conditions for `interface B` (only one field allowed at a time). """ input SearchByRootB { """ diff --git a/packages/graphql/src/SearchBy/Directives/DirectiveTest/CustomComplexOperator.expected.graphql b/packages/graphql/src/SearchBy/Directives/DirectiveTest/CustomComplexOperator.expected.graphql index a27e9e5a6..e408a1cf1 100644 --- a/packages/graphql/src/SearchBy/Directives/DirectiveTest/CustomComplexOperator.expected.graphql +++ b/packages/graphql/src/SearchBy/Directives/DirectiveTest/CustomComplexOperator.expected.graphql @@ -215,7 +215,7 @@ input SearchByComplexCustomInt { } """ -Available conditions for `input Child` (only one property allowed at a time). +Available conditions for `input Child` (only one field allowed at a time). """ input SearchByConditionChild { """ @@ -226,7 +226,7 @@ input SearchByConditionChild { } """ -Available conditions for `input Properties` (only one property allowed at a time). +Available conditions for `input Properties` (only one field allowed at a time). """ input SearchByConditionProperties { """ @@ -246,7 +246,7 @@ input SearchByConditionProperties { """ Relationship condition. """ - defaultOperator: SearchByRelationshipRelationChild + defaultOperator: SearchByRelationshipChild @searchByOperatorRelationship } @@ -257,7 +257,7 @@ See also: * https://laravel.com/docs/eloquent-relationships#querying-relationship-existence * https://laravel.com/docs/eloquent-relationships#querying-relationship-absence """ -input SearchByRelationshipRelationChild { +input SearchByRelationshipChild { """ Count conditions. """ @@ -280,7 +280,7 @@ input SearchByRelationshipRelationChild { } """ -Available conditions for `input Child` (only one property allowed at a time). +Available conditions for `input Child` (only one field allowed at a time). """ input SearchByRootChild { """ @@ -309,7 +309,7 @@ input SearchByRootChild { } """ -Available conditions for `input Properties` (only one property allowed at a time). +Available conditions for `input Properties` (only one field allowed at a time). """ input SearchByRootProperties { """ diff --git a/packages/graphql/src/SearchBy/Directives/DirectiveTest/Example.expected.graphql b/packages/graphql/src/SearchBy/Directives/DirectiveTest/Example.expected.graphql index a36b5a928..da35404f9 100644 --- a/packages/graphql/src/SearchBy/Directives/DirectiveTest/Example.expected.graphql +++ b/packages/graphql/src/SearchBy/Directives/DirectiveTest/Example.expected.graphql @@ -210,7 +210,7 @@ input Comment { } """ -Available conditions for `input CommentsQuery` (only one property allowed at a time). +Available conditions for `input CommentsQuery` (only one field allowed at a time). """ input SearchByConditionCommentsQuery { """ @@ -228,12 +228,12 @@ input SearchByConditionCommentsQuery { """ Relationship condition. """ - user: SearchByRelationshipRelationUsersQuery + user: SearchByRelationshipUsersQuery @searchByOperatorRelationship } """ -Available conditions for `type User` (only one property allowed at a time). +Available conditions for `type User` (only one field allowed at a time). """ input SearchByConditionUser { """ @@ -250,7 +250,7 @@ input SearchByConditionUser { } """ -Available conditions for `input UsersQuery` (only one property allowed at a time). +Available conditions for `input UsersQuery` (only one field allowed at a time). """ input SearchByConditionUsersQuery { """ @@ -273,7 +273,7 @@ See also: * https://laravel.com/docs/eloquent-relationships#querying-relationship-existence * https://laravel.com/docs/eloquent-relationships#querying-relationship-absence """ -input SearchByRelationshipRelationUsersQuery { +input SearchByRelationshipUsersQuery { """ Count conditions. """ @@ -296,7 +296,7 @@ input SearchByRelationshipRelationUsersQuery { } """ -Available conditions for `input CommentsQuery` (only one property allowed at a time). +Available conditions for `input CommentsQuery` (only one field allowed at a time). """ input SearchByRootCommentsQuery { """ @@ -325,7 +325,7 @@ input SearchByRootCommentsQuery { } """ -Available conditions for `type User` (only one property allowed at a time). +Available conditions for `type User` (only one field allowed at a time). """ input SearchByRootUser { """ @@ -354,7 +354,7 @@ input SearchByRootUser { } """ -Available conditions for `input UsersQuery` (only one property allowed at a time). +Available conditions for `input UsersQuery` (only one field allowed at a time). """ input SearchByRootUsersQuery { """ diff --git a/packages/graphql/src/SearchBy/Directives/DirectiveTest/Explicit.expected.graphql b/packages/graphql/src/SearchBy/Directives/DirectiveTest/Explicit.expected.graphql index a7e636fde..ade34c2cd 100644 --- a/packages/graphql/src/SearchBy/Directives/DirectiveTest/Explicit.expected.graphql +++ b/packages/graphql/src/SearchBy/Directives/DirectiveTest/Explicit.expected.graphql @@ -224,19 +224,19 @@ input B { } """ -Available conditions for `input A` (only one property allowed at a time). +Available conditions for `input A` (only one field allowed at a time). """ input SearchByConditionA { """ Relationship condition. """ - field: SearchByRelationshipRelationB + field: SearchByRelationshipB @searchByOperatorRelationship """ Relationship condition. """ - fields: SearchByRelationshipRelationB + fields: SearchByRelationshipB @searchByOperatorRelationship """ @@ -253,7 +253,7 @@ input SearchByConditionA { } """ -Available conditions for `input B` (only one property allowed at a time). +Available conditions for `input B` (only one field allowed at a time). """ input SearchByConditionB { """ @@ -271,7 +271,7 @@ input SearchByConditionB { """ Relationship condition. """ - parent: SearchByRelationshipRelationA + parent: SearchByRelationshipA @searchByOperatorRelationship } @@ -282,7 +282,7 @@ See also: * https://laravel.com/docs/eloquent-relationships#querying-relationship-existence * https://laravel.com/docs/eloquent-relationships#querying-relationship-absence """ -input SearchByRelationshipRelationA { +input SearchByRelationshipA { """ Count conditions. """ @@ -311,7 +311,7 @@ See also: * https://laravel.com/docs/eloquent-relationships#querying-relationship-existence * https://laravel.com/docs/eloquent-relationships#querying-relationship-absence """ -input SearchByRelationshipRelationB { +input SearchByRelationshipB { """ Count conditions. """ @@ -334,7 +334,7 @@ input SearchByRelationshipRelationB { } """ -Available conditions for `input A` (only one property allowed at a time). +Available conditions for `input A` (only one field allowed at a time). """ input SearchByRootA { """ @@ -363,7 +363,7 @@ input SearchByRootA { } """ -Available conditions for `input B` (only one property allowed at a time). +Available conditions for `input B` (only one field allowed at a time). """ input SearchByRootB { """ diff --git a/packages/graphql/src/SearchBy/Directives/DirectiveTest/Ignored.expected.graphql b/packages/graphql/src/SearchBy/Directives/DirectiveTest/Ignored.expected.graphql index c15638908..f9bc91f1c 100644 --- a/packages/graphql/src/SearchBy/Directives/DirectiveTest/Ignored.expected.graphql +++ b/packages/graphql/src/SearchBy/Directives/DirectiveTest/Ignored.expected.graphql @@ -73,7 +73,7 @@ input IgnoredType { } """ -Available conditions for `input A` (only one property allowed at a time). +Available conditions for `input A` (only one field allowed at a time). """ input SearchByConditionA { """ @@ -90,7 +90,7 @@ input SearchByConditionA { } """ -Available conditions for `interface B` (only one property allowed at a time). +Available conditions for `interface B` (only one field allowed at a time). """ input SearchByConditionB { """ @@ -107,7 +107,7 @@ input SearchByConditionB { } """ -Available conditions for `input A` (only one property allowed at a time). +Available conditions for `input A` (only one field allowed at a time). """ input SearchByRootA { """ @@ -118,7 +118,7 @@ input SearchByRootA { } """ -Available conditions for `interface B` (only one property allowed at a time). +Available conditions for `interface B` (only one field allowed at a time). """ input SearchByRootB { """ diff --git a/packages/graphql/src/SearchBy/Directives/DirectiveTest/Implicit.expected.graphql b/packages/graphql/src/SearchBy/Directives/DirectiveTest/Implicit.expected.graphql index 59c07c8e6..bbd4963ad 100644 --- a/packages/graphql/src/SearchBy/Directives/DirectiveTest/Implicit.expected.graphql +++ b/packages/graphql/src/SearchBy/Directives/DirectiveTest/Implicit.expected.graphql @@ -270,7 +270,7 @@ enum SearchByTypeFlag { } """ -Available conditions for `type A` (only one property allowed at a time). +Available conditions for `type A` (only one field allowed at a time). """ input SearchByConditionA { """ @@ -288,49 +288,49 @@ input SearchByConditionA { """ Relationship condition. """ - operator: SearchByRelationshipRelationB + operator: SearchByRelationshipB @searchByOperatorRelationship """ Relationship condition. """ - operators: SearchByRelationshipRelationB + operators: SearchByRelationshipB @searchByOperatorRelationship """ Relationship condition. """ - relation: SearchByRelationshipRelationB + relation: SearchByRelationshipB @searchByOperatorRelationship """ Relationship condition. """ - relationWithArgs: SearchByRelationshipRelationA + relationWithArgs: SearchByRelationshipA @searchByOperatorRelationship """ Relationship condition. """ - relations: SearchByRelationshipRelationB + relations: SearchByRelationshipB @searchByOperatorRelationship """ Relationship condition. """ - relationsPaginated: SearchByRelationshipRelationB + relationsPaginated: SearchByRelationshipB @searchByOperatorRelationship """ Relationship condition. """ - relationsPaginatedWithArgs: SearchByRelationshipRelationB + relationsPaginatedWithArgs: SearchByRelationshipB @searchByOperatorRelationship """ Relationship condition. """ - relationsWithArgs: SearchByRelationshipRelationA + relationsWithArgs: SearchByRelationshipA @searchByOperatorRelationship """ @@ -353,7 +353,7 @@ input SearchByConditionA { } """ -Available conditions for `type B` (only one property allowed at a time). +Available conditions for `type B` (only one field allowed at a time). """ input SearchByConditionB { """ @@ -371,12 +371,12 @@ input SearchByConditionB { """ Relationship condition. """ - parent: SearchByRelationshipRelationA + parent: SearchByRelationshipA @searchByOperatorRelationship } """ -Available conditions for `interface C` (only one property allowed at a time). +Available conditions for `interface C` (only one field allowed at a time). """ input SearchByConditionC { """ @@ -394,49 +394,49 @@ input SearchByConditionC { """ Relationship condition. """ - operator: SearchByRelationshipRelationB + operator: SearchByRelationshipB @searchByOperatorRelationship """ Relationship condition. """ - operators: SearchByRelationshipRelationB + operators: SearchByRelationshipB @searchByOperatorRelationship """ Relationship condition. """ - relation: SearchByRelationshipRelationB + relation: SearchByRelationshipB @searchByOperatorRelationship """ Relationship condition. """ - relationWithArgs: SearchByRelationshipRelationA + relationWithArgs: SearchByRelationshipA @searchByOperatorRelationship """ Relationship condition. """ - relations: SearchByRelationshipRelationB + relations: SearchByRelationshipB @searchByOperatorRelationship """ Relationship condition. """ - relationsPaginated: SearchByRelationshipRelationB + relationsPaginated: SearchByRelationshipB @searchByOperatorRelationship """ Relationship condition. """ - relationsPaginatedWithArgs: SearchByRelationshipRelationB + relationsPaginatedWithArgs: SearchByRelationshipB @searchByOperatorRelationship """ Relationship condition. """ - relationsWithArgs: SearchByRelationshipRelationA + relationsWithArgs: SearchByRelationshipA @searchByOperatorRelationship """ @@ -465,7 +465,7 @@ See also: * https://laravel.com/docs/eloquent-relationships#querying-relationship-existence * https://laravel.com/docs/eloquent-relationships#querying-relationship-absence """ -input SearchByRelationshipRelationA { +input SearchByRelationshipA { """ Count conditions. """ @@ -494,7 +494,7 @@ See also: * https://laravel.com/docs/eloquent-relationships#querying-relationship-existence * https://laravel.com/docs/eloquent-relationships#querying-relationship-absence """ -input SearchByRelationshipRelationB { +input SearchByRelationshipB { """ Count conditions. """ @@ -517,7 +517,7 @@ input SearchByRelationshipRelationB { } """ -Available conditions for `type A` (only one property allowed at a time). +Available conditions for `type A` (only one field allowed at a time). """ input SearchByRootA { """ @@ -546,7 +546,7 @@ input SearchByRootA { } """ -Available conditions for `type B` (only one property allowed at a time). +Available conditions for `type B` (only one field allowed at a time). """ input SearchByRootB { """ @@ -575,7 +575,7 @@ input SearchByRootB { } """ -Available conditions for `interface C` (only one property allowed at a time). +Available conditions for `interface C` (only one field allowed at a time). """ input SearchByRootC { """ @@ -920,6 +920,11 @@ input StreamBuilder { interface C { field: B! + + fieldWithArgs( + arg: String + ): Int! + fields: [B!]! """ @@ -935,10 +940,6 @@ interface C { operators: [B!] @searchByOperatorRelationship - property( - arg: String - ): Int! - relation: B! @hasOne @@ -1062,6 +1063,11 @@ scalar StreamOffset type A { field: B! + + fieldWithArgs( + arg: String + ): Int! + fields: [B!]! """ @@ -1077,10 +1083,6 @@ type A { operators: [B!] @searchByOperatorRelationship - property( - arg: String - ): Int! - relation: B! @hasOne diff --git a/packages/graphql/src/SearchBy/Directives/DirectiveTest/Implicit.schema.graphql b/packages/graphql/src/SearchBy/Directives/DirectiveTest/Implicit.schema.graphql index ffbe6b361..16193ba1e 100644 --- a/packages/graphql/src/SearchBy/Directives/DirectiveTest/Implicit.schema.graphql +++ b/packages/graphql/src/SearchBy/Directives/DirectiveTest/Implicit.schema.graphql @@ -25,7 +25,7 @@ type A { # Should be ignored field: B! fields: [B!]! - property(arg: String): Int! + fieldWithArgs(arg: String): Int! resolver: Int! @field(resolver: "\\LastDragon_ru\\LaraASP\\GraphQL\\SearchBy\\Directives\\DirectiveTest__Resolver") stream: [A!]! @stream( sortable: false @@ -64,7 +64,7 @@ interface C { # Should be ignored field: B! fields: [B!]! - property(arg: String): Int! + fieldWithArgs(arg: String): Int! resolver: Int! @field(resolver: "\\LastDragon_ru\\LaraASP\\GraphQL\\SearchBy\\Directives\\DirectiveTest__Resolver") stream: [A!]! @stream( sortable: false diff --git a/packages/graphql/src/SearchBy/Directives/DirectiveTest/InterfaceUpdate.expected.graphql b/packages/graphql/src/SearchBy/Directives/DirectiveTest/InterfaceUpdate.expected.graphql index 9371d338d..15fd33065 100644 --- a/packages/graphql/src/SearchBy/Directives/DirectiveTest/InterfaceUpdate.expected.graphql +++ b/packages/graphql/src/SearchBy/Directives/DirectiveTest/InterfaceUpdate.expected.graphql @@ -28,7 +28,7 @@ input A { } """ -Available conditions for `input A` (only one property allowed at a time). +Available conditions for `input A` (only one field allowed at a time). """ input SearchByConditionA { """ @@ -39,7 +39,7 @@ input SearchByConditionA { } """ -Available conditions for `type B` (only one property allowed at a time). +Available conditions for `type B` (only one field allowed at a time). """ input SearchByConditionB { """ @@ -50,7 +50,7 @@ input SearchByConditionB { } """ -Available conditions for `input A` (only one property allowed at a time). +Available conditions for `input A` (only one field allowed at a time). """ input SearchByRootA { """ @@ -61,7 +61,7 @@ input SearchByRootA { } """ -Available conditions for `type B` (only one property allowed at a time). +Available conditions for `type B` (only one field allowed at a time). """ input SearchByRootB { """ diff --git a/packages/graphql/src/SearchBy/Directives/DirectiveTest/Query.expected.graphql b/packages/graphql/src/SearchBy/Directives/DirectiveTest/Query.expected.graphql index 0688b3f49..87fe1711c 100644 --- a/packages/graphql/src/SearchBy/Directives/DirectiveTest/Query.expected.graphql +++ b/packages/graphql/src/SearchBy/Directives/DirectiveTest/Query.expected.graphql @@ -129,7 +129,7 @@ enum SearchByTypeFlag { } """ -Available conditions for `input InputA` (only one property allowed at a time). +Available conditions for `input InputA` (only one field allowed at a time). """ input SearchByQueryConditionInputA { """ @@ -146,7 +146,7 @@ input SearchByQueryConditionInputA { } """ -Available conditions for `input TypeB` (only one property allowed at a time). +Available conditions for `input TypeB` (only one field allowed at a time). """ input SearchByQueryConditionTypeB { """ @@ -163,7 +163,7 @@ input SearchByQueryConditionTypeB { } """ -Available conditions for `input InputA` (only one property allowed at a time). +Available conditions for `input InputA` (only one field allowed at a time). """ input SearchByQueryRootInputA { """ @@ -192,7 +192,7 @@ input SearchByQueryRootInputA { } """ -Available conditions for `input TypeB` (only one property allowed at a time). +Available conditions for `input TypeB` (only one field allowed at a time). """ input SearchByQueryRootTypeB { """ diff --git a/packages/graphql/src/SearchBy/Directives/DirectiveTest/ScalarOperators.expected.graphql b/packages/graphql/src/SearchBy/Directives/DirectiveTest/ScalarOperators.expected.graphql index ed5ccee4e..e2ed9e0f3 100644 --- a/packages/graphql/src/SearchBy/Directives/DirectiveTest/ScalarOperators.expected.graphql +++ b/packages/graphql/src/SearchBy/Directives/DirectiveTest/ScalarOperators.expected.graphql @@ -91,7 +91,7 @@ enum SearchByTypeFlag { } """ -Available conditions for `input A` (only one property allowed at a time). +Available conditions for `input A` (only one field allowed at a time). """ input SearchByConditionA { """ @@ -137,7 +137,7 @@ input SearchByEnumEnumAOrNull { } """ -Available conditions for `input A` (only one property allowed at a time). +Available conditions for `input A` (only one field allowed at a time). """ input SearchByRootA { """ diff --git a/packages/graphql/src/SearchBy/Directives/DirectiveTest/ScalarOperators.schema.graphql b/packages/graphql/src/SearchBy/Directives/DirectiveTest/ScalarOperators.schema.graphql index a5edc3ddf..eaeded777 100644 --- a/packages/graphql/src/SearchBy/Directives/DirectiveTest/ScalarOperators.schema.graphql +++ b/packages/graphql/src/SearchBy/Directives/DirectiveTest/ScalarOperators.schema.graphql @@ -21,6 +21,7 @@ enum EnumA } scalar SearchByExtra +@searchByOperatorField @searchByOperatorAllOf scalar Mixed diff --git a/packages/graphql/src/SearchBy/Directives/DirectiveTest/Scout.expected.graphql b/packages/graphql/src/SearchBy/Directives/DirectiveTest/Scout.expected.graphql index 0461c7f7e..aaf524989 100644 --- a/packages/graphql/src/SearchBy/Directives/DirectiveTest/Scout.expected.graphql +++ b/packages/graphql/src/SearchBy/Directives/DirectiveTest/Scout.expected.graphql @@ -87,7 +87,7 @@ enum EnumIgnored } """ -Available conditions for `input InputA` (only one property allowed at a time). +Available conditions for `input InputA` (only one field allowed at a time). """ input SearchByScoutConditionInputA { """ @@ -221,7 +221,7 @@ input SearchByScoutConditionInputA { } """ -Available conditions for `input InputB` (only one property allowed at a time). +Available conditions for `input InputB` (only one field allowed at a time). """ input SearchByScoutConditionInputB { """ @@ -232,7 +232,7 @@ input SearchByScoutConditionInputB { } """ -Available conditions for `input NestedA` (only one property allowed at a time). +Available conditions for `input NestedA` (only one field allowed at a time). """ input SearchByScoutConditionNestedA { """ @@ -249,7 +249,7 @@ input SearchByScoutConditionNestedA { } """ -Available conditions for `input NestedB` (only one property allowed at a time). +Available conditions for `input NestedB` (only one field allowed at a time). """ input SearchByScoutConditionNestedB { """ @@ -260,7 +260,7 @@ input SearchByScoutConditionNestedB { } """ -Available conditions for `input NestedC` (only one property allowed at a time). +Available conditions for `input NestedC` (only one field allowed at a time). """ input SearchByScoutConditionNestedC { """ @@ -271,7 +271,7 @@ input SearchByScoutConditionNestedC { } """ -Available conditions for `type Object` (only one property allowed at a time). +Available conditions for `type Object` (only one field allowed at a time). """ input SearchByScoutConditionObject { """ @@ -399,7 +399,7 @@ input SearchByScoutConditionObject { } """ -Available conditions for `interface ObjectInterface` (only one property allowed at a time). +Available conditions for `interface ObjectInterface` (only one field allowed at a time). """ input SearchByScoutConditionObjectInterface { """ @@ -527,7 +527,7 @@ input SearchByScoutConditionObjectInterface { } """ -Available conditions for `type ObjectNested` (only one property allowed at a time). +Available conditions for `type ObjectNested` (only one field allowed at a time). """ input SearchByScoutConditionObjectNested { """ @@ -572,7 +572,7 @@ input SearchByScoutEnumEnumAOrNull { } """ -Available conditions for `input InputA` (only one property allowed at a time). +Available conditions for `input InputA` (only one field allowed at a time). """ input SearchByScoutRootInputA { """ @@ -589,7 +589,7 @@ input SearchByScoutRootInputA { } """ -Available conditions for `input InputB` (only one property allowed at a time). +Available conditions for `input InputB` (only one field allowed at a time). """ input SearchByScoutRootInputB { """ @@ -606,7 +606,7 @@ input SearchByScoutRootInputB { } """ -Available conditions for `input NestedA` (only one property allowed at a time). +Available conditions for `input NestedA` (only one field allowed at a time). """ input SearchByScoutRootNestedA { """ @@ -623,7 +623,7 @@ input SearchByScoutRootNestedA { } """ -Available conditions for `input NestedB` (only one property allowed at a time). +Available conditions for `input NestedB` (only one field allowed at a time). """ input SearchByScoutRootNestedB { """ @@ -640,7 +640,7 @@ input SearchByScoutRootNestedB { } """ -Available conditions for `input NestedC` (only one property allowed at a time). +Available conditions for `input NestedC` (only one field allowed at a time). """ input SearchByScoutRootNestedC { """ @@ -657,7 +657,7 @@ input SearchByScoutRootNestedC { } """ -Available conditions for `type Object` (only one property allowed at a time). +Available conditions for `type Object` (only one field allowed at a time). """ input SearchByScoutRootObject { """ @@ -674,7 +674,7 @@ input SearchByScoutRootObject { } """ -Available conditions for `interface ObjectInterface` (only one property allowed at a time). +Available conditions for `interface ObjectInterface` (only one field allowed at a time). """ input SearchByScoutRootObjectInterface { """ @@ -691,7 +691,7 @@ input SearchByScoutRootObjectInterface { } """ -Available conditions for `type ObjectNested` (only one property allowed at a time). +Available conditions for `type ObjectNested` (only one field allowed at a time). """ input SearchByScoutRootObjectNested { """ diff --git a/packages/graphql/src/SearchBy/Directives/DirectiveTest/Scout.expected.v10.3.0.graphql b/packages/graphql/src/SearchBy/Directives/DirectiveTest/Scout.expected.v10.3.0.graphql index 47c0e6eda..41947d213 100644 --- a/packages/graphql/src/SearchBy/Directives/DirectiveTest/Scout.expected.v10.3.0.graphql +++ b/packages/graphql/src/SearchBy/Directives/DirectiveTest/Scout.expected.v10.3.0.graphql @@ -93,7 +93,7 @@ enum EnumIgnored } """ -Available conditions for `input InputA` (only one property allowed at a time). +Available conditions for `input InputA` (only one field allowed at a time). """ input SearchByScoutConditionInputA { """ @@ -227,7 +227,7 @@ input SearchByScoutConditionInputA { } """ -Available conditions for `input InputB` (only one property allowed at a time). +Available conditions for `input InputB` (only one field allowed at a time). """ input SearchByScoutConditionInputB { """ @@ -238,7 +238,7 @@ input SearchByScoutConditionInputB { } """ -Available conditions for `input NestedA` (only one property allowed at a time). +Available conditions for `input NestedA` (only one field allowed at a time). """ input SearchByScoutConditionNestedA { """ @@ -255,7 +255,7 @@ input SearchByScoutConditionNestedA { } """ -Available conditions for `input NestedB` (only one property allowed at a time). +Available conditions for `input NestedB` (only one field allowed at a time). """ input SearchByScoutConditionNestedB { """ @@ -266,7 +266,7 @@ input SearchByScoutConditionNestedB { } """ -Available conditions for `input NestedC` (only one property allowed at a time). +Available conditions for `input NestedC` (only one field allowed at a time). """ input SearchByScoutConditionNestedC { """ @@ -277,7 +277,7 @@ input SearchByScoutConditionNestedC { } """ -Available conditions for `type Object` (only one property allowed at a time). +Available conditions for `type Object` (only one field allowed at a time). """ input SearchByScoutConditionObject { """ @@ -405,7 +405,7 @@ input SearchByScoutConditionObject { } """ -Available conditions for `interface ObjectInterface` (only one property allowed at a time). +Available conditions for `interface ObjectInterface` (only one field allowed at a time). """ input SearchByScoutConditionObjectInterface { """ @@ -533,7 +533,7 @@ input SearchByScoutConditionObjectInterface { } """ -Available conditions for `type ObjectNested` (only one property allowed at a time). +Available conditions for `type ObjectNested` (only one field allowed at a time). """ input SearchByScoutConditionObjectNested { """ @@ -590,7 +590,7 @@ input SearchByScoutEnumEnumAOrNull { } """ -Available conditions for `input InputA` (only one property allowed at a time). +Available conditions for `input InputA` (only one field allowed at a time). """ input SearchByScoutRootInputA { """ @@ -607,7 +607,7 @@ input SearchByScoutRootInputA { } """ -Available conditions for `input InputB` (only one property allowed at a time). +Available conditions for `input InputB` (only one field allowed at a time). """ input SearchByScoutRootInputB { """ @@ -624,7 +624,7 @@ input SearchByScoutRootInputB { } """ -Available conditions for `input NestedA` (only one property allowed at a time). +Available conditions for `input NestedA` (only one field allowed at a time). """ input SearchByScoutRootNestedA { """ @@ -641,7 +641,7 @@ input SearchByScoutRootNestedA { } """ -Available conditions for `input NestedB` (only one property allowed at a time). +Available conditions for `input NestedB` (only one field allowed at a time). """ input SearchByScoutRootNestedB { """ @@ -658,7 +658,7 @@ input SearchByScoutRootNestedB { } """ -Available conditions for `input NestedC` (only one property allowed at a time). +Available conditions for `input NestedC` (only one field allowed at a time). """ input SearchByScoutRootNestedC { """ @@ -675,7 +675,7 @@ input SearchByScoutRootNestedC { } """ -Available conditions for `type Object` (only one property allowed at a time). +Available conditions for `type Object` (only one field allowed at a time). """ input SearchByScoutRootObject { """ @@ -692,7 +692,7 @@ input SearchByScoutRootObject { } """ -Available conditions for `interface ObjectInterface` (only one property allowed at a time). +Available conditions for `interface ObjectInterface` (only one field allowed at a time). """ input SearchByScoutRootObjectInterface { """ @@ -709,7 +709,7 @@ input SearchByScoutRootObjectInterface { } """ -Available conditions for `type ObjectNested` (only one property allowed at a time). +Available conditions for `type ObjectNested` (only one field allowed at a time). """ input SearchByScoutRootObjectNested { """ diff --git a/packages/graphql/src/SearchBy/Directives/DirectiveTest/TypeRegistry.expected.graphql b/packages/graphql/src/SearchBy/Directives/DirectiveTest/TypeRegistry.expected.graphql index a8f93da5a..4955cfb70 100644 --- a/packages/graphql/src/SearchBy/Directives/DirectiveTest/TypeRegistry.expected.graphql +++ b/packages/graphql/src/SearchBy/Directives/DirectiveTest/TypeRegistry.expected.graphql @@ -203,13 +203,13 @@ enum SearchByTypeFlag { enum TestEnum { """ - test property + description """ - property + a } """ -Available conditions for `input TestTypeA` (only one property allowed at a time). +Available conditions for `input TestTypeA` (only one field allowed at a time). """ input SearchByConditionTestTypeA { """ @@ -232,13 +232,13 @@ input SearchByConditionTestTypeA { } """ -Available conditions for `input TestTypeB` (only one property allowed at a time). +Available conditions for `input TestTypeB` (only one field allowed at a time). """ input SearchByConditionTestTypeB { """ Relationship condition. """ - child: SearchByRelationshipRelationTestTypeA + child: SearchByRelationshipTestTypeA @searchByOperatorRelationship """ @@ -296,7 +296,7 @@ See also: * https://laravel.com/docs/eloquent-relationships#querying-relationship-existence * https://laravel.com/docs/eloquent-relationships#querying-relationship-absence """ -input SearchByRelationshipRelationTestTypeA { +input SearchByRelationshipTestTypeA { """ Count conditions. """ @@ -319,7 +319,7 @@ input SearchByRelationshipRelationTestTypeA { } """ -Available conditions for `input TestTypeA` (only one property allowed at a time). +Available conditions for `input TestTypeA` (only one field allowed at a time). """ input SearchByRootTestTypeA { """ @@ -348,7 +348,7 @@ input SearchByRootTestTypeA { } """ -Available conditions for `input TestTypeB` (only one property allowed at a time). +Available conditions for `input TestTypeB` (only one field allowed at a time). """ input SearchByRootTestTypeB { """ diff --git a/packages/graphql/src/SearchBy/Directives/DirectiveTest/V5Compat.expected.graphql b/packages/graphql/src/SearchBy/Directives/DirectiveTest/V5Compat.expected.graphql index 776069b5c..1c9f66786 100644 --- a/packages/graphql/src/SearchBy/Directives/DirectiveTest/V5Compat.expected.graphql +++ b/packages/graphql/src/SearchBy/Directives/DirectiveTest/V5Compat.expected.graphql @@ -204,7 +204,7 @@ input Comment { } """ -Available conditions for `input CommentsQuery` (only one property allowed at a time). +Available conditions for `input CommentsQuery` (only one field allowed at a time). """ input SearchByConditionCommentsQuery { """ @@ -240,12 +240,12 @@ input SearchByConditionCommentsQuery { """ Relationship condition. """ - user: SearchByRelationshipRelationUsersQuery + user: SearchByRelationshipUsersQuery @searchByOperatorRelationship } """ -Available conditions for `type User` (only one property allowed at a time). +Available conditions for `type User` (only one field allowed at a time). """ input SearchByConditionUser { """ @@ -280,7 +280,7 @@ input SearchByConditionUser { } """ -Available conditions for `input UsersQuery` (only one property allowed at a time). +Available conditions for `input UsersQuery` (only one field allowed at a time). """ input SearchByConditionUsersQuery { """ @@ -321,7 +321,7 @@ See also: * https://laravel.com/docs/eloquent-relationships#querying-relationship-existence * https://laravel.com/docs/eloquent-relationships#querying-relationship-absence """ -input SearchByRelationshipRelationUsersQuery { +input SearchByRelationshipUsersQuery { """ Count conditions. """ diff --git a/packages/graphql/src/SearchBy/Directives/DirectiveTest/V5CompatScout.expected.graphql b/packages/graphql/src/SearchBy/Directives/DirectiveTest/V5CompatScout.expected.graphql index e36ded74d..96a1a2c4c 100644 --- a/packages/graphql/src/SearchBy/Directives/DirectiveTest/V5CompatScout.expected.graphql +++ b/packages/graphql/src/SearchBy/Directives/DirectiveTest/V5CompatScout.expected.graphql @@ -81,7 +81,7 @@ enum EnumIgnored } """ -Available conditions for `input InputA` (only one property allowed at a time). +Available conditions for `input InputA` (only one field allowed at a time). """ input SearchByScoutConditionInputA { """ @@ -221,7 +221,7 @@ input SearchByScoutConditionInputA { } """ -Available conditions for `input InputB` (only one property allowed at a time). +Available conditions for `input InputB` (only one field allowed at a time). """ input SearchByScoutConditionInputB { """ @@ -238,7 +238,7 @@ input SearchByScoutConditionInputB { } """ -Available conditions for `input NestedA` (only one property allowed at a time). +Available conditions for `input NestedA` (only one field allowed at a time). """ input SearchByScoutConditionNestedA { """ @@ -261,7 +261,7 @@ input SearchByScoutConditionNestedA { } """ -Available conditions for `input NestedB` (only one property allowed at a time). +Available conditions for `input NestedB` (only one field allowed at a time). """ input SearchByScoutConditionNestedB { """ @@ -278,7 +278,7 @@ input SearchByScoutConditionNestedB { } """ -Available conditions for `input NestedC` (only one property allowed at a time). +Available conditions for `input NestedC` (only one field allowed at a time). """ input SearchByScoutConditionNestedC { """ @@ -295,7 +295,7 @@ input SearchByScoutConditionNestedC { } """ -Available conditions for `type Object` (only one property allowed at a time). +Available conditions for `type Object` (only one field allowed at a time). """ input SearchByScoutConditionObject { """ @@ -429,7 +429,7 @@ input SearchByScoutConditionObject { } """ -Available conditions for `interface ObjectInterface` (only one property allowed at a time). +Available conditions for `interface ObjectInterface` (only one field allowed at a time). """ input SearchByScoutConditionObjectInterface { """ @@ -563,7 +563,7 @@ input SearchByScoutConditionObjectInterface { } """ -Available conditions for `type ObjectNested` (only one property allowed at a time). +Available conditions for `type ObjectNested` (only one field allowed at a time). """ input SearchByScoutConditionObjectNested { """ diff --git a/packages/graphql/src/SearchBy/Operators.php b/packages/graphql/src/SearchBy/Operators.php index d38064c9c..0728bd216 100644 --- a/packages/graphql/src/SearchBy/Operators.php +++ b/packages/graphql/src/SearchBy/Operators.php @@ -17,6 +17,7 @@ use LastDragon_ru\LaraASP\GraphQL\SearchBy\Definitions\SearchByOperatorContainsDirective; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Definitions\SearchByOperatorEndsWithDirective; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Definitions\SearchByOperatorEqualDirective; +use LastDragon_ru\LaraASP\GraphQL\SearchBy\Definitions\SearchByOperatorFieldDirective; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Definitions\SearchByOperatorGreaterThanDirective; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Definitions\SearchByOperatorGreaterThanOrEqualDirective; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Definitions\SearchByOperatorInDirective; @@ -112,6 +113,7 @@ class Operators extends BuilderOperators { SearchByOperatorIsNotNullDirective::class, ], self::Extra => [ + SearchByOperatorFieldDirective::class, SearchByOperatorAllOfDirective::class, SearchByOperatorAnyOfDirective::class, SearchByOperatorNotDirective::class, diff --git a/packages/graphql/src/SearchBy/Operators/Child.php b/packages/graphql/src/SearchBy/Operators/Child.php index facb33fca..8cd291293 100644 --- a/packages/graphql/src/SearchBy/Operators/Child.php +++ b/packages/graphql/src/SearchBy/Operators/Child.php @@ -21,17 +21,23 @@ public static function getName(): string { } #[Override] - public function getFieldType(TypeProvider $provider, TypeSource $source, Context $context): string { + public function isAvailable(TypeProvider $provider, TypeSource $source, Context $context): bool { + return parent::isAvailable($provider, $source, $context) + && $source->isObject(); + } + + #[Override] + public function getFieldType(TypeProvider $provider, TypeSource $source, Context $context): ?string { return $provider->getType(Root::class, $source, $context); } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Field condition.'; } #[Override] - public function isAvailable(string $builder, Context $context): bool { + protected function isBuilderSupported(string $builder): bool { return is_a($builder, ScoutBuilder::class, true); } } diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/Between.php b/packages/graphql/src/SearchBy/Operators/Comparison/Between.php index d066c0ad3..5a121c731 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/Between.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/Between.php @@ -10,7 +10,7 @@ use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\TypeProvider; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\TypeSource; use LastDragon_ru\LaraASP\GraphQL\Builder\Exceptions\OperatorUnsupportedBuilder; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Operators\Operator; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Types\Range; use Nuwave\Lighthouse\Execution\Arguments\Argument; @@ -23,12 +23,12 @@ public static function getName(): string { } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Within a range.'; } #[Override] - public function getFieldType(TypeProvider $provider, TypeSource $source, Context $context): string { + public function getFieldType(TypeProvider $provider, TypeSource $source, Context $context): ?string { return $provider->getType(Range::class, $source, $context); } @@ -36,7 +36,7 @@ public function getFieldType(TypeProvider $provider, TypeSource $source, Context public function call( Handler $handler, object $builder, - Property $property, + Field $field, Argument $argument, Context $context, ): object { @@ -44,10 +44,10 @@ public function call( throw new OperatorUnsupportedBuilder($this, $builder); } - $property = $this->resolver->getProperty($builder, $property->getParent()); - $value = Cast::toIterable($argument->toPlain()); + $field = $this->resolver->getField($builder, $field->getParent()); + $value = Cast::toIterable($argument->toPlain()); - $builder->whereBetween($property, $value); + $builder->whereBetween($field, $value); return $builder; } diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/BetweenTest.php b/packages/graphql/src/SearchBy/Operators/Comparison/BetweenTest.php index f08729d84..3e6e8fe51 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/BetweenTest.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/BetweenTest.php @@ -4,7 +4,7 @@ use Closure; use LastDragon_ru\LaraASP\GraphQL\Builder\Context; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Directives\Directive; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\DataProviders\BuilderDataProvider; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\OperatorTests; @@ -34,12 +34,12 @@ final class BetweenTest extends TestCase { * @param BuilderFactory $builderFactory * @param Closure(static): Argument $argumentFactory * @param Closure(static): Context|null $contextFactory - * @param Closure(object, Property): string|null $resolver + * @param Closure(object, Field): string|null $resolver */ public function testCall( array $expected, Closure $builderFactory, - Property $property, + Field $field, Closure $argumentFactory, ?Closure $contextFactory, ?Closure $resolver, @@ -48,7 +48,7 @@ public function testCall( Directive::class, $expected, $builderFactory, - $property, + $field, $argumentFactory, $contextFactory, $resolver, @@ -65,42 +65,42 @@ public static function dataProviderCall(): array { return (new CompositeDataProvider( new BuilderDataProvider(), new ArrayDataProvider([ - 'property' => [ + 'field' => [ [ - 'query' => 'select * from "test_objects" where "property" between ? and ?', + 'query' => 'select * from "test_objects" where "field" between ? and ?', 'bindings' => [1, 2], ], - new Property('property', 'operator name should be ignored'), + new Field('field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('[Int!]!', [1, 2, 3]); }, null, null, ], - 'property.path' => [ + 'field.path' => [ [ - 'query' => 'select * from "test_objects" where "path"."to"."property" between ? and ?', + 'query' => 'select * from "test_objects" where "path"."to"."field" between ? and ?', 'bindings' => [1, 2], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('[Int!]!', [1, 2, 3]); }, null, null, ], - 'resolver' => [ + 'resolver' => [ [ - 'query' => 'select * from "test_objects" where "path__to__property" between ? and ?', + 'query' => 'select * from "test_objects" where "path__to__field" between ? and ?', 'bindings' => [1, 2], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('[Int!]!', [1, 2, 3]); }, null, - static function (object $builder, Property $property): string { - return implode('__', $property->getPath()); + static function (object $builder, Field $field): string { + return implode('__', $field->getPath()); }, ], ]), diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/BitwiseAnd.php b/packages/graphql/src/SearchBy/Operators/Comparison/BitwiseAnd.php index 15274813d..51c45ca4f 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/BitwiseAnd.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/BitwiseAnd.php @@ -7,7 +7,7 @@ use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Context; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Handler; use LastDragon_ru\LaraASP\GraphQL\Builder\Exceptions\OperatorUnsupportedBuilder; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Operators\Operator; use Nuwave\Lighthouse\Execution\Arguments\Argument; use Override; @@ -19,7 +19,7 @@ public static function getName(): string { } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Bitwise AND (`&`).'; } @@ -27,7 +27,7 @@ public function getFieldDescription(): string { public function call( Handler $handler, object $builder, - Property $property, + Field $field, Argument $argument, Context $context, ): object { @@ -35,9 +35,9 @@ public function call( throw new OperatorUnsupportedBuilder($this, $builder); } - $property = $this->resolver->getProperty($builder, $property->getParent()); - $value = $argument->toPlain(); - $builder = $builder->where($property, '&', $value); + $field = $this->resolver->getField($builder, $field->getParent()); + $value = $argument->toPlain(); + $builder = $builder->where($field, '&', $value); return $builder; } diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/BitwiseAndTest.php b/packages/graphql/src/SearchBy/Operators/Comparison/BitwiseAndTest.php index 2ee9ff066..f752665a1 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/BitwiseAndTest.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/BitwiseAndTest.php @@ -4,7 +4,7 @@ use Closure; use LastDragon_ru\LaraASP\GraphQL\Builder\Context; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Directives\Directive; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\DataProviders\BuilderDataProvider; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\OperatorTests; @@ -34,12 +34,12 @@ final class BitwiseAndTest extends TestCase { * @param BuilderFactory $builderFactory * @param Closure(static): Argument $argumentFactory * @param Closure(static): Context|null $contextFactory - * @param Closure(object, Property): string|null $resolver + * @param Closure(object, Field): string|null $resolver */ public function testCall( array $expected, Closure $builderFactory, - Property $property, + Field $field, Closure $argumentFactory, ?Closure $contextFactory, ?Closure $resolver, @@ -48,7 +48,7 @@ public function testCall( Directive::class, $expected, $builderFactory, - $property, + $field, $argumentFactory, $contextFactory, $resolver, @@ -65,42 +65,42 @@ public static function dataProviderCall(): array { return (new CompositeDataProvider( new BuilderDataProvider(), new ArrayDataProvider([ - 'property' => [ + 'field' => [ [ - 'query' => 'select * from "test_objects" where "property" & ?', + 'query' => 'select * from "test_objects" where "field" & ?', 'bindings' => ['abc'], ], - new Property('property', 'operator name should be ignored'), + new Field('field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('String!', 'abc'); }, null, null, ], - 'property.path' => [ + 'field.path' => [ [ - 'query' => 'select * from "test_objects" where "path"."to"."property" & ?', + 'query' => 'select * from "test_objects" where "path"."to"."field" & ?', 'bindings' => [123], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('Int!', 123); }, null, null, ], - 'resolver' => [ + 'resolver' => [ [ - 'query' => 'select * from "test_objects" where "path__to__property" & ?', + 'query' => 'select * from "test_objects" where "path__to__field" & ?', 'bindings' => [123], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('Int!', 123); }, null, - static function (object $builder, Property $property): string { - return implode('__', $property->getPath()); + static function (object $builder, Field $field): string { + return implode('__', $field->getPath()); }, ], ]), diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/BitwiseLeftShift.php b/packages/graphql/src/SearchBy/Operators/Comparison/BitwiseLeftShift.php index 2fe078173..cbd00d02b 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/BitwiseLeftShift.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/BitwiseLeftShift.php @@ -7,7 +7,7 @@ use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Context; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Handler; use LastDragon_ru\LaraASP\GraphQL\Builder\Exceptions\OperatorUnsupportedBuilder; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Operators\Operator; use Nuwave\Lighthouse\Execution\Arguments\Argument; use Override; @@ -19,7 +19,7 @@ public static function getName(): string { } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Bitwise Left shift (`<<`).'; } @@ -27,7 +27,7 @@ public function getFieldDescription(): string { public function call( Handler $handler, object $builder, - Property $property, + Field $field, Argument $argument, Context $context, ): object { @@ -35,9 +35,9 @@ public function call( throw new OperatorUnsupportedBuilder($this, $builder); } - $property = $this->resolver->getProperty($builder, $property->getParent()); - $value = $argument->toPlain(); - $builder = $builder->where($property, '<<', $value); + $field = $this->resolver->getField($builder, $field->getParent()); + $value = $argument->toPlain(); + $builder = $builder->where($field, '<<', $value); return $builder; } diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/BitwiseLeftShiftTest.php b/packages/graphql/src/SearchBy/Operators/Comparison/BitwiseLeftShiftTest.php index 2c1a9031a..1bf33e83f 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/BitwiseLeftShiftTest.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/BitwiseLeftShiftTest.php @@ -4,7 +4,7 @@ use Closure; use LastDragon_ru\LaraASP\GraphQL\Builder\Context; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Directives\Directive; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\DataProviders\BuilderDataProvider; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\OperatorTests; @@ -34,12 +34,12 @@ final class BitwiseLeftShiftTest extends TestCase { * @param BuilderFactory $builderFactory * @param Closure(static): Argument $argumentFactory * @param Closure(static): Context|null $contextFactory - * @param Closure(object, Property): string|null $resolver + * @param Closure(object, Field): string|null $resolver */ public function testCall( array $expected, Closure $builderFactory, - Property $property, + Field $field, Closure $argumentFactory, ?Closure $contextFactory, ?Closure $resolver, @@ -48,7 +48,7 @@ public function testCall( Directive::class, $expected, $builderFactory, - $property, + $field, $argumentFactory, $contextFactory, $resolver, @@ -65,42 +65,42 @@ public static function dataProviderCall(): array { return (new CompositeDataProvider( new BuilderDataProvider(), new ArrayDataProvider([ - 'property' => [ + 'field' => [ [ - 'query' => 'select * from "test_objects" where "property" << ?', + 'query' => 'select * from "test_objects" where "field" << ?', 'bindings' => ['abc'], ], - new Property('property', 'operator name should be ignored'), + new Field('field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('String!', 'abc'); }, null, null, ], - 'property.path' => [ + 'field.path' => [ [ - 'query' => 'select * from "test_objects" where "path"."to"."property" << ?', + 'query' => 'select * from "test_objects" where "path"."to"."field" << ?', 'bindings' => [123], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('Int!', 123); }, null, null, ], - 'resolver' => [ + 'resolver' => [ [ - 'query' => 'select * from "test_objects" where "path__to__property" << ?', + 'query' => 'select * from "test_objects" where "path__to__field" << ?', 'bindings' => [123], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('Int!', 123); }, null, - static function (object $builder, Property $property): string { - return implode('__', $property->getPath()); + static function (object $builder, Field $field): string { + return implode('__', $field->getPath()); }, ], ]), diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/BitwiseOr.php b/packages/graphql/src/SearchBy/Operators/Comparison/BitwiseOr.php index 747eb0955..6a3a9f0f5 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/BitwiseOr.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/BitwiseOr.php @@ -7,7 +7,7 @@ use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Context; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Handler; use LastDragon_ru\LaraASP\GraphQL\Builder\Exceptions\OperatorUnsupportedBuilder; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Operators\Operator; use Nuwave\Lighthouse\Execution\Arguments\Argument; use Override; @@ -19,7 +19,7 @@ public static function getName(): string { } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Bitwise OR (`|`).'; } @@ -27,7 +27,7 @@ public function getFieldDescription(): string { public function call( Handler $handler, object $builder, - Property $property, + Field $field, Argument $argument, Context $context, ): object { @@ -35,9 +35,9 @@ public function call( throw new OperatorUnsupportedBuilder($this, $builder); } - $property = $this->resolver->getProperty($builder, $property->getParent()); - $value = $argument->toPlain(); - $builder = $builder->where($property, '|', $value); + $field = $this->resolver->getField($builder, $field->getParent()); + $value = $argument->toPlain(); + $builder = $builder->where($field, '|', $value); return $builder; } diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/BitwiseOrTest.php b/packages/graphql/src/SearchBy/Operators/Comparison/BitwiseOrTest.php index 0ca5b99b1..2e4407bac 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/BitwiseOrTest.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/BitwiseOrTest.php @@ -4,7 +4,7 @@ use Closure; use LastDragon_ru\LaraASP\GraphQL\Builder\Context; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Directives\Directive; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\DataProviders\BuilderDataProvider; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\OperatorTests; @@ -34,12 +34,12 @@ final class BitwiseOrTest extends TestCase { * @param BuilderFactory $builderFactory * @param Closure(static): Argument $argumentFactory * @param Closure(static): Context|null $contextFactory - * @param Closure(object, Property): string|null $resolver + * @param Closure(object, Field): string|null $resolver */ public function testCall( array $expected, Closure $builderFactory, - Property $property, + Field $field, Closure $argumentFactory, ?Closure $contextFactory, ?Closure $resolver, @@ -48,7 +48,7 @@ public function testCall( Directive::class, $expected, $builderFactory, - $property, + $field, $argumentFactory, $contextFactory, $resolver, @@ -65,42 +65,42 @@ public static function dataProviderCall(): array { return (new CompositeDataProvider( new BuilderDataProvider(), new ArrayDataProvider([ - 'property' => [ + 'field' => [ [ - 'query' => 'select * from "test_objects" where "property" | ?', + 'query' => 'select * from "test_objects" where "field" | ?', 'bindings' => ['abc'], ], - new Property('property', 'operator name should be ignored'), + new Field('field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('String!', 'abc'); }, null, null, ], - 'property.path' => [ + 'field.path' => [ [ - 'query' => 'select * from "test_objects" where "path"."to"."property" | ?', + 'query' => 'select * from "test_objects" where "path"."to"."field" | ?', 'bindings' => [123], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('Int!', 123); }, null, null, ], - 'resolver' => [ + 'resolver' => [ [ - 'query' => 'select * from "test_objects" where "path__to__property" | ?', + 'query' => 'select * from "test_objects" where "path__to__field" | ?', 'bindings' => [123], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('Int!', 123); }, null, - static function (object $builder, Property $property): string { - return implode('__', $property->getPath()); + static function (object $builder, Field $field): string { + return implode('__', $field->getPath()); }, ], ]), diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/BitwiseRightShift.php b/packages/graphql/src/SearchBy/Operators/Comparison/BitwiseRightShift.php index 98e6989c6..27f0b96e6 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/BitwiseRightShift.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/BitwiseRightShift.php @@ -7,7 +7,7 @@ use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Context; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Handler; use LastDragon_ru\LaraASP\GraphQL\Builder\Exceptions\OperatorUnsupportedBuilder; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Operators\Operator; use Nuwave\Lighthouse\Execution\Arguments\Argument; use Override; @@ -19,7 +19,7 @@ public static function getName(): string { } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Bitwise Right shift (`>>`).'; } @@ -27,7 +27,7 @@ public function getFieldDescription(): string { public function call( Handler $handler, object $builder, - Property $property, + Field $field, Argument $argument, Context $context, ): object { @@ -35,9 +35,9 @@ public function call( throw new OperatorUnsupportedBuilder($this, $builder); } - $property = $this->resolver->getProperty($builder, $property->getParent()); - $value = $argument->toPlain(); - $builder = $builder->where($property, '>>', $value); + $field = $this->resolver->getField($builder, $field->getParent()); + $value = $argument->toPlain(); + $builder = $builder->where($field, '>>', $value); return $builder; } diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/BitwiseRightShiftTest.php b/packages/graphql/src/SearchBy/Operators/Comparison/BitwiseRightShiftTest.php index b554293b2..dbd1ce272 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/BitwiseRightShiftTest.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/BitwiseRightShiftTest.php @@ -4,7 +4,7 @@ use Closure; use LastDragon_ru\LaraASP\GraphQL\Builder\Context; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Directives\Directive; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\DataProviders\BuilderDataProvider; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\OperatorTests; @@ -34,12 +34,12 @@ final class BitwiseRightShiftTest extends TestCase { * @param BuilderFactory $builderFactory * @param Closure(static): Argument $argumentFactory * @param Closure(static): Context|null $contextFactory - * @param Closure(object, Property): string|null $resolver + * @param Closure(object, Field): string|null $resolver */ public function testCall( array $expected, Closure $builderFactory, - Property $property, + Field $field, Closure $argumentFactory, ?Closure $contextFactory, ?Closure $resolver, @@ -48,7 +48,7 @@ public function testCall( Directive::class, $expected, $builderFactory, - $property, + $field, $argumentFactory, $contextFactory, $resolver, @@ -65,42 +65,42 @@ public static function dataProviderCall(): array { return (new CompositeDataProvider( new BuilderDataProvider(), new ArrayDataProvider([ - 'property' => [ + 'field' => [ [ - 'query' => 'select * from "test_objects" where "property" >> ?', + 'query' => 'select * from "test_objects" where "field" >> ?', 'bindings' => ['abc'], ], - new Property('property', 'operator name should be ignored'), + new Field('field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('String!', 'abc'); }, null, null, ], - 'property.path' => [ + 'field.path' => [ [ - 'query' => 'select * from "test_objects" where "path"."to"."property" >> ?', + 'query' => 'select * from "test_objects" where "path"."to"."field" >> ?', 'bindings' => [123], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('Int!', 123); }, null, null, ], - 'resolver' => [ + 'resolver' => [ [ - 'query' => 'select * from "test_objects" where "path__to__property" >> ?', + 'query' => 'select * from "test_objects" where "path__to__field" >> ?', 'bindings' => [123], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('Int!', 123); }, null, - static function (object $builder, Property $property): string { - return implode('__', $property->getPath()); + static function (object $builder, Field $field): string { + return implode('__', $field->getPath()); }, ], ]), diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/BitwiseXor.php b/packages/graphql/src/SearchBy/Operators/Comparison/BitwiseXor.php index ec43de260..c4d56f659 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/BitwiseXor.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/BitwiseXor.php @@ -7,7 +7,7 @@ use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Context; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Handler; use LastDragon_ru\LaraASP\GraphQL\Builder\Exceptions\OperatorUnsupportedBuilder; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Operators\Operator; use Nuwave\Lighthouse\Execution\Arguments\Argument; use Override; @@ -19,7 +19,7 @@ public static function getName(): string { } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Bitwise XOR (`^`).'; } @@ -27,7 +27,7 @@ public function getFieldDescription(): string { public function call( Handler $handler, object $builder, - Property $property, + Field $field, Argument $argument, Context $context, ): object { @@ -35,9 +35,9 @@ public function call( throw new OperatorUnsupportedBuilder($this, $builder); } - $property = $this->resolver->getProperty($builder, $property->getParent()); - $value = $argument->toPlain(); - $builder = $builder->where($property, '^', $value); + $field = $this->resolver->getField($builder, $field->getParent()); + $value = $argument->toPlain(); + $builder = $builder->where($field, '^', $value); return $builder; } diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/BitwiseXorTest.php b/packages/graphql/src/SearchBy/Operators/Comparison/BitwiseXorTest.php index d3e9bcc73..4ed32463c 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/BitwiseXorTest.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/BitwiseXorTest.php @@ -4,7 +4,7 @@ use Closure; use LastDragon_ru\LaraASP\GraphQL\Builder\Context; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Directives\Directive; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\DataProviders\BuilderDataProvider; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\OperatorTests; @@ -34,12 +34,12 @@ final class BitwiseXorTest extends TestCase { * @param BuilderFactory $builderFactory * @param Closure(static): Argument $argumentFactory * @param Closure(static): Context|null $contextFactory - * @param Closure(object, Property): string|null $resolver + * @param Closure(object, Field): string|null $resolver */ public function testCall( array $expected, Closure $builderFactory, - Property $property, + Field $field, Closure $argumentFactory, ?Closure $contextFactory, ?Closure $resolver, @@ -48,7 +48,7 @@ public function testCall( Directive::class, $expected, $builderFactory, - $property, + $field, $argumentFactory, $contextFactory, $resolver, @@ -65,42 +65,42 @@ public static function dataProviderCall(): array { return (new CompositeDataProvider( new BuilderDataProvider(), new ArrayDataProvider([ - 'property' => [ + 'field' => [ [ - 'query' => 'select * from "test_objects" where "property" ^ ?', + 'query' => 'select * from "test_objects" where "field" ^ ?', 'bindings' => ['abc'], ], - new Property('property', 'operator name should be ignored'), + new Field('field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('String!', 'abc'); }, null, null, ], - 'property.path' => [ + 'field.path' => [ [ - 'query' => 'select * from "test_objects" where "path"."to"."property" ^ ?', + 'query' => 'select * from "test_objects" where "path"."to"."field" ^ ?', 'bindings' => [123], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('Int!', 123); }, null, null, ], - 'resolver' => [ + 'resolver' => [ [ - 'query' => 'select * from "test_objects" where "path__to__property" ^ ?', + 'query' => 'select * from "test_objects" where "path__to__field" ^ ?', 'bindings' => [123], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('Int!', 123); }, null, - static function (object $builder, Property $property): string { - return implode('__', $property->getPath()); + static function (object $builder, Field $field): string { + return implode('__', $field->getPath()); }, ], ]), diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/Contains.php b/packages/graphql/src/SearchBy/Operators/Comparison/Contains.php index af180eb72..f4131bceb 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/Contains.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/Contains.php @@ -10,7 +10,7 @@ use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Context; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Handler; use LastDragon_ru\LaraASP\GraphQL\Builder\Exceptions\OperatorUnsupportedBuilder; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Operators\Operator; use Nuwave\Lighthouse\Execution\Arguments\Argument; use Override; @@ -24,7 +24,7 @@ public static function getName(): string { } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Contains.'; } @@ -32,7 +32,7 @@ public function getFieldDescription(): string { public function call( Handler $handler, object $builder, - Property $property, + Field $field, Argument $argument, Context $context, ): object { @@ -41,13 +41,13 @@ public function call( } $character = $this->getEscapeCharacter(); - $property = $this->resolver->getProperty($builder, $property->getParent()); - $property = $builder->getGrammar()->wrap($property); + $field = $this->resolver->getField($builder, $field->getParent()); + $field = $builder->getGrammar()->wrap($field); $value = (string) Cast::toStringable($argument->toPlain()); $not = $this->isNegated() ? ' NOT' : ''; $builder->whereRaw( - "{$property}{$not} LIKE ? ESCAPE '{$character}'", + "{$field}{$not} LIKE ? ESCAPE '{$character}'", [ $this->value($this->escape($builder, $value)), ], diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/ContainsTest.php b/packages/graphql/src/SearchBy/Operators/Comparison/ContainsTest.php index bb40cebe5..b3a70ad72 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/ContainsTest.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/ContainsTest.php @@ -10,7 +10,7 @@ use Illuminate\Database\Query\Grammars\SQLiteGrammar; use Illuminate\Database\Query\Grammars\SqlServerGrammar; use LastDragon_ru\LaraASP\GraphQL\Builder\Context; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Directives\Directive; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\DataProviders\BuilderDataProvider; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\OperatorTests; @@ -41,13 +41,13 @@ final class ContainsTest extends TestCase { * @param class-string $grammar * @param Closure(static): Argument $argumentFactory * @param Closure(static): Context|null $contextFactory - * @param Closure(object, Property): string|null $resolver + * @param Closure(object, Field): string|null $resolver */ public function testCall( array $expected, Closure $builderFactory, string $grammar, - Property $property, + Field $field, Closure $argumentFactory, ?Closure $contextFactory, ?Closure $resolver, @@ -70,7 +70,7 @@ public function testCall( Directive::class, $expected, $builderFactory, - $property, + $field, $argumentFactory, $contextFactory, $resolver, @@ -89,11 +89,11 @@ public static function dataProviderCall(): array { new ArrayDataProvider([ MySqlGrammar::class => [ [ - 'query' => 'select * from `test_objects` where `property` LIKE ? ESCAPE \'!\'', + 'query' => 'select * from `test_objects` where `field` LIKE ? ESCAPE \'!\'', 'bindings' => ['%!%a[!_]c!!!%%'], ], MySqlGrammar::class, - new Property('property', 'operator name should be ignored'), + new Field('field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('String!', '%a[_]c!%'); }, @@ -102,11 +102,11 @@ static function (self $test): Argument { ], SQLiteGrammar::class => [ [ - 'query' => 'select * from "test_objects" where "property" LIKE ? ESCAPE \'!\'', + 'query' => 'select * from "test_objects" where "field" LIKE ? ESCAPE \'!\'', 'bindings' => ['%!%a[!_]c!!!%%'], ], SQLiteGrammar::class, - new Property('property', 'operator name should be ignored'), + new Field('field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('String!', '%a[_]c!%'); }, @@ -115,11 +115,11 @@ static function (self $test): Argument { ], PostgresGrammar::class => [ [ - 'query' => 'select * from "test_objects" where "property" LIKE ? ESCAPE \'!\'', + 'query' => 'select * from "test_objects" where "field" LIKE ? ESCAPE \'!\'', 'bindings' => ['%!%a[!_]c!!!%%'], ], PostgresGrammar::class, - new Property('property', 'operator name should be ignored'), + new Field('field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('String!', '%a[_]c!%'); }, @@ -128,24 +128,24 @@ static function (self $test): Argument { ], SqlServerGrammar::class => [ [ - 'query' => 'select * from [test_objects] where [property] LIKE ? ESCAPE \'!\'', + 'query' => 'select * from [test_objects] where [field] LIKE ? ESCAPE \'!\'', 'bindings' => ['%!%a![!_!]c!!!%%'], ], SqlServerGrammar::class, - new Property('property', 'operator name should be ignored'), + new Field('field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('String!', '%a[_]c!%'); }, null, null, ], - 'property.path' => [ + 'field.path' => [ [ - 'query' => 'select * from "test_objects" where "path"."to"."property" LIKE ? ESCAPE \'!\'', + 'query' => 'select * from "test_objects" where "path"."to"."field" LIKE ? ESCAPE \'!\'', 'bindings' => ['%!%a[!_]c!!!%%'], ], SQLiteGrammar::class, - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('String!', '%a[_]c!%'); }, @@ -154,17 +154,17 @@ static function (self $test): Argument { ], 'resolver' => [ [ - 'query' => 'select * from "test_objects" where "path__to__property" LIKE ? ESCAPE \'!\'', + 'query' => 'select * from "test_objects" where "path__to__field" LIKE ? ESCAPE \'!\'', 'bindings' => ['%!%a[!_]c!!!%%'], ], SQLiteGrammar::class, - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('String!', '%a[_]c!%'); }, null, - static function (object $builder, Property $property): string { - return implode('__', $property->getPath()); + static function (object $builder, Field $field): string { + return implode('__', $field->getPath()); }, ], ]), diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/EndsWith.php b/packages/graphql/src/SearchBy/Operators/Comparison/EndsWith.php index c46fbb2cc..64fe2cc50 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/EndsWith.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/EndsWith.php @@ -11,7 +11,7 @@ public static function getName(): string { } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Ends with a string.'; } diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/EndsWithTest.php b/packages/graphql/src/SearchBy/Operators/Comparison/EndsWithTest.php index 7f03977ef..445c86196 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/EndsWithTest.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/EndsWithTest.php @@ -4,7 +4,7 @@ use Closure; use LastDragon_ru\LaraASP\GraphQL\Builder\Context; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Directives\Directive; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\DataProviders\BuilderDataProvider; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\OperatorTests; @@ -34,12 +34,12 @@ final class EndsWithTest extends TestCase { * @param BuilderFactory $builderFactory * @param Closure(static): Argument $argumentFactory * @param Closure(static): Context|null $contextFactory - * @param Closure(object, Property): string|null $resolver + * @param Closure(object, Field): string|null $resolver */ public function testCall( array $expected, Closure $builderFactory, - Property $property, + Field $field, Closure $argumentFactory, ?Closure $contextFactory, ?Closure $resolver, @@ -48,7 +48,7 @@ public function testCall( Directive::class, $expected, $builderFactory, - $property, + $field, $argumentFactory, $contextFactory, $resolver, @@ -65,42 +65,42 @@ public static function dataProviderCall(): array { return (new CompositeDataProvider( new BuilderDataProvider(), new ArrayDataProvider([ - 'property' => [ + 'field' => [ [ - 'query' => 'select * from "test_objects" where "property" LIKE ? ESCAPE \'!\'', + 'query' => 'select * from "test_objects" where "field" LIKE ? ESCAPE \'!\'', 'bindings' => ['%!%a[!_]c!!!%'], ], - new Property('property', 'operator name should be ignored'), + new Field('field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('String!', '%a[_]c!%'); }, null, null, ], - 'property.path' => [ + 'field.path' => [ [ - 'query' => 'select * from "test_objects" where "path"."to"."property" LIKE ? ESCAPE \'!\'', + 'query' => 'select * from "test_objects" where "path"."to"."field" LIKE ? ESCAPE \'!\'', 'bindings' => ['%abc'], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('String!', 'abc'); }, null, null, ], - 'resolver' => [ + 'resolver' => [ [ - 'query' => 'select * from "test_objects" where "path__to__property" LIKE ? ESCAPE \'!\'', + 'query' => 'select * from "test_objects" where "path__to__field" LIKE ? ESCAPE \'!\'', 'bindings' => ['%abc'], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('String!', 'abc'); }, null, - static function (object $builder, Property $property): string { - return implode('__', $property->getPath()); + static function (object $builder, Field $field): string { + return implode('__', $field->getPath()); }, ], ]), diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/Equal.php b/packages/graphql/src/SearchBy/Operators/Comparison/Equal.php index e321b34f1..b29f098b7 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/Equal.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/Equal.php @@ -8,7 +8,7 @@ use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Context; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Handler; use LastDragon_ru\LaraASP\GraphQL\Builder\Exceptions\OperatorUnsupportedBuilder; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\Builder\Traits\WithScoutSupport; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Operators\Operator; use Nuwave\Lighthouse\Execution\Arguments\Argument; @@ -23,7 +23,7 @@ public static function getName(): string { } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Equal (`=`).'; } @@ -31,17 +31,17 @@ public function getFieldDescription(): string { public function call( Handler $handler, object $builder, - Property $property, + Field $field, Argument $argument, Context $context, ): object { - $property = $this->resolver->getProperty($builder, $property->getParent()); - $value = $argument->toPlain(); + $field = $this->resolver->getField($builder, $field->getParent()); + $value = $argument->toPlain(); if ($builder instanceof EloquentBuilder || $builder instanceof QueryBuilder) { - $builder->where($property, '=', $value); + $builder->where($field, '=', $value); } elseif ($builder instanceof ScoutBuilder) { - $builder->where($property, $value); + $builder->where($field, $value); } else { throw new OperatorUnsupportedBuilder($this, $builder); } diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/EqualTest.php b/packages/graphql/src/SearchBy/Operators/Comparison/EqualTest.php index 5bf138c66..f099768de 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/EqualTest.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/EqualTest.php @@ -7,6 +7,7 @@ use Laravel\Scout\Builder as ScoutBuilder; use LastDragon_ru\LaraASP\GraphQL\Builder\Context; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Scout\FieldResolver; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\Builder\Property; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Directives\Directive; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\DataProviders\BuilderDataProvider; @@ -40,12 +41,12 @@ final class EqualTest extends TestCase { * @param BuilderFactory $builderFactory * @param Closure(static): Argument $argumentFactory * @param Closure(static): Context|null $contextFactory - * @param Closure(object, Property): string|null $resolver + * @param Closure(object, Field): string|null $resolver */ public function testCall( array $expected, Closure $builderFactory, - Property $property, + Field $field, Closure $argumentFactory, ?Closure $contextFactory, ?Closure $resolver, @@ -54,7 +55,7 @@ public function testCall( Directive::class, $expected, $builderFactory, - $property, + $field, $argumentFactory, $contextFactory, $resolver, @@ -64,18 +65,18 @@ public function testCall( /** * @dataProvider dataProviderCallScout * - * @param array $expected - * @param Closure(static): ScoutBuilder $builderFactory - * @param Closure(static): Argument $argumentFactory - * @param Closure(static): Context|null $contextFactory - * @param Closure(object, Property): string|null $resolver - * @param Closure():FieldResolver|null $fieldResolver + * @param array $expected + * @param Closure(static): ScoutBuilder $builderFactory + * @param Closure(static): Argument $argumentFactory + * @param Closure(static): Context|null $contextFactory + * @param Closure(object, Field): string|null $resolver + * @param Closure():FieldResolver|null $fieldResolver */ #[RequiresLaravelScout] public function testCallScoutBuilder( array $expected, Closure $builderFactory, - Property $property, + Field $field, Closure $argumentFactory, ?Closure $contextFactory, ?Closure $resolver, @@ -89,7 +90,7 @@ public function testCallScoutBuilder( Directive::class, $expected, $builderFactory, - $property, + $field, $argumentFactory, $contextFactory, $resolver, @@ -106,42 +107,42 @@ public static function dataProviderCall(): array { return (new CompositeDataProvider( new BuilderDataProvider(), new ArrayDataProvider([ - 'property' => [ + 'field' => [ [ - 'query' => 'select * from "test_objects" where "property" = ?', + 'query' => 'select * from "test_objects" where "field" = ?', 'bindings' => ['abc'], ], - new Property('property', 'operator name should be ignored'), + new Field('field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('String!', 'abc'); }, null, null, ], - 'property.path' => [ + 'field.path' => [ [ - 'query' => 'select * from "test_objects" where "path"."to"."property" = ?', + 'query' => 'select * from "test_objects" where "path"."to"."field" = ?', 'bindings' => [123], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('Int!', 123); }, null, null, ], - 'resolver' => [ + 'resolver' => [ [ - 'query' => 'select * from "test_objects" where "path__to__property" = ?', + 'query' => 'select * from "test_objects" where "path__to__field" = ?', 'bindings' => [123], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('Int!', 123); }, null, - static function (object $builder, Property $property): string { - return implode('__', $property->getPath()); + static function (object $builder, Field $field): string { + return implode('__', $field->getPath()); }, ], ]), @@ -155,13 +156,13 @@ public static function dataProviderCallScout(): array { return (new CompositeDataProvider( new ScoutBuilderDataProvider(), new ArrayDataProvider([ - 'property' => [ + 'field' => [ [ 'wheres' => [ - 'path.to.property' => 'abc', + 'path.to.field' => 'abc', ], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('String!', 'abc'); }, @@ -193,16 +194,16 @@ public function getField(Model $model, Property $property): string { 'resolver' => [ [ 'wheres' => [ - 'path__to__property' => 'abc', + 'path__to__field' => 'abc', ], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('String!', 'abc'); }, null, - static function (object $builder, Property $property): string { - return implode('__', $property->getPath()); + static function (object $builder, Field $field): string { + return implode('__', $field->getPath()); }, null, ], diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/GreaterThan.php b/packages/graphql/src/SearchBy/Operators/Comparison/GreaterThan.php index 5778cf647..6bb2a825d 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/GreaterThan.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/GreaterThan.php @@ -7,7 +7,7 @@ use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Context; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Handler; use LastDragon_ru\LaraASP\GraphQL\Builder\Exceptions\OperatorUnsupportedBuilder; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Operators\Operator; use Nuwave\Lighthouse\Execution\Arguments\Argument; use Override; @@ -19,7 +19,7 @@ public static function getName(): string { } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Greater than (`>`).'; } @@ -27,7 +27,7 @@ public function getFieldDescription(): string { public function call( Handler $handler, object $builder, - Property $property, + Field $field, Argument $argument, Context $context, ): object { @@ -35,10 +35,10 @@ public function call( throw new OperatorUnsupportedBuilder($this, $builder); } - $property = $this->resolver->getProperty($builder, $property->getParent()); - $value = $argument->toPlain(); + $field = $this->resolver->getField($builder, $field->getParent()); + $value = $argument->toPlain(); - $builder->where($property, '>', $value); + $builder->where($field, '>', $value); return $builder; } diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/GreaterThanOrEqual.php b/packages/graphql/src/SearchBy/Operators/Comparison/GreaterThanOrEqual.php index c58a5400e..48cd90ba0 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/GreaterThanOrEqual.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/GreaterThanOrEqual.php @@ -7,7 +7,7 @@ use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Context; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Handler; use LastDragon_ru\LaraASP\GraphQL\Builder\Exceptions\OperatorUnsupportedBuilder; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Operators\Operator; use Nuwave\Lighthouse\Execution\Arguments\Argument; use Override; @@ -19,7 +19,7 @@ public static function getName(): string { } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Greater than or equal to (`>=`).'; } @@ -27,7 +27,7 @@ public function getFieldDescription(): string { public function call( Handler $handler, object $builder, - Property $property, + Field $field, Argument $argument, Context $context, ): object { @@ -35,10 +35,10 @@ public function call( throw new OperatorUnsupportedBuilder($this, $builder); } - $property = $this->resolver->getProperty($builder, $property->getParent()); - $value = $argument->toPlain(); + $field = $this->resolver->getField($builder, $field->getParent()); + $value = $argument->toPlain(); - $builder->where($property, '>=', $value); + $builder->where($field, '>=', $value); return $builder; } diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/GreaterThanOrEqualTest.php b/packages/graphql/src/SearchBy/Operators/Comparison/GreaterThanOrEqualTest.php index 6a9e8e0aa..4a4df0f61 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/GreaterThanOrEqualTest.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/GreaterThanOrEqualTest.php @@ -4,7 +4,7 @@ use Closure; use LastDragon_ru\LaraASP\GraphQL\Builder\Context; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Directives\Directive; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\DataProviders\BuilderDataProvider; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\OperatorTests; @@ -34,12 +34,12 @@ final class GreaterThanOrEqualTest extends TestCase { * @param BuilderFactory $builderFactory * @param Closure(static): Argument $argumentFactory * @param Closure(static): Context|null $contextFactory - * @param Closure(object, Property): string|null $resolver + * @param Closure(object, Field): string|null $resolver */ public function testCall( array $expected, Closure $builderFactory, - Property $property, + Field $field, Closure $argumentFactory, ?Closure $contextFactory, ?Closure $resolver, @@ -48,7 +48,7 @@ public function testCall( Directive::class, $expected, $builderFactory, - $property, + $field, $argumentFactory, $contextFactory, $resolver, @@ -65,42 +65,42 @@ public static function dataProviderCall(): array { return (new CompositeDataProvider( new BuilderDataProvider(), new ArrayDataProvider([ - 'property' => [ + 'field' => [ [ - 'query' => 'select * from "test_objects" where "property" >= ?', + 'query' => 'select * from "test_objects" where "field" >= ?', 'bindings' => [123], ], - new Property('property', 'operator name should be ignored'), + new Field('field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('Int!', 123); }, null, null, ], - 'property.path' => [ + 'field.path' => [ [ - 'query' => 'select * from "test_objects" where "path"."to"."property" >= ?', + 'query' => 'select * from "test_objects" where "path"."to"."field" >= ?', 'bindings' => [321], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('Int!', 321); }, null, null, ], - 'resolver' => [ + 'resolver' => [ [ - 'query' => 'select * from "test_objects" where "path__to__property" >= ?', + 'query' => 'select * from "test_objects" where "path__to__field" >= ?', 'bindings' => [321], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('Int!', 321); }, null, - static function (object $builder, Property $property): string { - return implode('__', $property->getPath()); + static function (object $builder, Field $field): string { + return implode('__', $field->getPath()); }, ], ]), diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/GreaterThanTest.php b/packages/graphql/src/SearchBy/Operators/Comparison/GreaterThanTest.php index cf3c63480..401c17424 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/GreaterThanTest.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/GreaterThanTest.php @@ -4,7 +4,7 @@ use Closure; use LastDragon_ru\LaraASP\GraphQL\Builder\Context; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Directives\Directive; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\DataProviders\BuilderDataProvider; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\OperatorTests; @@ -34,12 +34,12 @@ final class GreaterThanTest extends TestCase { * @param BuilderFactory $builderFactory * @param Closure(static): Argument $argumentFactory * @param Closure(static): Context|null $contextFactory - * @param Closure(object, Property): string|null $resolver + * @param Closure(object, Field): string|null $resolver */ public function testCall( array $expected, Closure $builderFactory, - Property $property, + Field $field, Closure $argumentFactory, ?Closure $contextFactory, ?Closure $resolver, @@ -48,7 +48,7 @@ public function testCall( Directive::class, $expected, $builderFactory, - $property, + $field, $argumentFactory, $contextFactory, $resolver, @@ -65,42 +65,42 @@ public static function dataProviderCall(): array { return (new CompositeDataProvider( new BuilderDataProvider(), new ArrayDataProvider([ - 'property' => [ + 'field' => [ [ - 'query' => 'select * from "test_objects" where "property" > ?', + 'query' => 'select * from "test_objects" where "field" > ?', 'bindings' => [123], ], - new Property('property', 'operator name should be ignored'), + new Field('field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('Int!', 123); }, null, null, ], - 'property.path' => [ + 'field.path' => [ [ - 'query' => 'select * from "test_objects" where "path"."to"."property" > ?', + 'query' => 'select * from "test_objects" where "path"."to"."field" > ?', 'bindings' => [321], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('Int!', 321); }, null, null, ], - 'resolver' => [ + 'resolver' => [ [ - 'query' => 'select * from "test_objects" where "path__to__property" > ?', + 'query' => 'select * from "test_objects" where "path__to__field" > ?', 'bindings' => [321], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('Int!', 321); }, null, - static function (object $builder, Property $property): string { - return implode('__', $property->getPath()); + static function (object $builder, Field $field): string { + return implode('__', $field->getPath()); }, ], ]), diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/In.php b/packages/graphql/src/SearchBy/Operators/Comparison/In.php index 5be89f857..45fde623e 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/In.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/In.php @@ -10,7 +10,7 @@ use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\TypeProvider; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\TypeSource; use LastDragon_ru\LaraASP\GraphQL\Builder\Exceptions\OperatorUnsupportedBuilder; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\Builder\Traits\WithScoutSupport; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Operators\Operator; use Nuwave\Lighthouse\Execution\Arguments\Argument; @@ -25,12 +25,12 @@ public static function getName(): string { } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Within a set of values.'; } #[Override] - public function getFieldType(TypeProvider $provider, TypeSource $source, Context $context): string { + public function getFieldType(TypeProvider $provider, TypeSource $source, Context $context): ?string { return "[{$source->getTypeName()}!]"; } @@ -38,17 +38,17 @@ public function getFieldType(TypeProvider $provider, TypeSource $source, Context public function call( Handler $handler, object $builder, - Property $property, + Field $field, Argument $argument, Context $context, ): object { - $property = $this->resolver->getProperty($builder, $property->getParent()); - $value = (array) $argument->toPlain(); + $field = $this->resolver->getField($builder, $field->getParent()); + $value = (array) $argument->toPlain(); if ($builder instanceof EloquentBuilder || $builder instanceof QueryBuilder) { - $builder->whereIn($property, $value); + $builder->whereIn($field, $value); } elseif ($builder instanceof ScoutBuilder) { - $builder->whereIn($property, $value); + $builder->whereIn($field, $value); } else { throw new OperatorUnsupportedBuilder($this, $builder); } diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/InTest.php b/packages/graphql/src/SearchBy/Operators/Comparison/InTest.php index f882300ec..ba4888418 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/InTest.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/InTest.php @@ -7,6 +7,7 @@ use Laravel\Scout\Builder as ScoutBuilder; use LastDragon_ru\LaraASP\GraphQL\Builder\Context; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Scout\FieldResolver; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\Builder\Property; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Directives\Directive; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\DataProviders\BuilderDataProvider; @@ -40,12 +41,12 @@ final class InTest extends TestCase { * @param BuilderFactory $builderFactory * @param Closure(static): Argument $argumentFactory * @param Closure(static): Context|null $contextFactory - * @param Closure(object, Property): string|null $resolver + * @param Closure(object, Field): string|null $resolver */ public function testCall( array $expected, Closure $builderFactory, - Property $property, + Field $field, Closure $argumentFactory, ?Closure $contextFactory, ?Closure $resolver, @@ -54,7 +55,7 @@ public function testCall( Directive::class, $expected, $builderFactory, - $property, + $field, $argumentFactory, $contextFactory, $resolver, @@ -64,18 +65,18 @@ public function testCall( /** * @dataProvider dataProviderCallScout * - * @param array $expected - * @param Closure(static): ScoutBuilder $builderFactory - * @param Closure(static): Argument $argumentFactory - * @param Closure(static): Context|null $contextFactory - * @param Closure(object, Property): string|null $resolver - * @param Closure():FieldResolver|null $fieldResolver + * @param array $expected + * @param Closure(static): ScoutBuilder $builderFactory + * @param Closure(static): Argument $argumentFactory + * @param Closure(static): Context|null $contextFactory + * @param Closure(object, Field): string|null $resolver + * @param Closure():FieldResolver|null $fieldResolver */ #[RequiresLaravelScout] public function testCallScoutBuilder( array $expected, Closure $builderFactory, - Property $property, + Field $field, Closure $argumentFactory, ?Closure $contextFactory, ?Closure $resolver, @@ -89,7 +90,7 @@ public function testCallScoutBuilder( Directive::class, $expected, $builderFactory, - $property, + $field, $argumentFactory, $contextFactory, $resolver, @@ -106,42 +107,42 @@ public static function dataProviderCall(): array { return (new CompositeDataProvider( new BuilderDataProvider(), new ArrayDataProvider([ - 'property' => [ + 'field' => [ [ - 'query' => 'select * from "test_objects" where "property" in (?, ?, ?)', + 'query' => 'select * from "test_objects" where "field" in (?, ?, ?)', 'bindings' => [1, 2, 3], ], - new Property('property', 'operator name should be ignored'), + new Field('field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('[Int!]!', [1, 2, 3]); }, null, null, ], - 'property.path' => [ + 'field.path' => [ [ - 'query' => 'select * from "test_objects" where "path"."to"."property" in (?, ?, ?)', + 'query' => 'select * from "test_objects" where "path"."to"."field" in (?, ?, ?)', 'bindings' => ['a', 'b', 'c'], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('[String!]!', ['a', 'b', 'c']); }, null, null, ], - 'resolver' => [ + 'resolver' => [ [ - 'query' => 'select * from "test_objects" where "path__to__property" in (?, ?, ?)', + 'query' => 'select * from "test_objects" where "path__to__field" in (?, ?, ?)', 'bindings' => ['a', 'b', 'c'], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('[String!]!', ['a', 'b', 'c']); }, null, - static function (object $builder, Property $property): string { - return implode('__', $property->getPath()); + static function (object $builder, Field $field): string { + return implode('__', $field->getPath()); }, ], ]), @@ -155,13 +156,13 @@ public static function dataProviderCallScout(): array { return (new CompositeDataProvider( new ScoutBuilderDataProvider(), new ArrayDataProvider([ - 'property' => [ + 'field' => [ [ 'whereIns' => [ - 'path.to.property' => [1, 2, 3], + 'path.to.field' => [1, 2, 3], ], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('[Int!]!', [1, 2, 3]); }, @@ -196,16 +197,16 @@ public function getField(Model $model, Property $property): string { 'resolver' => [ [ 'whereIns' => [ - 'path__to__property' => [1, 2, 3], + 'path__to__field' => [1, 2, 3], ], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('[Int!]!', [1, 2, 3]); }, null, - static function (object $builder, Property $property): string { - return implode('__', $property->getPath()); + static function (object $builder, Field $field): string { + return implode('__', $field->getPath()); }, null, ], diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/IsNotNull.php b/packages/graphql/src/SearchBy/Operators/Comparison/IsNotNull.php index 5074edb2e..30f53d6a7 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/IsNotNull.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/IsNotNull.php @@ -9,7 +9,7 @@ use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\TypeProvider; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\TypeSource; use LastDragon_ru\LaraASP\GraphQL\Builder\Exceptions\OperatorUnsupportedBuilder; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Operators\Operator; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Types\Flag; use Nuwave\Lighthouse\Execution\Arguments\Argument; @@ -25,12 +25,12 @@ public static function getName(): string { } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Is NOT NULL?'; } #[Override] - public function getFieldType(TypeProvider $provider, TypeSource $source, Context $context): string { + public function getFieldType(TypeProvider $provider, TypeSource $source, Context $context): ?string { return $provider->getType(Flag::class, $source, $context); } @@ -38,7 +38,7 @@ public function getFieldType(TypeProvider $provider, TypeSource $source, Context public function call( Handler $handler, object $builder, - Property $property, + Field $field, Argument $argument, Context $context, ): object { @@ -46,9 +46,9 @@ public function call( throw new OperatorUnsupportedBuilder($this, $builder); } - $property = $this->resolver->getProperty($builder, $property->getParent()); + $field = $this->resolver->getField($builder, $field->getParent()); - $builder->whereNotNull($property); + $builder->whereNotNull($field); return $builder; } diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/IsNotNullTest.php b/packages/graphql/src/SearchBy/Operators/Comparison/IsNotNullTest.php index a4a2ad6fe..e73ac7d97 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/IsNotNullTest.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/IsNotNullTest.php @@ -4,7 +4,7 @@ use Closure; use LastDragon_ru\LaraASP\GraphQL\Builder\Context; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Directives\Directive; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\DataProviders\BuilderDataProvider; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\OperatorTests; @@ -34,12 +34,12 @@ final class IsNotNullTest extends TestCase { * @param BuilderFactory $builderFactory * @param Closure(static): Argument $argumentFactory * @param Closure(static): Context|null $contextFactory - * @param Closure(object, Property): string|null $resolver + * @param Closure(object, Field): string|null $resolver */ public function testCall( array $expected, Closure $builderFactory, - Property $property, + Field $field, Closure $argumentFactory, ?Closure $contextFactory, ?Closure $resolver, @@ -48,7 +48,7 @@ public function testCall( Directive::class, $expected, $builderFactory, - $property, + $field, $argumentFactory, $contextFactory, $resolver, @@ -65,42 +65,42 @@ public static function dataProviderCall(): array { return (new CompositeDataProvider( new BuilderDataProvider(), new ArrayDataProvider([ - 'property' => [ + 'field' => [ [ - 'query' => 'select * from "test_objects" where "property" is not null', + 'query' => 'select * from "test_objects" where "field" is not null', 'bindings' => [], ], - new Property('property', 'operator name should be ignored'), + new Field('field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('Boolean', null); }, null, null, ], - 'property.path' => [ + 'field.path' => [ [ - 'query' => 'select * from "test_objects" where "path"."to"."property" is not null', + 'query' => 'select * from "test_objects" where "path"."to"."field" is not null', 'bindings' => [], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('Boolean', null); }, null, null, ], - 'resolver' => [ + 'resolver' => [ [ - 'query' => 'select * from "test_objects" where "path__to__property" is not null', + 'query' => 'select * from "test_objects" where "path__to__field" is not null', 'bindings' => [], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('Boolean', null); }, null, - static function (object $builder, Property $property): string { - return implode('__', $property->getPath()); + static function (object $builder, Field $field): string { + return implode('__', $field->getPath()); }, ], ]), diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/IsNull.php b/packages/graphql/src/SearchBy/Operators/Comparison/IsNull.php index 79c17ca65..383da73ea 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/IsNull.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/IsNull.php @@ -9,7 +9,7 @@ use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\TypeProvider; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\TypeSource; use LastDragon_ru\LaraASP\GraphQL\Builder\Exceptions\OperatorUnsupportedBuilder; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Operators\Operator; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Types\Flag; use Nuwave\Lighthouse\Execution\Arguments\Argument; @@ -25,12 +25,12 @@ public static function getName(): string { } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Is NULL?'; } #[Override] - public function getFieldType(TypeProvider $provider, TypeSource $source, Context $context): string { + public function getFieldType(TypeProvider $provider, TypeSource $source, Context $context): ?string { return $provider->getType(Flag::class, $source, $context); } @@ -38,7 +38,7 @@ public function getFieldType(TypeProvider $provider, TypeSource $source, Context public function call( Handler $handler, object $builder, - Property $property, + Field $field, Argument $argument, Context $context, ): object { @@ -46,9 +46,9 @@ public function call( throw new OperatorUnsupportedBuilder($this, $builder); } - $property = $this->resolver->getProperty($builder, $property->getParent()); + $field = $this->resolver->getField($builder, $field->getParent()); - $builder->whereNull($property); + $builder->whereNull($field); return $builder; } diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/IsNullTest.php b/packages/graphql/src/SearchBy/Operators/Comparison/IsNullTest.php index b3bd0d2c9..8a5b5403f 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/IsNullTest.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/IsNullTest.php @@ -4,7 +4,7 @@ use Closure; use LastDragon_ru\LaraASP\GraphQL\Builder\Context; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Directives\Directive; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\DataProviders\BuilderDataProvider; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\OperatorTests; @@ -34,12 +34,12 @@ final class IsNullTest extends TestCase { * @param BuilderFactory $builderFactory * @param Closure(static): Argument $argumentFactory * @param Closure(static): Context|null $contextFactory - * @param Closure(object, Property): string|null $resolver + * @param Closure(object, Field): string|null $resolver */ public function testCall( array $expected, Closure $builderFactory, - Property $property, + Field $field, Closure $argumentFactory, ?Closure $contextFactory, ?Closure $resolver, @@ -48,7 +48,7 @@ public function testCall( Directive::class, $expected, $builderFactory, - $property, + $field, $argumentFactory, $contextFactory, $resolver, @@ -65,42 +65,42 @@ public static function dataProviderCall(): array { return (new CompositeDataProvider( new BuilderDataProvider(), new ArrayDataProvider([ - 'property' => [ + 'field' => [ [ - 'query' => 'select * from "test_objects" where "property" is null', + 'query' => 'select * from "test_objects" where "field" is null', 'bindings' => [], ], - new Property('property', 'operator name should be ignored'), + new Field('field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('Boolean', null); }, null, null, ], - 'property.path' => [ + 'field.path' => [ [ - 'query' => 'select * from "test_objects" where "path"."to"."property" is null', + 'query' => 'select * from "test_objects" where "path"."to"."field" is null', 'bindings' => [], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('Boolean', null); }, null, null, ], - 'resolver' => [ + 'resolver' => [ [ - 'query' => 'select * from "test_objects" where "path__to__property" is null', + 'query' => 'select * from "test_objects" where "path__to__field" is null', 'bindings' => [], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('Boolean', null); }, null, - static function (object $builder, Property $property): string { - return implode('__', $property->getPath()); + static function (object $builder, Field $field): string { + return implode('__', $field->getPath()); }, ], ]), diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/LessThan.php b/packages/graphql/src/SearchBy/Operators/Comparison/LessThan.php index 09945da6e..38a8e3f59 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/LessThan.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/LessThan.php @@ -7,7 +7,7 @@ use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Context; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Handler; use LastDragon_ru\LaraASP\GraphQL\Builder\Exceptions\OperatorUnsupportedBuilder; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Operators\Operator; use Nuwave\Lighthouse\Execution\Arguments\Argument; use Override; @@ -19,7 +19,7 @@ public static function getName(): string { } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Less than (`<`).'; } @@ -27,7 +27,7 @@ public function getFieldDescription(): string { public function call( Handler $handler, object $builder, - Property $property, + Field $field, Argument $argument, Context $context, ): object { @@ -35,10 +35,10 @@ public function call( throw new OperatorUnsupportedBuilder($this, $builder); } - $property = $this->resolver->getProperty($builder, $property->getParent()); - $value = $argument->toPlain(); + $field = $this->resolver->getField($builder, $field->getParent()); + $value = $argument->toPlain(); - $builder->where($property, '<', $value); + $builder->where($field, '<', $value); return $builder; } diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/LessThanOrEqual.php b/packages/graphql/src/SearchBy/Operators/Comparison/LessThanOrEqual.php index fad4d1d5e..bad619a8a 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/LessThanOrEqual.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/LessThanOrEqual.php @@ -7,7 +7,7 @@ use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Context; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Handler; use LastDragon_ru\LaraASP\GraphQL\Builder\Exceptions\OperatorUnsupportedBuilder; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Operators\Operator; use Nuwave\Lighthouse\Execution\Arguments\Argument; use Override; @@ -19,7 +19,7 @@ public static function getName(): string { } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Less than or equal to (`<=`).'; } @@ -27,7 +27,7 @@ public function getFieldDescription(): string { public function call( Handler $handler, object $builder, - Property $property, + Field $field, Argument $argument, Context $context, ): object { @@ -35,10 +35,10 @@ public function call( throw new OperatorUnsupportedBuilder($this, $builder); } - $property = $this->resolver->getProperty($builder, $property->getParent()); - $value = $argument->toPlain(); + $field = $this->resolver->getField($builder, $field->getParent()); + $value = $argument->toPlain(); - $builder->where($property, '<=', $value); + $builder->where($field, '<=', $value); return $builder; } diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/LessThanOrEqualTest.php b/packages/graphql/src/SearchBy/Operators/Comparison/LessThanOrEqualTest.php index d1508ed6c..cdd36b32e 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/LessThanOrEqualTest.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/LessThanOrEqualTest.php @@ -4,7 +4,7 @@ use Closure; use LastDragon_ru\LaraASP\GraphQL\Builder\Context; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Directives\Directive; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\DataProviders\BuilderDataProvider; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\OperatorTests; @@ -34,12 +34,12 @@ final class LessThanOrEqualTest extends TestCase { * @param BuilderFactory $builderFactory * @param Closure(static): Argument $argumentFactory * @param Closure(static): Context|null $contextFactory - * @param Closure(object, Property): string|null $resolver + * @param Closure(object, Field): string|null $resolver */ public function testCall( array $expected, Closure $builderFactory, - Property $property, + Field $field, Closure $argumentFactory, ?Closure $contextFactory, ?Closure $resolver, @@ -48,7 +48,7 @@ public function testCall( Directive::class, $expected, $builderFactory, - $property, + $field, $argumentFactory, $contextFactory, $resolver, @@ -65,42 +65,42 @@ public static function dataProviderCall(): array { return (new CompositeDataProvider( new BuilderDataProvider(), new ArrayDataProvider([ - 'property' => [ + 'field' => [ [ - 'query' => 'select * from "test_objects" where "property" <= ?', + 'query' => 'select * from "test_objects" where "field" <= ?', 'bindings' => [123], ], - new Property('property', 'operator name should be ignored'), + new Field('field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('Int!', 123); }, null, null, ], - 'property.path' => [ + 'field.path' => [ [ - 'query' => 'select * from "test_objects" where "path"."to"."property" <= ?', + 'query' => 'select * from "test_objects" where "path"."to"."field" <= ?', 'bindings' => [321], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('Int!', 321); }, null, null, ], - 'resolver' => [ + 'resolver' => [ [ - 'query' => 'select * from "test_objects" where "path__to__property" <= ?', + 'query' => 'select * from "test_objects" where "path__to__field" <= ?', 'bindings' => [321], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('Int!', 321); }, null, - static function (object $builder, Property $property): string { - return implode('__', $property->getPath()); + static function (object $builder, Field $field): string { + return implode('__', $field->getPath()); }, ], ]), diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/LessThanTest.php b/packages/graphql/src/SearchBy/Operators/Comparison/LessThanTest.php index 8db0dfeda..ecf51c826 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/LessThanTest.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/LessThanTest.php @@ -4,7 +4,7 @@ use Closure; use LastDragon_ru\LaraASP\GraphQL\Builder\Context; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Directives\Directive; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\DataProviders\BuilderDataProvider; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\OperatorTests; @@ -34,12 +34,12 @@ final class LessThanTest extends TestCase { * @param BuilderFactory $builderFactory * @param Closure(static): Argument $argumentFactory * @param Closure(static): Context|null $contextFactory - * @param Closure(object, Property): string|null $resolver + * @param Closure(object, Field): string|null $resolver */ public function testCall( array $expected, Closure $builderFactory, - Property $property, + Field $field, Closure $argumentFactory, ?Closure $contextFactory, ?Closure $resolver, @@ -48,7 +48,7 @@ public function testCall( Directive::class, $expected, $builderFactory, - $property, + $field, $argumentFactory, $contextFactory, $resolver, @@ -65,42 +65,42 @@ public static function dataProviderCall(): array { return (new CompositeDataProvider( new BuilderDataProvider(), new ArrayDataProvider([ - 'property' => [ + 'field' => [ [ - 'query' => 'select * from "test_objects" where "property" < ?', + 'query' => 'select * from "test_objects" where "field" < ?', 'bindings' => [123], ], - new Property('property', 'operator name should be ignored'), + new Field('field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('Int!', 123); }, null, null, ], - 'property.path' => [ + 'field.path' => [ [ - 'query' => 'select * from "test_objects" where "path"."to"."property" < ?', + 'query' => 'select * from "test_objects" where "path"."to"."field" < ?', 'bindings' => [321], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('Int!', 321); }, null, null, ], - 'resolve' => [ + 'resolve' => [ [ - 'query' => 'select * from "test_objects" where "path__to__property" < ?', + 'query' => 'select * from "test_objects" where "path__to__field" < ?', 'bindings' => [321], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('Int!', 321); }, null, - static function (object $builder, Property $property): string { - return implode('__', $property->getPath()); + static function (object $builder, Field $field): string { + return implode('__', $field->getPath()); }, ], ]), diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/Like.php b/packages/graphql/src/SearchBy/Operators/Comparison/Like.php index bfc2be694..c2086fba7 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/Like.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/Like.php @@ -8,7 +8,7 @@ use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Context; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Handler; use LastDragon_ru\LaraASP\GraphQL\Builder\Exceptions\OperatorUnsupportedBuilder; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Operators\Operator; use Nuwave\Lighthouse\Execution\Arguments\Argument; use Override; @@ -20,7 +20,7 @@ public static function getName(): string { } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Like.'; } @@ -28,7 +28,7 @@ public function getFieldDescription(): string { public function call( Handler $handler, object $builder, - Property $property, + Field $field, Argument $argument, Context $context, ): object { @@ -36,10 +36,10 @@ public function call( throw new OperatorUnsupportedBuilder($this, $builder); } - $property = $this->resolver->getProperty($builder, $property->getParent()); - $value = (string) Cast::toStringable($argument->toPlain()); + $field = $this->resolver->getField($builder, $field->getParent()); + $value = (string) Cast::toStringable($argument->toPlain()); - $builder->where($property, 'like', $value); + $builder->where($field, 'like', $value); return $builder; } diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/LikeTest.php b/packages/graphql/src/SearchBy/Operators/Comparison/LikeTest.php index b8796ea7e..653d87e48 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/LikeTest.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/LikeTest.php @@ -4,7 +4,7 @@ use Closure; use LastDragon_ru\LaraASP\GraphQL\Builder\Context; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Directives\Directive; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\DataProviders\BuilderDataProvider; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\OperatorTests; @@ -34,12 +34,12 @@ final class LikeTest extends TestCase { * @param BuilderFactory $builderFactory * @param Closure(static): Argument $argumentFactory * @param Closure(static): Context|null $contextFactory - * @param Closure(object, Property): string|null $resolver + * @param Closure(object, Field): string|null $resolver */ public function testCall( array $expected, Closure $builderFactory, - Property $property, + Field $field, Closure $argumentFactory, ?Closure $contextFactory, ?Closure $resolver, @@ -48,7 +48,7 @@ public function testCall( Directive::class, $expected, $builderFactory, - $property, + $field, $argumentFactory, $contextFactory, $resolver, @@ -65,42 +65,42 @@ public static function dataProviderCall(): array { return (new CompositeDataProvider( new BuilderDataProvider(), new ArrayDataProvider([ - 'property' => [ + 'field' => [ [ - 'query' => 'select * from "test_objects" where "property" like ?', + 'query' => 'select * from "test_objects" where "field" like ?', 'bindings' => ['abc'], ], - new Property('property', 'operator name should be ignored'), + new Field('field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('String!', 'abc'); }, null, null, ], - 'property.path' => [ + 'field.path' => [ [ - 'query' => 'select * from "test_objects" where "path"."to"."property" like ?', + 'query' => 'select * from "test_objects" where "path"."to"."field" like ?', 'bindings' => ['abc'], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('String!', 'abc'); }, null, null, ], - 'resolver' => [ + 'resolver' => [ [ - 'query' => 'select * from "test_objects" where "path__to__property" like ?', + 'query' => 'select * from "test_objects" where "path__to__field" like ?', 'bindings' => ['abc'], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('String!', 'abc'); }, null, - static function (object $builder, Property $property): string { - return implode('__', $property->getPath()); + static function (object $builder, Field $field): string { + return implode('__', $field->getPath()); }, ], ]), diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/NotBetween.php b/packages/graphql/src/SearchBy/Operators/Comparison/NotBetween.php index 7b444ce29..38c7f2d98 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/NotBetween.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/NotBetween.php @@ -8,7 +8,7 @@ use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Context; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Handler; use LastDragon_ru\LaraASP\GraphQL\Builder\Exceptions\OperatorUnsupportedBuilder; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use Nuwave\Lighthouse\Execution\Arguments\Argument; use Override; @@ -19,7 +19,7 @@ public static function getName(): string { } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Outside a range.'; } @@ -27,7 +27,7 @@ public function getFieldDescription(): string { public function call( Handler $handler, object $builder, - Property $property, + Field $field, Argument $argument, Context $context, ): object { @@ -35,10 +35,10 @@ public function call( throw new OperatorUnsupportedBuilder($this, $builder); } - $property = $this->resolver->getProperty($builder, $property->getParent()); - $value = Cast::toIterable($argument->toPlain()); + $field = $this->resolver->getField($builder, $field->getParent()); + $value = Cast::toIterable($argument->toPlain()); - $builder->whereNotBetween($property, $value); + $builder->whereNotBetween($field, $value); return $builder; } diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/NotBetweenTest.php b/packages/graphql/src/SearchBy/Operators/Comparison/NotBetweenTest.php index 4121f1375..0a48bdd6a 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/NotBetweenTest.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/NotBetweenTest.php @@ -4,7 +4,7 @@ use Closure; use LastDragon_ru\LaraASP\GraphQL\Builder\Context; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Directives\Directive; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\DataProviders\BuilderDataProvider; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\OperatorTests; @@ -34,12 +34,12 @@ final class NotBetweenTest extends TestCase { * @param BuilderFactory $builderFactory * @param Closure(static): Argument $argumentFactory * @param Closure(static): Context|null $contextFactory - * @param Closure(object, Property): string|null $resolver + * @param Closure(object, Field): string|null $resolver */ public function testCall( array $expected, Closure $builderFactory, - Property $property, + Field $field, Closure $argumentFactory, ?Closure $contextFactory, ?Closure $resolver, @@ -48,7 +48,7 @@ public function testCall( Directive::class, $expected, $builderFactory, - $property, + $field, $argumentFactory, $contextFactory, $resolver, @@ -65,42 +65,42 @@ public static function dataProviderCall(): array { return (new CompositeDataProvider( new BuilderDataProvider(), new ArrayDataProvider([ - 'property' => [ + 'field' => [ [ - 'query' => 'select * from "test_objects" where "property" not between ? and ?', + 'query' => 'select * from "test_objects" where "field" not between ? and ?', 'bindings' => [1, 2], ], - new Property('property', 'operator name should be ignored'), + new Field('field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('[Int!]!', [1, 2, 3]); }, null, null, ], - 'property.path' => [ + 'field.path' => [ [ - 'query' => 'select * from "test_objects" where "path"."to"."property" not between ? and ?', + 'query' => 'select * from "test_objects" where "path"."to"."field" not between ? and ?', 'bindings' => [1, 2], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('[Int!]!', [1, 2, 3]); }, null, null, ], - 'resolver' => [ + 'resolver' => [ [ - 'query' => 'select * from "test_objects" where "path__to__property" not between ? and ?', + 'query' => 'select * from "test_objects" where "path__to__field" not between ? and ?', 'bindings' => [1, 2], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('[Int!]!', [1, 2, 3]); }, null, - static function (object $builder, Property $property): string { - return implode('__', $property->getPath()); + static function (object $builder, Field $field): string { + return implode('__', $field->getPath()); }, ], ]), diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/NotContains.php b/packages/graphql/src/SearchBy/Operators/Comparison/NotContains.php index 1a28bc91d..4950fb690 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/NotContains.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/NotContains.php @@ -11,7 +11,7 @@ public static function getName(): string { } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Not contains.'; } diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/NotContainsTest.php b/packages/graphql/src/SearchBy/Operators/Comparison/NotContainsTest.php index 2c1367d1c..1dd1d7acc 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/NotContainsTest.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/NotContainsTest.php @@ -10,7 +10,7 @@ use Illuminate\Database\Query\Grammars\SQLiteGrammar; use Illuminate\Database\Query\Grammars\SqlServerGrammar; use LastDragon_ru\LaraASP\GraphQL\Builder\Context; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Directives\Directive; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\DataProviders\BuilderDataProvider; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\OperatorTests; @@ -41,13 +41,13 @@ final class NotContainsTest extends TestCase { * @param class-string $grammar * @param Closure(static): Argument $argumentFactory * @param Closure(static): Context|null $contextFactory - * @param Closure(object, Property): string|null $resolver + * @param Closure(object, Field): string|null $resolver */ public function testCall( array $expected, Closure $builderFactory, string $grammar, - Property $property, + Field $field, Closure $argumentFactory, ?Closure $contextFactory, ?Closure $resolver, @@ -70,7 +70,7 @@ public function testCall( Directive::class, $expected, $builderFactory, - $property, + $field, $argumentFactory, $contextFactory, $resolver, @@ -89,11 +89,11 @@ public static function dataProviderCall(): array { new ArrayDataProvider([ MySqlGrammar::class => [ [ - 'query' => 'select * from `test_objects` where `property` NOT LIKE ? ESCAPE \'!\'', + 'query' => 'select * from `test_objects` where `field` NOT LIKE ? ESCAPE \'!\'', 'bindings' => ['%!%a[!_]c!!!%%'], ], MySqlGrammar::class, - new Property('property', 'operator name should be ignored'), + new Field('field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('String!', '%a[_]c!%'); }, @@ -102,11 +102,11 @@ static function (self $test): Argument { ], SQLiteGrammar::class => [ [ - 'query' => 'select * from "test_objects" where "property" NOT LIKE ? ESCAPE \'!\'', + 'query' => 'select * from "test_objects" where "field" NOT LIKE ? ESCAPE \'!\'', 'bindings' => ['%!%a[!_]c!!!%%'], ], SQLiteGrammar::class, - new Property('property', 'operator name should be ignored'), + new Field('field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('String!', '%a[_]c!%'); }, @@ -115,11 +115,11 @@ static function (self $test): Argument { ], PostgresGrammar::class => [ [ - 'query' => 'select * from "test_objects" where "property" NOT LIKE ? ESCAPE \'!\'', + 'query' => 'select * from "test_objects" where "field" NOT LIKE ? ESCAPE \'!\'', 'bindings' => ['%!%a[!_]c!!!%%'], ], PostgresGrammar::class, - new Property('property', 'operator name should be ignored'), + new Field('field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('String!', '%a[_]c!%'); }, @@ -128,27 +128,27 @@ static function (self $test): Argument { ], SqlServerGrammar::class => [ [ - 'query' => 'select * from [test_objects] where [property] NOT LIKE ? ESCAPE \'!\'', + 'query' => 'select * from [test_objects] where [field] NOT LIKE ? ESCAPE \'!\'', 'bindings' => ['%!%a![!_!]c!!!%%'], ], SqlServerGrammar::class, - new Property('property', 'operator name should be ignored'), + new Field('field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('String!', '%a[_]c!%'); }, null, null, ], - 'property.path' => [ + 'field.path' => [ [ 'query' => <<<'SQL' - select * from "test_objects" where "path"."to"."property" NOT LIKE ? ESCAPE '!' + select * from "test_objects" where "path"."to"."field" NOT LIKE ? ESCAPE '!' SQL , 'bindings' => ['%!%a[!_]c!!!%%'], ], SQLiteGrammar::class, - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('String!', '%a[_]c!%'); }, @@ -157,17 +157,17 @@ static function (self $test): Argument { ], 'resolver' => [ [ - 'query' => 'select * from "test_objects" where "path__to__property" NOT LIKE ? ESCAPE \'!\'', + 'query' => 'select * from "test_objects" where "path__to__field" NOT LIKE ? ESCAPE \'!\'', 'bindings' => ['%!%a[!_]c!!!%%'], ], SQLiteGrammar::class, - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('String!', '%a[_]c!%'); }, null, - static function (object $builder, Property $property): string { - return implode('__', $property->getPath()); + static function (object $builder, Field $field): string { + return implode('__', $field->getPath()); }, ], ]), diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/NotEndsWith.php b/packages/graphql/src/SearchBy/Operators/Comparison/NotEndsWith.php index 8fcda5291..e64f07357 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/NotEndsWith.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/NotEndsWith.php @@ -11,7 +11,7 @@ public static function getName(): string { } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Not ends with a string.'; } diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/NotEndsWithTest.php b/packages/graphql/src/SearchBy/Operators/Comparison/NotEndsWithTest.php index 734459f3c..4e96328ae 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/NotEndsWithTest.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/NotEndsWithTest.php @@ -4,7 +4,7 @@ use Closure; use LastDragon_ru\LaraASP\GraphQL\Builder\Context; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Directives\Directive; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\DataProviders\BuilderDataProvider; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\OperatorTests; @@ -34,12 +34,12 @@ final class NotEndsWithTest extends TestCase { * @param BuilderFactory $builderFactory * @param Closure(static): Argument $argumentFactory * @param Closure(static): Context|null $contextFactory - * @param Closure(object, Property): string|null $resolver + * @param Closure(object, Field): string|null $resolver */ public function testCall( array $expected, Closure $builderFactory, - Property $property, + Field $field, Closure $argumentFactory, ?Closure $contextFactory, ?Closure $resolver, @@ -48,7 +48,7 @@ public function testCall( Directive::class, $expected, $builderFactory, - $property, + $field, $argumentFactory, $contextFactory, $resolver, @@ -65,48 +65,48 @@ public static function dataProviderCall(): array { return (new CompositeDataProvider( new BuilderDataProvider(), new ArrayDataProvider([ - 'property' => [ + 'field' => [ [ - 'query' => 'select * from "test_objects" where "property" NOT LIKE ? ESCAPE \'!\'', + 'query' => 'select * from "test_objects" where "field" NOT LIKE ? ESCAPE \'!\'', 'bindings' => ['%!%a[!_]c!!!%'], ], - new Property('property', 'operator name should be ignored'), + new Field('field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('String!', '%a[_]c!%'); }, null, null, ], - 'property.path' => [ + 'field.path' => [ [ 'query' => <<<'SQL' - select * from "test_objects" where "path"."to"."property" NOT LIKE ? ESCAPE '!' + select * from "test_objects" where "path"."to"."field" NOT LIKE ? ESCAPE '!' SQL , 'bindings' => ['%abc'], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('String!', 'abc'); }, null, null, ], - 'resolver' => [ + 'resolver' => [ [ 'query' => <<<'SQL' - select * from "test_objects" where "path__to__property" NOT LIKE ? ESCAPE '!' + select * from "test_objects" where "path__to__field" NOT LIKE ? ESCAPE '!' SQL , 'bindings' => ['%abc'], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('String!', 'abc'); }, null, - static function (object $builder, Property $property): string { - return implode('__', $property->getPath()); + static function (object $builder, Field $field): string { + return implode('__', $field->getPath()); }, ], ]), diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/NotEqual.php b/packages/graphql/src/SearchBy/Operators/Comparison/NotEqual.php index a5df90af0..15fcda3f5 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/NotEqual.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/NotEqual.php @@ -7,7 +7,7 @@ use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Context; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Handler; use LastDragon_ru\LaraASP\GraphQL\Builder\Exceptions\OperatorUnsupportedBuilder; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Operators\Operator; use Nuwave\Lighthouse\Execution\Arguments\Argument; use Override; @@ -19,7 +19,7 @@ public static function getName(): string { } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Not Equal (`!=`).'; } @@ -27,7 +27,7 @@ public function getFieldDescription(): string { public function call( Handler $handler, object $builder, - Property $property, + Field $field, Argument $argument, Context $context, ): object { @@ -35,10 +35,10 @@ public function call( throw new OperatorUnsupportedBuilder($this, $builder); } - $property = $this->resolver->getProperty($builder, $property->getParent()); - $value = $argument->toPlain(); + $field = $this->resolver->getField($builder, $field->getParent()); + $value = $argument->toPlain(); - $builder->where($property, '!=', $value); + $builder->where($field, '!=', $value); return $builder; } diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/NotEqualTest.php b/packages/graphql/src/SearchBy/Operators/Comparison/NotEqualTest.php index dd6f7b239..564759b67 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/NotEqualTest.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/NotEqualTest.php @@ -4,7 +4,7 @@ use Closure; use LastDragon_ru\LaraASP\GraphQL\Builder\Context; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Directives\Directive; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\DataProviders\BuilderDataProvider; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\OperatorTests; @@ -34,12 +34,12 @@ final class NotEqualTest extends TestCase { * @param BuilderFactory $builderFactory * @param Closure(static): Argument $argumentFactory * @param Closure(static): Context|null $contextFactory - * @param Closure(object, Property): string|null $resolver + * @param Closure(object, Field): string|null $resolver */ public function testCall( array $expected, Closure $builderFactory, - Property $property, + Field $field, Closure $argumentFactory, ?Closure $contextFactory, ?Closure $resolver, @@ -48,7 +48,7 @@ public function testCall( Directive::class, $expected, $builderFactory, - $property, + $field, $argumentFactory, $contextFactory, $resolver, @@ -65,42 +65,42 @@ public static function dataProviderCall(): array { return (new CompositeDataProvider( new BuilderDataProvider(), new ArrayDataProvider([ - 'property' => [ + 'field' => [ [ - 'query' => 'select * from "test_objects" where "property" != ?', + 'query' => 'select * from "test_objects" where "field" != ?', 'bindings' => ['abc'], ], - new Property('property', 'operator name should be ignored'), + new Field('field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('String!', 'abc'); }, null, null, ], - 'property.path' => [ + 'field.path' => [ [ - 'query' => 'select * from "test_objects" where "path"."to"."property" != ?', + 'query' => 'select * from "test_objects" where "path"."to"."field" != ?', 'bindings' => [123], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('Int!', 123); }, null, null, ], - 'resolver' => [ + 'resolver' => [ [ - 'query' => 'select * from "test_objects" where "path__to__property" != ?', + 'query' => 'select * from "test_objects" where "path__to__field" != ?', 'bindings' => [123], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('Int!', 123); }, null, - static function (object $builder, Property $property): string { - return implode('__', $property->getPath()); + static function (object $builder, Field $field): string { + return implode('__', $field->getPath()); }, ], ]), diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/NotIn.php b/packages/graphql/src/SearchBy/Operators/Comparison/NotIn.php index 926bb5f36..6db8a425f 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/NotIn.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/NotIn.php @@ -10,7 +10,7 @@ use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\TypeProvider; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\TypeSource; use LastDragon_ru\LaraASP\GraphQL\Builder\Exceptions\OperatorUnsupportedBuilder; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\Builder\Traits\WithScoutSupport; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Operators\Operator; use Nuwave\Lighthouse\Execution\Arguments\Argument; @@ -25,12 +25,12 @@ public static function getName(): string { } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Outside a set of values.'; } #[Override] - public function getFieldType(TypeProvider $provider, TypeSource $source, Context $context): string { + public function getFieldType(TypeProvider $provider, TypeSource $source, Context $context): ?string { return "[{$source->getTypeName()}!]"; } @@ -42,17 +42,17 @@ protected function getScoutVersion(): ?string { public function call( Handler $handler, object $builder, - Property $property, + Field $field, Argument $argument, Context $context, ): object { - $property = $this->resolver->getProperty($builder, $property->getParent()); - $value = (array) $argument->toPlain(); + $field = $this->resolver->getField($builder, $field->getParent()); + $value = (array) $argument->toPlain(); if ($builder instanceof EloquentBuilder || $builder instanceof QueryBuilder) { - $builder->whereNotIn($property, $value); + $builder->whereNotIn($field, $value); } elseif ($builder instanceof ScoutBuilder) { - $builder->whereNotIn($property, $value); + $builder->whereNotIn($field, $value); } else { throw new OperatorUnsupportedBuilder($this, $builder); } diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/NotInTest.php b/packages/graphql/src/SearchBy/Operators/Comparison/NotInTest.php index ec22c3635..f8cef4969 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/NotInTest.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/NotInTest.php @@ -9,6 +9,7 @@ use Laravel\Scout\Builder as ScoutBuilder; use LastDragon_ru\LaraASP\GraphQL\Builder\Context; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Scout\FieldResolver; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\Builder\Property; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Directives\Directive; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\DataProviders\BuilderDataProvider; @@ -43,12 +44,12 @@ final class NotInTest extends TestCase { * @param BuilderFactory $builderFactory * @param Closure(static): Argument $argumentFactory * @param Closure(static): Context|null $contextFactory - * @param Closure(object, Property): string|null $resolver + * @param Closure(object, Field): string|null $resolver */ public function testCall( array $expected, Closure $builderFactory, - Property $property, + Field $field, Closure $argumentFactory, ?Closure $contextFactory, ?Closure $resolver, @@ -57,7 +58,7 @@ public function testCall( Directive::class, $expected, $builderFactory, - $property, + $field, $argumentFactory, $contextFactory, $resolver, @@ -67,18 +68,18 @@ public function testCall( /** * @dataProvider dataProviderCallScout * - * @param array $expected - * @param Closure(static): ScoutBuilder $builderFactory - * @param Closure(static): Argument $argumentFactory - * @param Closure(static): Context|null $contextFactory - * @param Closure(object, Property): string|null $resolver - * @param Closure():FieldResolver|null $fieldResolver + * @param array $expected + * @param Closure(static): ScoutBuilder $builderFactory + * @param Closure(static): Argument $argumentFactory + * @param Closure(static): Context|null $contextFactory + * @param Closure(object, Field): string|null $resolver + * @param Closure():FieldResolver|null $fieldResolver */ #[RequiresLaravelScout] public function testCallScoutBuilder( array $expected, Closure $builderFactory, - Property $property, + Field $field, Closure $argumentFactory, ?Closure $contextFactory, ?Closure $resolver, @@ -107,7 +108,7 @@ public function testCallScoutBuilder( Directive::class, $expected, $builderFactory, - $property, + $field, $argumentFactory, $contextFactory, $resolver, @@ -124,42 +125,42 @@ public static function dataProviderCall(): array { return (new CompositeDataProvider( new BuilderDataProvider(), new ArrayDataProvider([ - 'property' => [ + 'field' => [ [ - 'query' => 'select * from "test_objects" where "property" not in (?, ?, ?)', + 'query' => 'select * from "test_objects" where "field" not in (?, ?, ?)', 'bindings' => [1, 2, 3], ], - new Property('property', 'operator name should be ignored'), + new Field('field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('[Int!]!', [1, 2, 3]); }, null, null, ], - 'property.path' => [ + 'field.path' => [ [ - 'query' => 'select * from "test_objects" where "path"."to"."property" not in (?, ?, ?)', + 'query' => 'select * from "test_objects" where "path"."to"."field" not in (?, ?, ?)', 'bindings' => ['a', 'b', 'c'], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('[String!]!', ['a', 'b', 'c']); }, null, null, ], - 'resolver' => [ + 'resolver' => [ [ - 'query' => 'select * from "test_objects" where "path__to__property" not in (?, ?, ?)', + 'query' => 'select * from "test_objects" where "path__to__field" not in (?, ?, ?)', 'bindings' => ['a', 'b', 'c'], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('[String!]!', ['a', 'b', 'c']); }, null, - static function (object $builder, Property $property): string { - return implode('__', $property->getPath()); + static function (object $builder, Field $field): string { + return implode('__', $field->getPath()); }, ], ]), @@ -173,13 +174,13 @@ public static function dataProviderCallScout(): array { return (new CompositeDataProvider( new ScoutBuilderDataProvider(), new ArrayDataProvider([ - 'property' => [ + 'field' => [ [ 'whereNotIns' => [ - 'path.to.property' => [1, 2, 3], + 'path.to.field' => [1, 2, 3], ], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('[Int!]!', [1, 2, 3]); }, @@ -214,16 +215,16 @@ public function getField(Model $model, Property $property): string { 'resolver' => [ [ 'whereNotIns' => [ - 'path__to__property' => [1, 2, 3], + 'path__to__field' => [1, 2, 3], ], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('[Int!]!', [1, 2, 3]); }, null, - static function (object $builder, Property $property): string { - return implode('__', $property->getPath()); + static function (object $builder, Field $field): string { + return implode('__', $field->getPath()); }, null, ], diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/NotLike.php b/packages/graphql/src/SearchBy/Operators/Comparison/NotLike.php index 5cd284a85..168ac3201 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/NotLike.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/NotLike.php @@ -8,7 +8,7 @@ use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Context; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Handler; use LastDragon_ru\LaraASP\GraphQL\Builder\Exceptions\OperatorUnsupportedBuilder; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Operators\Operator; use Nuwave\Lighthouse\Execution\Arguments\Argument; use Override; @@ -20,7 +20,7 @@ public static function getName(): string { } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Not like.'; } @@ -28,7 +28,7 @@ public function getFieldDescription(): string { public function call( Handler $handler, object $builder, - Property $property, + Field $field, Argument $argument, Context $context, ): object { @@ -36,10 +36,10 @@ public function call( throw new OperatorUnsupportedBuilder($this, $builder); } - $property = $this->resolver->getProperty($builder, $property->getParent()); - $value = (string) Cast::toStringable($argument->toPlain()); + $field = $this->resolver->getField($builder, $field->getParent()); + $value = (string) Cast::toStringable($argument->toPlain()); - $builder->where($property, 'not like', $value); + $builder->where($field, 'not like', $value); return $builder; } diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/NotLikeTest.php b/packages/graphql/src/SearchBy/Operators/Comparison/NotLikeTest.php index e436495f3..e070a0649 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/NotLikeTest.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/NotLikeTest.php @@ -4,7 +4,7 @@ use Closure; use LastDragon_ru\LaraASP\GraphQL\Builder\Context; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Directives\Directive; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\DataProviders\BuilderDataProvider; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\OperatorTests; @@ -34,12 +34,12 @@ final class NotLikeTest extends TestCase { * @param BuilderFactory $builderFactory * @param Closure(static): Argument $argumentFactory * @param Closure(static): Context|null $contextFactory - * @param Closure(object, Property): string|null $resolver + * @param Closure(object, Field): string|null $resolver */ public function testCall( array $expected, Closure $builderFactory, - Property $property, + Field $field, Closure $argumentFactory, ?Closure $contextFactory, ?Closure $resolver, @@ -48,7 +48,7 @@ public function testCall( Directive::class, $expected, $builderFactory, - $property, + $field, $argumentFactory, $contextFactory, $resolver, @@ -65,42 +65,42 @@ public static function dataProviderCall(): array { return (new CompositeDataProvider( new BuilderDataProvider(), new ArrayDataProvider([ - 'property' => [ + 'field' => [ [ - 'query' => 'select * from "test_objects" where "property" not like ?', + 'query' => 'select * from "test_objects" where "field" not like ?', 'bindings' => ['abc'], ], - new Property('property', 'operator name should be ignored'), + new Field('field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('String!', 'abc'); }, null, null, ], - 'property.path' => [ + 'field.path' => [ [ - 'query' => 'select * from "test_objects" where "path"."to"."property" not like ?', + 'query' => 'select * from "test_objects" where "path"."to"."field" not like ?', 'bindings' => ['abc'], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('String!', 'abc'); }, null, null, ], - 'resolver' => [ + 'resolver' => [ [ - 'query' => 'select * from "test_objects" where "path__to__property" not like ?', + 'query' => 'select * from "test_objects" where "path__to__field" not like ?', 'bindings' => ['abc'], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('String!', 'abc'); }, null, - static function (object $builder, Property $property): string { - return implode('__', $property->getPath()); + static function (object $builder, Field $field): string { + return implode('__', $field->getPath()); }, ], ]), diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/NotStartsWith.php b/packages/graphql/src/SearchBy/Operators/Comparison/NotStartsWith.php index 9fdc02528..350986833 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/NotStartsWith.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/NotStartsWith.php @@ -11,7 +11,7 @@ public static function getName(): string { } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Not starts with a string.'; } diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/NotStartsWithTest.php b/packages/graphql/src/SearchBy/Operators/Comparison/NotStartsWithTest.php index 1fc8ebbe4..ff3364ef1 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/NotStartsWithTest.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/NotStartsWithTest.php @@ -4,7 +4,7 @@ use Closure; use LastDragon_ru\LaraASP\GraphQL\Builder\Context; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Directives\Directive; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\DataProviders\BuilderDataProvider; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\OperatorTests; @@ -34,12 +34,12 @@ final class NotStartsWithTest extends TestCase { * @param BuilderFactory $builderFactory * @param Closure(static): Argument $argumentFactory * @param Closure(static): Context|null $contextFactory - * @param Closure(object, Property): string|null $resolver + * @param Closure(object, Field): string|null $resolver */ public function testCall( array $expected, Closure $builderFactory, - Property $property, + Field $field, Closure $argumentFactory, ?Closure $contextFactory, ?Closure $resolver, @@ -48,7 +48,7 @@ public function testCall( Directive::class, $expected, $builderFactory, - $property, + $field, $argumentFactory, $contextFactory, $resolver, @@ -65,48 +65,48 @@ public static function dataProviderCall(): array { return (new CompositeDataProvider( new BuilderDataProvider(), new ArrayDataProvider([ - 'property' => [ + 'field' => [ [ - 'query' => 'select * from "test_objects" where "property" NOT LIKE ? ESCAPE \'!\'', + 'query' => 'select * from "test_objects" where "field" NOT LIKE ? ESCAPE \'!\'', 'bindings' => ['!%a[!_]c!!!%%'], ], - new Property('property', 'operator name should be ignored'), + new Field('field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('String!', '%a[_]c!%'); }, null, null, ], - 'property.path' => [ + 'field.path' => [ [ 'query' => <<<'SQL' - select * from "test_objects" where "path"."to"."property" NOT LIKE ? ESCAPE '!' + select * from "test_objects" where "path"."to"."field" NOT LIKE ? ESCAPE '!' SQL , 'bindings' => ['abc%'], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('String!', 'abc'); }, null, null, ], - 'resolver' => [ + 'resolver' => [ [ 'query' => <<<'SQL' - select * from "test_objects" where "path__to__property" NOT LIKE ? ESCAPE '!' + select * from "test_objects" where "path__to__field" NOT LIKE ? ESCAPE '!' SQL , 'bindings' => ['abc%'], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('String!', 'abc'); }, null, - static function (object $builder, Property $property): string { - return implode('__', $property->getPath()); + static function (object $builder, Field $field): string { + return implode('__', $field->getPath()); }, ], ]), diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/StartsWith.php b/packages/graphql/src/SearchBy/Operators/Comparison/StartsWith.php index f15129af4..e6b3048a4 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/StartsWith.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/StartsWith.php @@ -11,7 +11,7 @@ public static function getName(): string { } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Starts with a string.'; } diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/StartsWithTest.php b/packages/graphql/src/SearchBy/Operators/Comparison/StartsWithTest.php index 8a90fd232..e616b1c4c 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/StartsWithTest.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/StartsWithTest.php @@ -4,7 +4,7 @@ use Closure; use LastDragon_ru\LaraASP\GraphQL\Builder\Context; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Directives\Directive; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\DataProviders\BuilderDataProvider; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\OperatorTests; @@ -34,12 +34,12 @@ final class StartsWithTest extends TestCase { * @param BuilderFactory $builderFactory * @param Closure(static): Argument $argumentFactory * @param Closure(static): Context|null $contextFactory - * @param Closure(object, Property): string|null $resolver + * @param Closure(object, Field): string|null $resolver */ public function testCall( array $expected, Closure $builderFactory, - Property $property, + Field $field, Closure $argumentFactory, ?Closure $contextFactory, ?Closure $resolver, @@ -48,7 +48,7 @@ public function testCall( Directive::class, $expected, $builderFactory, - $property, + $field, $argumentFactory, $contextFactory, $resolver, @@ -65,42 +65,42 @@ public static function dataProviderCall(): array { return (new CompositeDataProvider( new BuilderDataProvider(), new ArrayDataProvider([ - 'property' => [ + 'field' => [ [ - 'query' => 'select * from "test_objects" where "property" LIKE ? ESCAPE \'!\'', + 'query' => 'select * from "test_objects" where "field" LIKE ? ESCAPE \'!\'', 'bindings' => ['!%a[!_]c!!!%%'], ], - new Property('property', 'operator name should be ignored'), + new Field('field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('String!', '%a[_]c!%'); }, null, null, ], - 'property.path' => [ + 'field.path' => [ [ - 'query' => 'select * from "test_objects" where "path"."to"."property" LIKE ? ESCAPE \'!\'', + 'query' => 'select * from "test_objects" where "path"."to"."field" LIKE ? ESCAPE \'!\'', 'bindings' => ['abc%'], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('String!', 'abc'); }, null, null, ], - 'resolver' => [ + 'resolver' => [ [ - 'query' => 'select * from "test_objects" where "path__to__property" LIKE ? ESCAPE \'!\'', + 'query' => 'select * from "test_objects" where "path__to__field" LIKE ? ESCAPE \'!\'', 'bindings' => ['abc%'], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('String!', 'abc'); }, null, - static function (object $builder, Property $property): string { - return implode('__', $property->getPath()); + static function (object $builder, Field $field): string { + return implode('__', $field->getPath()); }, ], ]), diff --git a/packages/graphql/src/SearchBy/Operators/Complex/Relationship.php b/packages/graphql/src/SearchBy/Operators/Complex/Relationship.php index 1d5352142..c743346a9 100644 --- a/packages/graphql/src/SearchBy/Operators/Complex/Relationship.php +++ b/packages/graphql/src/SearchBy/Operators/Complex/Relationship.php @@ -7,13 +7,13 @@ use Illuminate\Database\Eloquent\Builder as EloquentBuilder; use Illuminate\Database\Eloquent\Model as EloquentModel; use LastDragon_ru\LaraASP\Eloquent\ModelHelper; -use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\BuilderPropertyResolver; +use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\BuilderFieldResolver; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Context; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Handler; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\TypeProvider; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\TypeSource; use LastDragon_ru\LaraASP\GraphQL\Builder\Exceptions\OperatorUnsupportedBuilder; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Definitions\SearchByOperatorConditionDirective; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Exceptions\OperatorInvalidArgumentValue; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Operators\Operator; @@ -28,7 +28,7 @@ class Relationship extends Operator { public function __construct( protected readonly SearchByOperatorConditionDirective $field, - BuilderPropertyResolver $resolver, + BuilderFieldResolver $resolver, ) { parent::__construct($resolver); } @@ -54,17 +54,23 @@ public static function getName(): string { } #[Override] - public function getFieldType(TypeProvider $provider, TypeSource $source, Context $context): string { + public function isAvailable(TypeProvider $provider, TypeSource $source, Context $context): bool { + return parent::isAvailable($provider, $source, $context) + && $source->isObject(); + } + + #[Override] + public function getFieldType(TypeProvider $provider, TypeSource $source, Context $context): ?string { return $provider->getType(RelationshipType::class, $source, $context); } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Relationship condition.'; } #[Override] - public function isAvailable(string $builder, Context $context): bool { + protected function isBuilderSupported(string $builder): bool { return is_a($builder, EloquentBuilder::class, true); } @@ -72,7 +78,7 @@ public function isAvailable(string $builder, Context $context): bool { public function call( Handler $handler, object $builder, - Property $property, + Field $field, Argument $argument, Context $context, ): object { @@ -93,7 +99,7 @@ public function call( // * where + notExists = doesntHave // Conditions - $relation = (new ModelHelper($builder))->getRelation($property->getName()); + $relation = (new ModelHelper($builder))->getRelation($field->getName()); $has = $argument->value->arguments['where'] ?? null; $hasCount = $argument->value->arguments['count'] ?? null; $notExists = (bool) ($argument->value->arguments['notExists']->value ?? false); @@ -105,7 +111,7 @@ public function call( if ($hasCount instanceof Argument) { $query = $builder->getQuery()->newQuery(); - $query = $this->field->call($handler, $query, new Property(), $hasCount, $context); + $query = $this->field->call($handler, $query, new Field(), $hasCount, $context); $where = reset($query->wheres); $count = $where['value'] ?? $count; $operator = $where['operator'] ?? $operator; @@ -119,7 +125,7 @@ public function call( // Build $this->build( $builder, - $property, + $field, $operator, $count, static function (EloquentBuilder $builder) use ($context, $relation, $handler, $alias, $has): void { @@ -128,7 +134,7 @@ static function (EloquentBuilder $builder) use ($context, $relation, $handler, $ } if ($has instanceof Argument && $has->value instanceof ArgumentSet) { - $handler->handle($builder, new Property($alias), $has->value, $context); + $handler->handle($builder, new Field($alias), $has->value, $context); } }, ); @@ -145,11 +151,11 @@ static function (EloquentBuilder $builder) use ($context, $relation, $handler, $ */ protected function build( EloquentBuilder $builder, - Property $property, + Field $field, string $operator, int $count, Closure $closure, ): void { - $builder->whereHas($property->getName(), $closure, $operator, $count); + $builder->whereHas($field->getName(), $closure, $operator, $count); } } diff --git a/packages/graphql/src/SearchBy/Operators/Complex/RelationshipTest.php b/packages/graphql/src/SearchBy/Operators/Complex/RelationshipTest.php index 708519cd1..653617ce8 100644 --- a/packages/graphql/src/SearchBy/Operators/Complex/RelationshipTest.php +++ b/packages/graphql/src/SearchBy/Operators/Complex/RelationshipTest.php @@ -7,8 +7,8 @@ use Illuminate\Database\Eloquent\Builder as EloquentBuilder; use LastDragon_ru\LaraASP\Eloquent\Exceptions\PropertyIsNotRelation; use LastDragon_ru\LaraASP\GraphQL\Builder\Context; -use LastDragon_ru\LaraASP\GraphQL\Builder\Exceptions\Client\ConditionTooManyOperators; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Exceptions\Client\ConditionTooManyFields; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Directives\Directive; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\DataProviders\BuilderDataProvider; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\Models\User; @@ -37,12 +37,12 @@ final class RelationshipTest extends TestCase { * @param BuilderFactory $builderFactory * @param Closure(static): Argument $argumentFactory * @param Closure(static): Context|null $contextFactory - * @param Closure(object, Property): string|null $resolver + * @param Closure(object, Field): string|null $resolver */ public function testCall( array|Exception $expected, Closure $builderFactory, - Property $property, + Field $field, Closure $argumentFactory, ?Closure $contextFactory, ?Closure $resolver, @@ -51,7 +51,7 @@ public function testCall( Directive::class, $expected, $builderFactory, - $property, + $field, $argumentFactory, $contextFactory, $resolver, @@ -67,7 +67,7 @@ public function testCall( public static function dataProviderCall(): array { $graphql = <<<'GRAPHQL' input TestInput { - property: TestOperators + field: TestOperators @searchByOperatorCondition user: TestRelation @@ -101,12 +101,12 @@ public static function dataProviderCall(): array { GRAPHQL; return [ - 'not a relation' => [ + 'not a relation' => [ new PropertyIsNotRelation(new User(), 'delete'), static function (): EloquentBuilder { return User::query(); }, - new Property('delete'), + new Field('delete'), static function (self $test) use ($graphql): Argument { return $test->getGraphQLArgument( 'TestRelation!', @@ -119,7 +119,7 @@ static function (self $test) use ($graphql): Argument { null, null, ], - '{exists: true}' => [ + '{exists: true}' => [ [ 'query' => 'select * from "users" where exists ('. 'select * from "cars" '. @@ -130,7 +130,7 @@ static function (self $test) use ($graphql): Argument { static function (): EloquentBuilder { return User::query(); }, - new Property('car'), + new Field('car'), static function (self $test) use ($graphql): Argument { return $test->getGraphQLArgument( 'TestRelation!', @@ -143,7 +143,7 @@ static function (self $test) use ($graphql): Argument { null, null, ], - '{notExists: true}' => [ + '{notExists: true}' => [ [ 'query' => 'select * from "users" where not exists ('. 'select * from "cars" '. @@ -154,7 +154,7 @@ static function (self $test) use ($graphql): Argument { static function (): EloquentBuilder { return User::query(); }, - new Property('car'), + new Field('car'), static function (self $test) use ($graphql): Argument { return $test->getGraphQLArgument( 'TestRelation', @@ -167,13 +167,13 @@ static function (self $test) use ($graphql): Argument { null, null, ], - '{relation: {property: {equal: 1}}}' => [ + '{relation: {field: {equal: 1}}}' => [ [ 'query' => <<<'SQL' select * from "users" where exists ( select * from "cars" where "users"."localKey" = "cars"."foreignKey" - and "cars"."property" = ? + and "cars"."field" = ? and "favorite" = ? ) SQL @@ -183,13 +183,13 @@ static function (self $test) use ($graphql): Argument { static function (): EloquentBuilder { return User::query(); }, - new Property('car'), + new Field('car'), static function (self $test) use ($graphql): Argument { return $test->getGraphQLArgument( 'TestRelation', [ 'where' => [ - 'property' => [ + 'field' => [ 'equal' => 123, ], ], @@ -200,7 +200,7 @@ static function (self $test) use ($graphql): Argument { null, null, ], - '{count: {equal: 1}}' => [ + '{count: {equal: 1}}' => [ [ 'query' => <<<'SQL' select * from "users" where ( @@ -216,7 +216,7 @@ static function (self $test) use ($graphql): Argument { static function (): EloquentBuilder { return User::query(); }, - new Property('car'), + new Field('car'), static function (self $test) use ($graphql): Argument { return $test->getGraphQLArgument( 'TestRelation', @@ -231,12 +231,12 @@ static function (self $test) use ($graphql): Argument { null, null, ], - '{count: { multiple operators }}' => [ - new ConditionTooManyOperators(['lessThan', 'equal']), + '{count: { multiple operators }}' => [ + new ConditionTooManyFields(['lessThan', 'equal']), static function (): EloquentBuilder { return User::query(); }, - new Property('car'), + new Field('car'), static function (self $test) use ($graphql): Argument { return $test->getGraphQLArgument( 'TestRelation', @@ -252,14 +252,14 @@ static function (self $test) use ($graphql): Argument { null, null, ], - '{where: {{property: {equal: 1}}}} (own)' => [ + '{where: {{field: {equal: 1}}}} (own)' => [ [ 'query' => <<<'SQL' select * from "users" where exists ( select * from "users" as "laravel_reserved_0" where "users"."localKey" = "laravel_reserved_0"."foreignKey" - and "laravel_reserved_0"."property" = ? + and "laravel_reserved_0"."field" = ? ) SQL , @@ -268,13 +268,13 @@ static function (self $test) use ($graphql): Argument { static function (): EloquentBuilder { return User::query(); }, - new Property('parent'), + new Field('parent'), static function (self $test) use ($graphql): Argument { return $test->getGraphQLArgument( 'TestRelation', [ 'where' => [ - 'property' => [ + 'field' => [ 'equal' => 123, ], ], @@ -285,7 +285,7 @@ static function (self $test) use ($graphql): Argument { null, null, ], - '{relation: {relation: {property: {equal: 1}}}}' => [ + '{relation: {relation: {field: {equal: 1}}}}' => [ [ 'query' => <<<'SQL' select @@ -307,7 +307,7 @@ static function (self $test) use ($graphql): Argument { "users" where "cars"."foreignKey" = "users"."ownerKey" - and "users"."property" = ? + and "users"."field" = ? and "deleted_at" is null ) and "favorite" = ? @@ -319,7 +319,7 @@ static function (self $test) use ($graphql): Argument { static function (): EloquentBuilder { return User::query(); }, - new Property('car'), + new Field('car'), static function (self $test) use ($graphql): Argument { return $test->getGraphQLArgument( 'TestRelation', @@ -327,7 +327,7 @@ static function (self $test) use ($graphql): Argument { 'where' => [ 'user' => [ 'where' => [ - 'property' => [ + 'field' => [ 'equal' => 123, ], ], @@ -340,14 +340,14 @@ static function (self $test) use ($graphql): Argument { null, null, ], - 'resolver' => [ + 'resolver' => [ [ 'query' => <<<'SQL' select * from "users" where exists ( select * from "users" as "laravel_reserved_0" where "users"."localKey" = "laravel_reserved_0"."foreignKey" - and "laravel_reserved_0"."resolved__property" = ? + and "laravel_reserved_0"."resolved__field" = ? ) SQL , @@ -356,13 +356,13 @@ static function (self $test) use ($graphql): Argument { static function (): EloquentBuilder { return User::query(); }, - new Property('parent'), + new Field('parent'), static function (self $test) use ($graphql): Argument { return $test->getGraphQLArgument( 'TestRelation', [ 'where' => [ - 'property' => [ + 'field' => [ 'equal' => 123, ], ], @@ -371,8 +371,8 @@ static function (self $test) use ($graphql): Argument { ); }, null, - static function (object $builder, Property $property): string { - return implode('.', $property->getParent()->getPath()).'.resolved__'.$property->getName(); + static function (object $builder, Field $field): string { + return implode('.', $field->getParent()->getPath()).'.resolved__'.$field->getName(); }, ], ]; diff --git a/packages/graphql/src/SearchBy/Operators/Complex/RelationshipType.php b/packages/graphql/src/SearchBy/Operators/Complex/RelationshipType.php index 99dbff373..79680d5a9 100644 --- a/packages/graphql/src/SearchBy/Operators/Complex/RelationshipType.php +++ b/packages/graphql/src/SearchBy/Operators/Complex/RelationshipType.php @@ -5,7 +5,6 @@ use GraphQL\Language\AST\TypeDefinitionNode; use GraphQL\Language\Parser; use GraphQL\Type\Definition\Type; -use Illuminate\Support\Str; use LastDragon_ru\LaraASP\GraphQL\Builder\Context\HandlerContextBuilderInfo; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Context; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\TypeDefinition; @@ -25,10 +24,9 @@ public function __construct() { public function getTypeName(TypeSource $source, Context $context): string { $typeName = $source->getTypeName(); $builderName = $context->get(HandlerContextBuilderInfo::class)?->value->getName() ?? 'Unknown'; - $operatorName = Str::studly(Relationship::getName()); $directiveName = Directive::Name; - return "{$directiveName}{$builderName}Relationship{$operatorName}{$typeName}"; + return "{$directiveName}{$builderName}Relationship{$typeName}"; } #[Override] @@ -38,14 +36,21 @@ public function getTypeDefinition( Context $context, string $name, ): TypeDefinitionNode|Type|null { - $int = $manipulator->getTypeSource(Type::nonNull(Type::int())); - $count = $manipulator->getType(Scalar::class, $int, $context); - $where = $manipulator->getType(Root::class, $source, $context); + // Object? + if (!$source->isObject()) { + return null; + } + + // Definition + $int = $manipulator->getTypeSource(Type::nonNull(Type::int())); + $count = $manipulator->getType(Scalar::class, $int, $context); + $where = $manipulator->getType(Root::class, $source, $context); + $origin = $manipulator->getTypeFullName($source->getType()); return Parser::inputObjectTypeDefinition( <<isScalar() || $source->isEnum()); + } + + #[Override] + public function getFieldType(TypeProvider $provider, TypeSource $source, Context $context): ?string { + return match (true) { + $source->isScalar() => $provider->getType(Scalar::class, $source, $context), + $source->isEnum() => $provider->getType(Enumeration::class, $source, $context), + default => null, + }; + } + + #[Override] + public function getFieldDescription(): ?string { return 'Field condition.'; } } diff --git a/packages/graphql/src/SearchBy/Operators/Field.php b/packages/graphql/src/SearchBy/Operators/Field.php index 7de399ab5..b5457d60d 100644 --- a/packages/graphql/src/SearchBy/Operators/Field.php +++ b/packages/graphql/src/SearchBy/Operators/Field.php @@ -6,7 +6,7 @@ use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Handler; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\TypeProvider; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\TypeSource; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field as BuilderField; use LastDragon_ru\LaraASP\GraphQL\Builder\Traits\HandlerOperator; use LastDragon_ru\LaraASP\GraphQL\Builder\Traits\WithScoutSupport; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Types\Condition\Condition; @@ -23,12 +23,18 @@ public static function getName(): string { } #[Override] - public function getFieldType(TypeProvider $provider, TypeSource $source, Context $context): string { + public function isAvailable(TypeProvider $provider, TypeSource $source, Context $context): bool { + return parent::isAvailable($provider, $source, $context) + && $source->isObject(); + } + + #[Override] + public function getFieldType(TypeProvider $provider, TypeSource $source, Context $context): ?string { return $provider->getType(Condition::class, $source, $context); } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Field.'; } @@ -36,10 +42,10 @@ public function getFieldDescription(): string { public function call( Handler $handler, object $builder, - Property $property, + BuilderField $field, Argument $argument, Context $context, ): object { - return $this->handle($handler, $builder, $property->getParent(), $argument, $context); + return $this->handle($handler, $builder, $field->getParent(), $argument, $context); } } diff --git a/packages/graphql/src/SearchBy/Operators/Logical/AllOf.php b/packages/graphql/src/SearchBy/Operators/Logical/AllOf.php index ea48b2afd..5dccf66b6 100644 --- a/packages/graphql/src/SearchBy/Operators/Logical/AllOf.php +++ b/packages/graphql/src/SearchBy/Operators/Logical/AllOf.php @@ -7,7 +7,7 @@ use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Handler; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\TypeProvider; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\TypeSource; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\Builder\Traits\WithScoutSupport; use Nuwave\Lighthouse\Execution\Arguments\Argument; use Override; @@ -24,14 +24,14 @@ public static function getName(): string { } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'All of the conditions must be true.'; } #[Override] - public function getFieldType(TypeProvider $provider, TypeSource $source, Context $context): string { + public function getFieldType(TypeProvider $provider, TypeSource $source, Context $context): ?string { $parent = parent::getFieldType($provider, $source, $context); - $type = "[{$parent}!]"; + $type = $parent ? "[{$parent}!]" : null; return $type; } @@ -45,21 +45,21 @@ protected function getBoolean(): string { public function call( Handler $handler, object $builder, - Property $property, + Field $field, Argument $argument, Context $context, ): object { // Scout? if (!($builder instanceof ScoutBuilder)) { - return parent::call($handler, $builder, $property, $argument, $context); + return parent::call($handler, $builder, $field, $argument, $context); } // Build - $property = $property->getParent(); + $field = $field->getParent(); $conditions = $this->getConditions($argument); foreach ($conditions as $arguments) { - $handler->handle($builder, $property, $arguments, $context); + $handler->handle($builder, $field, $arguments, $context); } // Return diff --git a/packages/graphql/src/SearchBy/Operators/Logical/AllOfTest.php b/packages/graphql/src/SearchBy/Operators/Logical/AllOfTest.php index 90cbb00f7..8253c9cb3 100644 --- a/packages/graphql/src/SearchBy/Operators/Logical/AllOfTest.php +++ b/packages/graphql/src/SearchBy/Operators/Logical/AllOfTest.php @@ -7,7 +7,7 @@ use Laravel\Scout\Builder as ScoutBuilder; use LastDragon_ru\LaraASP\GraphQL\Builder\Context; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Scout\FieldResolver; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Directives\Directive; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\DataProviders\BuilderDataProvider; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\DataProviders\EloquentBuilderDataProvider; @@ -43,12 +43,12 @@ final class AllOfTest extends TestCase { * @param BuilderFactory $builderFactory * @param Closure(static): Argument $argumentFactory * @param Closure(static): Context|null $contextFactory - * @param Closure(object, Property): string|null $resolver + * @param Closure(object, Field): string|null $resolver */ public function testCall( array $expected, Closure $builderFactory, - Property $property, + Field $field, Closure $argumentFactory, ?Closure $contextFactory, ?Closure $resolver, @@ -57,7 +57,7 @@ public function testCall( Directive::class, $expected, $builderFactory, - $property, + $field, $argumentFactory, $contextFactory, $resolver, @@ -67,18 +67,18 @@ public function testCall( /** * @dataProvider dataProviderCallScout * - * @param array $expected - * @param Closure(static): ScoutBuilder $builderFactory - * @param Closure(static): Argument $argumentFactory - * @param Closure(static): Context|null $contextFactory - * @param Closure(object, Property): string|null $resolver - * @param Closure():FieldResolver|null $fieldResolver + * @param array $expected + * @param Closure(static): ScoutBuilder $builderFactory + * @param Closure(static): Argument $argumentFactory + * @param Closure(static): Context|null $contextFactory + * @param Closure(object, Field): string|null $resolver + * @param Closure():FieldResolver|null $fieldResolver */ #[RequiresLaravelScout] public function testCallScoutBuilder( array $expected, Closure $builderFactory, - Property $property, + Field $field, Closure $argumentFactory, ?Closure $contextFactory, ?Closure $resolver, @@ -92,7 +92,7 @@ public function testCallScoutBuilder( Directive::class, $expected, $builderFactory, - $property, + $field, $argumentFactory, $contextFactory, $resolver, @@ -141,7 +141,7 @@ public static function dataProviderCall(): array { 'Query' => new CompositeDataProvider( new QueryBuilderDataProvider(), new ArrayDataProvider([ - 'property' => [ + 'field' => [ [ 'query' => 'select * from "test_objects" where (("a" = ?) and ("b" != ?))', 'bindings' => [ @@ -149,7 +149,7 @@ public static function dataProviderCall(): array { 22, ], ], - new Property('operator name should be ignored'), + new Field('operator name should be ignored'), $factory, null, null, @@ -165,7 +165,7 @@ public static function dataProviderCall(): array { 22, ], ], - new Property('alias', 'operator name should be ignored'), + new Field('alias', 'operator name should be ignored'), $factory, null, null, @@ -181,11 +181,11 @@ public static function dataProviderCall(): array { 22, ], ], - new Property('alias', 'operator name should be ignored'), + new Field('alias', 'operator name should be ignored'), $factory, null, - static function (object $builder, Property $property): string { - return implode('__', $property->getPath()); + static function (object $builder, Field $field): string { + return implode('__', $field->getPath()); }, ], ]), @@ -193,7 +193,7 @@ static function (object $builder, Property $property): string { 'Eloquent' => new CompositeDataProvider( new EloquentBuilderDataProvider(), new ArrayDataProvider([ - 'property' => [ + 'field' => [ [ 'query' => <<<'SQL' select * @@ -206,7 +206,7 @@ static function (object $builder, Property $property): string { 22, ], ], - new Property('operator name should be ignored'), + new Field('operator name should be ignored'), $factory, null, null, @@ -222,7 +222,7 @@ static function (object $builder, Property $property): string { 22, ], ], - new Property('alias', 'operator name should be ignored'), + new Field('alias', 'operator name should be ignored'), $factory, null, null, @@ -238,11 +238,11 @@ static function (object $builder, Property $property): string { 22, ], ], - new Property('alias', 'operator name should be ignored'), + new Field('alias', 'operator name should be ignored'), $factory, null, - static function (object $builder, Property $property): string { - return implode('__', $property->getPath()); + static function (object $builder, Field $field): string { + return implode('__', $field->getPath()); }, ], ]), @@ -289,17 +289,17 @@ public static function dataProviderCallScout(): array { return (new CompositeDataProvider( new ScoutBuilderDataProvider(), new ArrayDataProvider([ - 'property' => [ + 'field' => [ [ 'wheres' => [ - 'path.to.property.a' => 'aaa', - 'path.to.property.b' => 'bbb', + 'path.to.field.a' => 'aaa', + 'path.to.field.b' => 'bbb', ], 'whereIns' => [ - 'path.to.property.b' => [1, 2, 3], + 'path.to.field.b' => [1, 2, 3], ], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), $factory, null, null, @@ -308,14 +308,14 @@ public static function dataProviderCallScout(): array { 'resolver (deprecated)' => [ [ 'wheres' => [ - 'properties/path/to/property/a' => 'aaa', - 'properties/path/to/property/b' => 'bbb', + 'properties/path/to/field/a' => 'aaa', + 'properties/path/to/field/b' => 'bbb', ], 'whereIns' => [ - 'properties/path/to/property/b' => [1, 2, 3], + 'properties/path/to/field/b' => [1, 2, 3], ], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), $factory, null, null, @@ -325,8 +325,8 @@ static function (): FieldResolver { * @inheritDoc */ #[Override] - public function getField(Model $model, Property $property): string { - return 'properties/'.implode('/', $property->getPath()); + public function getField(Model $model, Field $field): string { + return 'properties/'.implode('/', $field->getPath()); } }; }, @@ -334,18 +334,18 @@ public function getField(Model $model, Property $property): string { 'resolver' => [ [ 'wheres' => [ - 'path__to__property__a' => 'aaa', - 'path__to__property__b' => 'bbb', + 'path__to__field__a' => 'aaa', + 'path__to__field__b' => 'bbb', ], 'whereIns' => [ - 'path__to__property__b' => [1, 2, 3], + 'path__to__field__b' => [1, 2, 3], ], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), $factory, null, - static function (object $builder, Property $property): string { - return implode('__', $property->getPath()); + static function (object $builder, Field $field): string { + return implode('__', $field->getPath()); }, null, ], diff --git a/packages/graphql/src/SearchBy/Operators/Logical/AnyOf.php b/packages/graphql/src/SearchBy/Operators/Logical/AnyOf.php index 184fcf061..2242b1ad9 100644 --- a/packages/graphql/src/SearchBy/Operators/Logical/AnyOf.php +++ b/packages/graphql/src/SearchBy/Operators/Logical/AnyOf.php @@ -17,14 +17,14 @@ public static function getName(): string { } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Any of the conditions must be true.'; } #[Override] - public function getFieldType(TypeProvider $provider, TypeSource $source, Context $context): string { + public function getFieldType(TypeProvider $provider, TypeSource $source, Context $context): ?string { $parent = parent::getFieldType($provider, $source, $context); - $type = "[{$parent}!]"; + $type = $parent ? "[{$parent}!]" : null; return $type; } diff --git a/packages/graphql/src/SearchBy/Operators/Logical/AnyOfTest.php b/packages/graphql/src/SearchBy/Operators/Logical/AnyOfTest.php index a9b553fce..29a629bf4 100644 --- a/packages/graphql/src/SearchBy/Operators/Logical/AnyOfTest.php +++ b/packages/graphql/src/SearchBy/Operators/Logical/AnyOfTest.php @@ -4,7 +4,7 @@ use Closure; use LastDragon_ru\LaraASP\GraphQL\Builder\Context; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Directives\Directive; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\DataProviders\BuilderDataProvider; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\DataProviders\EloquentBuilderDataProvider; @@ -37,12 +37,12 @@ final class AnyOfTest extends TestCase { * @param BuilderFactory $builderFactory * @param Closure(static): Argument $argumentFactory * @param Closure(static): Context|null $contextFactory - * @param Closure(object, Property): string|null $resolver + * @param Closure(object, Field): string|null $resolver */ public function testCall( array $expected, Closure $builderFactory, - Property $property, + Field $field, Closure $argumentFactory, ?Closure $contextFactory, ?Closure $resolver, @@ -51,7 +51,7 @@ public function testCall( Directive::class, $expected, $builderFactory, - $property, + $field, $argumentFactory, $contextFactory, $resolver, @@ -100,7 +100,7 @@ public static function dataProviderCall(): array { 'Query' => new CompositeDataProvider( new QueryBuilderDataProvider(), new ArrayDataProvider([ - 'property' => [ + 'field' => [ [ 'query' => 'select * from "test_objects" where (("a" = ?) or ("b" != ?))', 'bindings' => [ @@ -108,7 +108,7 @@ public static function dataProviderCall(): array { 22, ], ], - new Property('operator name should be ignored'), + new Field('operator name should be ignored'), $factory, null, null, @@ -124,7 +124,7 @@ public static function dataProviderCall(): array { 22, ], ], - new Property('alias', 'operator name should be ignored'), + new Field('alias', 'operator name should be ignored'), $factory, null, null, @@ -140,11 +140,11 @@ public static function dataProviderCall(): array { 22, ], ], - new Property('alias', 'operator name should be ignored'), + new Field('alias', 'operator name should be ignored'), $factory, null, - static function (object $builder, Property $property): string { - return implode('__', $property->getPath()); + static function (object $builder, Field $field): string { + return implode('__', $field->getPath()); }, ], ]), @@ -152,7 +152,7 @@ static function (object $builder, Property $property): string { 'Eloquent' => new CompositeDataProvider( new EloquentBuilderDataProvider(), new ArrayDataProvider([ - 'property' => [ + 'field' => [ [ 'query' => <<<'SQL' select * @@ -165,7 +165,7 @@ static function (object $builder, Property $property): string { 22, ], ], - new Property('operator name should be ignored'), + new Field('operator name should be ignored'), $factory, null, null, @@ -181,7 +181,7 @@ static function (object $builder, Property $property): string { 22, ], ], - new Property('alias', 'operator name should be ignored'), + new Field('alias', 'operator name should be ignored'), $factory, null, null, @@ -197,11 +197,11 @@ static function (object $builder, Property $property): string { 22, ], ], - new Property('alias', 'operator name should be ignored'), + new Field('alias', 'operator name should be ignored'), $factory, null, - static function (object $builder, Property $property): string { - return implode('__', $property->getPath()); + static function (object $builder, Field $field): string { + return implode('__', $field->getPath()); }, ], ]), diff --git a/packages/graphql/src/SearchBy/Operators/Logical/Logical.php b/packages/graphql/src/SearchBy/Operators/Logical/Logical.php index fb824b548..a8f6c53e4 100644 --- a/packages/graphql/src/SearchBy/Operators/Logical/Logical.php +++ b/packages/graphql/src/SearchBy/Operators/Logical/Logical.php @@ -9,7 +9,7 @@ use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\TypeProvider; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\TypeSource; use LastDragon_ru\LaraASP\GraphQL\Builder\Exceptions\OperatorUnsupportedBuilder; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Exceptions\OperatorInvalidArgumentValue; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Operators\Operator; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Types\Condition\Root; @@ -23,7 +23,7 @@ abstract class Logical extends Operator { #[Override] - public function getFieldType(TypeProvider $provider, TypeSource $source, Context $context): string { + public function getFieldType(TypeProvider $provider, TypeSource $source, Context $context): ?string { return $provider->getType(Root::class, $source, $context); } @@ -31,7 +31,7 @@ public function getFieldType(TypeProvider $provider, TypeSource $source, Context public function call( Handler $handler, object $builder, - Property $property, + Field $field, Argument $argument, Context $context, ): object { @@ -40,9 +40,9 @@ public function call( } $builder->where( - function (EloquentBuilder|QueryBuilder $builder) use ($handler, $context, $property, $argument): void { - // The last item is the name of the operator not a property - $property = $property->getParent(); + function (EloquentBuilder|QueryBuilder $builder) use ($handler, $context, $field, $argument): void { + // The last item is the name of the operator not a field + $field = $field->getParent(); $conditions = $this->getConditions($argument); foreach ($conditions as $arguments) { @@ -51,9 +51,9 @@ static function (EloquentBuilder|QueryBuilder $builder) use ( $handler, $context, $arguments, - $property, + $field, ): void { - $handler->handle($builder, $property, $arguments, $context); + $handler->handle($builder, $field, $arguments, $context); }, null, null, diff --git a/packages/graphql/src/SearchBy/Operators/Logical/Not.php b/packages/graphql/src/SearchBy/Operators/Logical/Not.php index ec46c3424..efe98b074 100644 --- a/packages/graphql/src/SearchBy/Operators/Logical/Not.php +++ b/packages/graphql/src/SearchBy/Operators/Logical/Not.php @@ -11,7 +11,7 @@ public static function getName(): string { } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Not.'; } diff --git a/packages/graphql/src/SearchBy/Operators/Logical/NotTest.php b/packages/graphql/src/SearchBy/Operators/Logical/NotTest.php index 98fa196bc..48bc69eba 100644 --- a/packages/graphql/src/SearchBy/Operators/Logical/NotTest.php +++ b/packages/graphql/src/SearchBy/Operators/Logical/NotTest.php @@ -4,7 +4,7 @@ use Closure; use LastDragon_ru\LaraASP\GraphQL\Builder\Context; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Directives\Directive; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\DataProviders\BuilderDataProvider; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\DataProviders\EloquentBuilderDataProvider; @@ -37,12 +37,12 @@ final class NotTest extends TestCase { * @param BuilderFactory $builderFactory * @param Closure(static): Argument $argumentFactory * @param Closure(static): Context|null $contextFactory - * @param Closure(object, Property): string|null $resolver + * @param Closure(object, Field): string|null $resolver */ public function testCall( array $expected, Closure $builderFactory, - Property $property, + Field $field, Closure $argumentFactory, ?Closure $contextFactory, ?Closure $resolver, @@ -51,7 +51,7 @@ public function testCall( Directive::class, $expected, $builderFactory, - $property, + $field, $argumentFactory, $contextFactory, $resolver, @@ -101,14 +101,14 @@ public static function dataProviderCall(): array { 'Query' => new CompositeDataProvider( new QueryBuilderDataProvider(), new ArrayDataProvider([ - 'property' => [ + 'field' => [ [ 'query' => 'select * from "test_objects" where (not ("a" = ?))', 'bindings' => [ 2, ], ], - new Property('operator name should be ignored'), + new Field('operator name should be ignored'), $factory, null, null, @@ -120,7 +120,7 @@ public static function dataProviderCall(): array { 2, ], ], - new Property('alias', 'operator name should be ignored'), + new Field('alias', 'operator name should be ignored'), $factory, null, null, @@ -132,11 +132,11 @@ public static function dataProviderCall(): array { 2, ], ], - new Property('alias', 'operator name should be ignored'), + new Field('alias', 'operator name should be ignored'), $factory, null, - static function (object $builder, Property $property): string { - return implode('__', $property->getPath()); + static function (object $builder, Field $field): string { + return implode('__', $field->getPath()); }, ], ]), @@ -144,14 +144,14 @@ static function (object $builder, Property $property): string { 'Eloquent' => new CompositeDataProvider( new EloquentBuilderDataProvider(), new ArrayDataProvider([ - 'property' => [ + 'field' => [ [ 'query' => 'select * from "test_objects" where (not ("test_objects"."a" = ?))', 'bindings' => [ 2, ], ], - new Property('operator name should be ignored'), + new Field('operator name should be ignored'), $factory, null, null, @@ -163,7 +163,7 @@ static function (object $builder, Property $property): string { 2, ], ], - new Property('alias', 'operator name should be ignored'), + new Field('alias', 'operator name should be ignored'), $factory, null, null, @@ -175,11 +175,11 @@ static function (object $builder, Property $property): string { 2, ], ], - new Property('alias', 'operator name should be ignored'), + new Field('alias', 'operator name should be ignored'), $factory, null, - static function (object $builder, Property $property): string { - return implode('__', $property->getPath()); + static function (object $builder, Field $field): string { + return implode('__', $field->getPath()); }, ], ]), diff --git a/packages/graphql/src/SearchBy/Operators/Operator.php b/packages/graphql/src/SearchBy/Operators/Operator.php index 2efe9451d..85a91422c 100644 --- a/packages/graphql/src/SearchBy/Operators/Operator.php +++ b/packages/graphql/src/SearchBy/Operators/Operator.php @@ -15,12 +15,12 @@ abstract class Operator extends OperatorDirective implements Marker { #[Override] - public function getFieldType(TypeProvider $provider, TypeSource $source, Context $context): string { + public function getFieldType(TypeProvider $provider, TypeSource $source, Context $context): ?string { return $source->getTypeName(); } #[Override] - public function isAvailable(string $builder, Context $context): bool { + protected function isBuilderSupported(string $builder): bool { return is_a($builder, EloquentBuilder::class, true) || is_a($builder, QueryBuilder::class, true); } diff --git a/packages/graphql/src/SearchBy/Operators/Root.php b/packages/graphql/src/SearchBy/Operators/Root.php index 8f7a45704..8afc656f4 100644 --- a/packages/graphql/src/SearchBy/Operators/Root.php +++ b/packages/graphql/src/SearchBy/Operators/Root.php @@ -20,12 +20,12 @@ public static function getName(): string { } #[Override] - public function getFieldType(TypeProvider $provider, TypeSource $source, Context $context): string { + public function getFieldType(TypeProvider $provider, TypeSource $source, Context $context): ?string { return $provider->getType(RootType::class, $source, $context); } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Directive root.'; } } diff --git a/packages/graphql/src/SearchBy/Types/Condition/Root.php b/packages/graphql/src/SearchBy/Types/Condition/Root.php index 6add0add8..ac1809921 100644 --- a/packages/graphql/src/SearchBy/Types/Condition/Root.php +++ b/packages/graphql/src/SearchBy/Types/Condition/Root.php @@ -7,29 +7,9 @@ use LastDragon_ru\LaraASP\GraphQL\Builder\Sources\InputSource; use LastDragon_ru\LaraASP\GraphQL\Builder\Sources\InterfaceSource; use LastDragon_ru\LaraASP\GraphQL\Builder\Sources\ObjectSource; -use LastDragon_ru\LaraASP\GraphQL\SearchBy\Definitions\SearchByOperatorFieldDirective; use Override; -use function array_merge; - class Root extends Type { - /** - * @inheritDoc - */ - #[Override] - protected function getOperators( - Manipulator $manipulator, - InterfaceSource|InputSource|ObjectSource $source, - Context $context, - ): array { - return array_merge( - parent::getOperators($manipulator, $source, $context), - [ - $manipulator->getOperator($this->getScope(), SearchByOperatorFieldDirective::class), - ], - ); - } - /** * @inheritDoc */ diff --git a/packages/graphql/src/SearchBy/Types/Condition/Type.php b/packages/graphql/src/SearchBy/Types/Condition/Type.php index 8c743b722..ba8d7372f 100644 --- a/packages/graphql/src/SearchBy/Types/Condition/Type.php +++ b/packages/graphql/src/SearchBy/Types/Condition/Type.php @@ -2,9 +2,9 @@ namespace LastDragon_ru\LaraASP\GraphQL\SearchBy\Types\Condition; -use GraphQL\Language\Parser; use LastDragon_ru\LaraASP\GraphQL\Builder\Context\HandlerContextBuilderInfo; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Context; +use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Operator as OperatorContract; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\TypeSource; use LastDragon_ru\LaraASP\GraphQL\Builder\Manipulator; use LastDragon_ru\LaraASP\GraphQL\Builder\Sources\InputFieldSource; @@ -20,13 +20,9 @@ use LastDragon_ru\LaraASP\GraphQL\SearchBy\Definitions\SearchByOperatorConditionDirective; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Directives\Directive; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Operators; -use LastDragon_ru\LaraASP\GraphQL\SearchBy\Types\Enumeration; -use LastDragon_ru\LaraASP\GraphQL\SearchBy\Types\Scalar; use Override; use ReflectionClass; -use function is_string; - abstract class Type extends InputObject { #[Override] public function getTypeName(TypeSource $source, Context $context): string { @@ -49,7 +45,7 @@ protected function getDescription( InputSource|ObjectSource|InterfaceSource $source, Context $context, ): string { - return "Available conditions for `{$source}` (only one property allowed at a time)."; + return "Available conditions for `{$source}` (only one field allowed at a time)."; } #[Override] @@ -72,29 +68,21 @@ protected function getTypeForFieldOperator(): ?string { return Operators::Object; } - /** - * @inheritDoc - */ #[Override] protected function getFieldOperator( Manipulator $manipulator, InputFieldSource|ObjectFieldSource|InterfaceFieldSource $field, Context $context, - ): ?array { - $operator = match (true) { - $field->isScalar() => Scalar::class, - $field->isEnum() => Enumeration::class, - $field->isObject() => parent::getFieldOperator($manipulator, $field, $context), - default => throw new NotImplemented($field), + ): ?OperatorContract { + return match (true) { + $field->isScalar(), $field->isEnum() => $manipulator->getOperator( + SearchByOperatorConditionDirective::class, + $this->getScope(), + $field, + $context, + ), + $field->isObject() => parent::getFieldOperator($manipulator, $field, $context), + default => throw new NotImplemented($field), }; - - if (is_string($operator)) { - $type = $manipulator->getType($operator, $field, $context); - $source = $manipulator->getTypeSource(Parser::typeReference($type)); - $operator = $manipulator->getOperator($this->getScope(), SearchByOperatorConditionDirective::class); - $operator = [$operator, $source]; - } - - return $operator; } } diff --git a/packages/graphql/src/SearchBy/Types/Condition/V5.php b/packages/graphql/src/SearchBy/Types/Condition/V5.php index b8800698a..3d54fe5f1 100644 --- a/packages/graphql/src/SearchBy/Types/Condition/V5.php +++ b/packages/graphql/src/SearchBy/Types/Condition/V5.php @@ -5,9 +5,17 @@ use LastDragon_ru\LaraASP\GraphQL\Builder\Context\HandlerContextBuilderInfo; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Context; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\TypeSource; +use LastDragon_ru\LaraASP\GraphQL\Builder\Manipulator; +use LastDragon_ru\LaraASP\GraphQL\Builder\Sources\InputSource; +use LastDragon_ru\LaraASP\GraphQL\Builder\Sources\InterfaceSource; +use LastDragon_ru\LaraASP\GraphQL\Builder\Sources\ObjectSource; +use LastDragon_ru\LaraASP\GraphQL\SearchBy\Definitions\SearchByOperatorFieldDirective; use LastDragon_ru\LaraASP\GraphQL\SearchBy\Directives\Directive; use Override; +use function array_filter; +use function array_values; + /** * @deprecated 5.5.0 Please migrate to the new query structure. */ @@ -21,4 +29,20 @@ public function getTypeName(TypeSource $source, Context $context): string { return "{$directiveName}{$builderName}{$name}{$typeName}"; } + + /** + * @inheritDoc + */ + #[Override] + protected function getOperators( + Manipulator $manipulator, + InterfaceSource|InputSource|ObjectSource $source, + Context $context, + ): array { + $operators = parent::getOperators($manipulator, $source, $context); + $operators = array_filter($operators, static fn ($o) => !($o instanceof SearchByOperatorFieldDirective)); + $operators = array_values($operators); + + return $operators; + } } diff --git a/packages/graphql/src/SearchBy/Types/Enumeration.php b/packages/graphql/src/SearchBy/Types/Enumeration.php index 9073abc03..177417ca4 100644 --- a/packages/graphql/src/SearchBy/Types/Enumeration.php +++ b/packages/graphql/src/SearchBy/Types/Enumeration.php @@ -39,23 +39,28 @@ public function getTypeDefinition( Context $context, string $name, ): TypeDefinitionNode|Type|null { + // Enum? + if (!$source->isEnum()) { + return null; + } + // Operators + $type = $manipulator->getTypeSource($source->getType()); $scope = Directive::getScope(); - $extras = $source->isNullable() ? [Operators::Null] : []; - $operators = $manipulator->getTypeOperators($scope, $source->getTypeName(), $context, ...$extras) - ?: $manipulator->getTypeOperators($scope, Operators::Enum, $context, ...$extras); + $extras = $type->isNullable() ? [Operators::Null] : []; + $operators = $manipulator->getTypeOperators($type->getTypeName(), $scope, $type, $context, ...$extras) + ?: $manipulator->getTypeOperators(Operators::Enum, $scope, $type, $context, ...$extras); if (!$operators) { return null; } // Definition - $content = $manipulator->getOperatorsFields($operators, $source, $context); - $typeName = $manipulator->getTypeFullName($source->getType()); + $content = $manipulator->getOperatorsFields($operators, $type, $context); $definition = Parser::inputObjectTypeDefinition( <<isScalar()) { + return null; + } + // Operators + $type = $manipulator->getTypeSource($source->getType()); $scope = Directive::getScope(); - $extras = $source->isNullable() ? [Operators::Null] : []; - $operators = $manipulator->getTypeOperators($scope, $source->getTypeName(), $context, ...$extras); + $extras = $type->isNullable() ? [Operators::Null] : []; + $operators = $manipulator->getTypeOperators($type->getTypeName(), $scope, $type, $context, ...$extras); if (!$operators) { return null; } // Definition - $content = $manipulator->getOperatorsFields($operators, $source, $context); - $typeName = $manipulator->getTypeFullName($source->getType()); + $content = $manipulator->getOperatorsFields($operators, $type, $context); $definition = Parser::inputObjectTypeDefinition( << [ Operators::Extra => [ - // empty + SortByOperatorFieldDirective::class, ], ], ]); @@ -423,7 +424,7 @@ public function testHandleBuilderV5Compat( * * @param array|Exception $expected * @param Closure(static): ScoutBuilder $builderFactory - * @param Closure(object, Property): string|null $resolver + * @param Closure(object, Field): string|null $resolver * @param Closure():FieldResolver|null $fieldResolver */ #[RequiresLaravelScout] @@ -442,10 +443,10 @@ public function testHandleScoutBuilder( if ($resolver) { $this->override( - BuilderPropertyResolver::class, + BuilderFieldResolver::class, static function (MockInterface $mock) use ($resolver): void { $mock - ->shouldReceive('getProperty') + ->shouldReceive('getField') ->atLeast() ->once() ->andReturnUsing($resolver); @@ -499,7 +500,7 @@ static function (MockInterface $mock) use ($resolver): void { * * @param array|Exception $expected * @param Closure(static): ScoutBuilder $builderFactory - * @param Closure(object, Property): string|null $resolver + * @param Closure(object, Field): string|null $resolver * @param Closure():FieldResolver|null $fieldResolver */ #[RequiresLaravelScout] @@ -521,10 +522,10 @@ public function testHandleScoutBuilderV5Compat( if ($resolver) { $this->override( - BuilderPropertyResolver::class, + BuilderFieldResolver::class, static function (MockInterface $mock) use ($resolver): void { $mock - ->shouldReceive('getProperty') + ->shouldReceive('getField') ->atLeast() ->once() ->andReturnUsing($resolver); @@ -600,7 +601,7 @@ public static function dataProviderManipulateArgDefinition(): array { static function (): void { config([ Package::Name.'.sort_by.operators.'.Operators::Extra => [ - // empty + SortByOperatorFieldDirective::class, ], ]); }, @@ -611,7 +612,7 @@ static function (): void { static function (): void { config([ Package::Name.'.sort_by.operators.'.Operators::Extra => [ - // empty + SortByOperatorFieldDirective::class, ], ]); @@ -636,7 +637,7 @@ static function (): void { static function (): void { config([ Package::Name.'.sort_by.operators.'.Operators::Extra => [ - // empty + SortByOperatorFieldDirective::class, ], ]); }, @@ -779,7 +780,7 @@ public static function dataProviderHandleBuilder(): array { null, ], 'too many fields (operators)' => [ - new ConditionTooManyProperties(['nullsFirst', 'field']), + new ConditionTooManyFields(['nullsFirst', 'field']), [ [ 'field' => [ @@ -793,7 +794,7 @@ public static function dataProviderHandleBuilder(): array { null, ], 'too many fields (fields)' => [ - new ConditionTooManyOperators(['id', 'value']), + new ConditionTooManyFields(['id', 'value']), [ [ 'field' => [ @@ -854,6 +855,7 @@ static function (): void { config([ "{$package}.sort_by.operators" => [ Operators::Extra => [ + SortByOperatorFieldDirective::class, SortByOperatorRandomDirective::class, ], ], @@ -1001,7 +1003,7 @@ public static function dataProviderHandleBuilderV5Compat(): array { null, ], 'too many properties' => [ - new ConditionTooManyProperties(['id', 'value']), + new ConditionTooManyFields(['id', 'value']), [ [ 'id' => 'asc', @@ -1056,6 +1058,7 @@ static function (): void { config([ "{$package}.sort_by.operators" => [ Operators::Extra => [ + SortByOperatorFieldDirective::class, SortByOperatorRandomDirective::class, ], ], @@ -1181,7 +1184,7 @@ public static function dataProviderHandleScoutBuilder(): array { null, ], 'too many fields (fields)' => [ - new ConditionTooManyOperators(['a', 'b']), + new ConditionTooManyFields(['a', 'b']), [ [ 'field' => [ @@ -1328,8 +1331,8 @@ public function getField( ], ], ], - static function (object $builder, Property $property): string { - return implode('__', $property->getPath()); + static function (object $builder, Field $field): string { + return implode('__', $field->getPath()); }, null, ], @@ -1369,7 +1372,7 @@ public static function dataProviderHandleScoutBuilderV5Compat(): array { null, ], 'too many properties' => [ - new ConditionTooManyProperties(['a', 'b']), + new ConditionTooManyFields(['a', 'b']), [ [ 'a' => 'asc', @@ -1496,8 +1499,8 @@ public function getField( 'b' => 'desc', ], ], - static function (object $builder, Property $property): string { - return implode('__', $property->getPath()); + static function (object $builder, Field $field): string { + return implode('__', $field->getPath()); }, null, ], diff --git a/packages/graphql/src/SortBy/Directives/DirectiveTest/AllowedDirectives.expected.graphql b/packages/graphql/src/SortBy/Directives/DirectiveTest/AllowedDirectives.expected.graphql index cf9df25b2..0d2b0cff4 100644 --- a/packages/graphql/src/SortBy/Directives/DirectiveTest/AllowedDirectives.expected.graphql +++ b/packages/graphql/src/SortBy/Directives/DirectiveTest/AllowedDirectives.expected.graphql @@ -36,7 +36,7 @@ enum SortByTypeDirection { } """ -Sort clause for `type A` (only one property allowed at a time). +Sort clause for `type A` (only one field allowed at a time). """ input SortByClauseA { """ @@ -50,7 +50,7 @@ input SortByClauseA { } """ -Sort clause for `interface B` (only one property allowed at a time). +Sort clause for `interface B` (only one field allowed at a time). """ input SortByClauseB { """ @@ -64,7 +64,7 @@ input SortByClauseB { } """ -Sort clause for `type A` (only one property allowed at a time). +Sort clause for `type A` (only one field allowed at a time). """ input SortByRootA { """ @@ -75,7 +75,7 @@ input SortByRootA { } """ -Sort clause for `interface B` (only one property allowed at a time). +Sort clause for `interface B` (only one field allowed at a time). """ input SortByRootB { """ diff --git a/packages/graphql/src/SortBy/Directives/DirectiveTest/Example.expected.graphql b/packages/graphql/src/SortBy/Directives/DirectiveTest/Example.expected.graphql index f2e7e518e..2540b0f2d 100644 --- a/packages/graphql/src/SortBy/Directives/DirectiveTest/Example.expected.graphql +++ b/packages/graphql/src/SortBy/Directives/DirectiveTest/Example.expected.graphql @@ -54,7 +54,7 @@ enum SortByTypeDirection { } """ -Sort clause for `type Comment` (only one property allowed at a time). +Sort clause for `type Comment` (only one field allowed at a time). """ input SortByClauseComment { """ @@ -71,7 +71,7 @@ input SortByClauseComment { } """ -Sort clause for `type User` (only one property allowed at a time). +Sort clause for `type User` (only one field allowed at a time). """ input SortByClauseUser { """ @@ -88,7 +88,7 @@ input SortByClauseUser { } """ -Sort clause for `input UsersSort` (only one property allowed at a time). +Sort clause for `input UsersSort` (only one field allowed at a time). """ input SortByClauseUsersSort { """ @@ -105,7 +105,7 @@ input SortByClauseUsersSort { } """ -Sort clause for `type Comment` (only one property allowed at a time). +Sort clause for `type Comment` (only one field allowed at a time). """ input SortByRootComment { """ @@ -128,7 +128,7 @@ input SortByRootComment { } """ -Sort clause for `input UsersSort` (only one property allowed at a time). +Sort clause for `input UsersSort` (only one field allowed at a time). """ input SortByRootUsersSort { """ diff --git a/packages/graphql/src/SortBy/Directives/DirectiveTest/Explicit.expected.graphql b/packages/graphql/src/SortBy/Directives/DirectiveTest/Explicit.expected.graphql index 4975cfd77..11ae6206b 100644 --- a/packages/graphql/src/SortBy/Directives/DirectiveTest/Explicit.expected.graphql +++ b/packages/graphql/src/SortBy/Directives/DirectiveTest/Explicit.expected.graphql @@ -76,7 +76,7 @@ input B { } """ -Sort clause for `input A` (only one property allowed at a time). +Sort clause for `input A` (only one field allowed at a time). """ input SortByClauseA { """ @@ -105,7 +105,7 @@ input SortByClauseA { } """ -Sort clause for `input B` (only one property allowed at a time). +Sort clause for `input B` (only one field allowed at a time). """ input SortByClauseB { """ @@ -128,7 +128,7 @@ input SortByClauseB { } """ -Sort clause for `input A` (only one property allowed at a time). +Sort clause for `input A` (only one field allowed at a time). """ input SortByRootA { """ diff --git a/packages/graphql/src/SortBy/Directives/DirectiveTest/Ignored.expected.graphql b/packages/graphql/src/SortBy/Directives/DirectiveTest/Ignored.expected.graphql index fb46e972a..712479f19 100644 --- a/packages/graphql/src/SortBy/Directives/DirectiveTest/Ignored.expected.graphql +++ b/packages/graphql/src/SortBy/Directives/DirectiveTest/Ignored.expected.graphql @@ -88,7 +88,7 @@ input IgnoredType { } """ -Sort clause for `input A` (only one property allowed at a time). +Sort clause for `input A` (only one field allowed at a time). """ input SortByClauseA { """ @@ -105,7 +105,7 @@ input SortByClauseA { } """ -Sort clause for `interface B` (only one property allowed at a time). +Sort clause for `interface B` (only one field allowed at a time). """ input SortByClauseB { """ @@ -116,7 +116,7 @@ input SortByClauseB { } """ -Sort clause for `input A` (only one property allowed at a time). +Sort clause for `input A` (only one field allowed at a time). """ input SortByRootA { """ @@ -127,7 +127,7 @@ input SortByRootA { } """ -Sort clause for `interface B` (only one property allowed at a time). +Sort clause for `interface B` (only one field allowed at a time). """ input SortByRootB { """ diff --git a/packages/graphql/src/SortBy/Directives/DirectiveTest/Implicit.expected.graphql b/packages/graphql/src/SortBy/Directives/DirectiveTest/Implicit.expected.graphql index ecc88a241..de1733e71 100644 --- a/packages/graphql/src/SortBy/Directives/DirectiveTest/Implicit.expected.graphql +++ b/packages/graphql/src/SortBy/Directives/DirectiveTest/Implicit.expected.graphql @@ -122,7 +122,7 @@ enum SortByTypeDirection { } """ -Sort clause for `type A` (only one property allowed at a time). +Sort clause for `type A` (only one field allowed at a time). """ input SortByClauseA { """ @@ -196,7 +196,7 @@ input SortByClauseA { } """ -Sort clause for `type B` (only one property allowed at a time). +Sort clause for `type B` (only one field allowed at a time). """ input SortByClauseB { """ @@ -219,7 +219,7 @@ input SortByClauseB { } """ -Sort clause for `interface C` (only one property allowed at a time). +Sort clause for `interface C` (only one field allowed at a time). """ input SortByClauseC { """ @@ -293,7 +293,7 @@ input SortByClauseC { } """ -Sort clause for `type A` (only one property allowed at a time). +Sort clause for `type A` (only one field allowed at a time). """ input SortByRootA { """ @@ -316,7 +316,7 @@ input SortByRootA { } """ -Sort clause for `interface C` (only one property allowed at a time). +Sort clause for `interface C` (only one field allowed at a time). """ input SortByRootC { """ @@ -360,6 +360,11 @@ input StreamBuilder { interface C { field: B! + + fieldWithArgs( + arg: String + ): Int! + fields: [B!]! """ @@ -376,10 +381,6 @@ interface C { operators: [B!] @sortByOperatorChild - property( - arg: String - ): Int! - relation: B! @hasOne @@ -503,6 +504,11 @@ scalar StreamOffset type A { field: B! + + fieldWithArgs( + arg: String + ): Int! + fields: [B!]! """ @@ -519,10 +525,6 @@ type A { operators: [B!] @sortByOperatorChild - property( - arg: String - ): Int! - relation: B! @hasOne diff --git a/packages/graphql/src/SortBy/Directives/DirectiveTest/Implicit.schema.graphql b/packages/graphql/src/SortBy/Directives/DirectiveTest/Implicit.schema.graphql index c74a11423..ca3b08580 100644 --- a/packages/graphql/src/SortBy/Directives/DirectiveTest/Implicit.schema.graphql +++ b/packages/graphql/src/SortBy/Directives/DirectiveTest/Implicit.schema.graphql @@ -25,7 +25,7 @@ type A { list: [String!] field: B! fields: [B!]! - property(arg: String): Int! + fieldWithArgs(arg: String): Int! resolver: Int! @field(resolver: "\\LastDragon_ru\\LaraASP\\GraphQL\\SortBy\\Directives\\DirectiveTest__Resolver") stream: [A!]! @stream( searchable: false @@ -65,7 +65,7 @@ interface C { list: [String!] field: B! fields: [B!]! - property(arg: String): Int! + fieldWithArgs(arg: String): Int! resolver: Int! @field(resolver: "\\LastDragon_ru\\LaraASP\\GraphQL\\SortBy\\Directives\\DirectiveTest__Resolver") stream: [A!]! @stream( searchable: false diff --git a/packages/graphql/src/SortBy/Directives/DirectiveTest/InterfaceUpdate.expected.graphql b/packages/graphql/src/SortBy/Directives/DirectiveTest/InterfaceUpdate.expected.graphql index c76b2e247..a787fd610 100644 --- a/packages/graphql/src/SortBy/Directives/DirectiveTest/InterfaceUpdate.expected.graphql +++ b/packages/graphql/src/SortBy/Directives/DirectiveTest/InterfaceUpdate.expected.graphql @@ -40,7 +40,7 @@ input A { } """ -Sort clause for `input A` (only one property allowed at a time). +Sort clause for `input A` (only one field allowed at a time). """ input SortByClauseA { """ @@ -51,7 +51,7 @@ input SortByClauseA { } """ -Sort clause for `type B` (only one property allowed at a time). +Sort clause for `type B` (only one field allowed at a time). """ input SortByClauseB { """ @@ -62,7 +62,7 @@ input SortByClauseB { } """ -Sort clause for `input A` (only one property allowed at a time). +Sort clause for `input A` (only one field allowed at a time). """ input SortByRootA { """ @@ -73,7 +73,7 @@ input SortByRootA { } """ -Sort clause for `type B` (only one property allowed at a time). +Sort clause for `type B` (only one field allowed at a time). """ input SortByRootB { """ diff --git a/packages/graphql/src/SortBy/Directives/DirectiveTest/Query.expected.graphql b/packages/graphql/src/SortBy/Directives/DirectiveTest/Query.expected.graphql index 46fe84f06..6f54e5b6e 100644 --- a/packages/graphql/src/SortBy/Directives/DirectiveTest/Query.expected.graphql +++ b/packages/graphql/src/SortBy/Directives/DirectiveTest/Query.expected.graphql @@ -48,7 +48,7 @@ enum SortByTypeDirection { } """ -Sort clause for `input InputA` (only one property allowed at a time). +Sort clause for `input InputA` (only one field allowed at a time). """ input SortByQueryClauseInputA { """ @@ -65,7 +65,7 @@ input SortByQueryClauseInputA { } """ -Sort clause for `input TypeB` (only one property allowed at a time). +Sort clause for `input TypeB` (only one field allowed at a time). """ input SortByQueryClauseTypeB { """ @@ -82,7 +82,7 @@ input SortByQueryClauseTypeB { } """ -Sort clause for `input InputA` (only one property allowed at a time). +Sort clause for `input InputA` (only one field allowed at a time). """ input SortByQueryRootInputA { """ @@ -105,7 +105,7 @@ input SortByQueryRootInputA { } """ -Sort clause for `input TypeB` (only one property allowed at a time). +Sort clause for `input TypeB` (only one field allowed at a time). """ input SortByQueryRootTypeB { """ diff --git a/packages/graphql/src/SortBy/Directives/DirectiveTest/Scout.expected.graphql b/packages/graphql/src/SortBy/Directives/DirectiveTest/Scout.expected.graphql index c7d6fa2f3..91386d089 100644 --- a/packages/graphql/src/SortBy/Directives/DirectiveTest/Scout.expected.graphql +++ b/packages/graphql/src/SortBy/Directives/DirectiveTest/Scout.expected.graphql @@ -44,7 +44,6 @@ on directive @sortByOperatorRandom on | ENUM - | FIELD_DEFINITION | INPUT_FIELD_DEFINITION | SCALAR @@ -93,7 +92,7 @@ enum Value { } """ -Sort clause for `input Nested` (only one property allowed at a time). +Sort clause for `input Nested` (only one field allowed at a time). """ input SortByClauseNested { """ @@ -110,7 +109,7 @@ input SortByClauseNested { } """ -Sort clause for `type Object` (only one property allowed at a time). +Sort clause for `type Object` (only one field allowed at a time). """ input SortByClauseObject { """ @@ -178,7 +177,7 @@ input SortByClauseObject { } """ -Sort clause for `interface ObjectInterface` (only one property allowed at a time). +Sort clause for `interface ObjectInterface` (only one field allowed at a time). """ input SortByClauseObjectInterface { """ @@ -246,7 +245,7 @@ input SortByClauseObjectInterface { } """ -Sort clause for `type ObjectNested` (only one property allowed at a time). +Sort clause for `type ObjectNested` (only one field allowed at a time). """ input SortByClauseObjectNested { """ @@ -257,7 +256,7 @@ input SortByClauseObjectNested { } """ -Sort clause for `input Properties` (only one property allowed at a time). +Sort clause for `input Properties` (only one field allowed at a time). """ input SortByClauseProperties { """ @@ -337,7 +336,7 @@ input SortByClauseProperties { } """ -Sort clause for `input Properties` (only one property allowed at a time). +Sort clause for `input Properties` (only one field allowed at a time). """ input SortByQueryClauseProperties { """ @@ -405,7 +404,7 @@ input SortByQueryClauseProperties { } """ -Sort clause for `input Properties` (only one property allowed at a time). +Sort clause for `input Properties` (only one field allowed at a time). """ input SortByQueryRootProperties { """ @@ -434,7 +433,7 @@ input SortByQueryRootProperties { } """ -Sort clause for `type Object` (only one property allowed at a time). +Sort clause for `type Object` (only one field allowed at a time). """ input SortByRootObject { """ @@ -463,7 +462,7 @@ input SortByRootObject { } """ -Sort clause for `interface ObjectInterface` (only one property allowed at a time). +Sort clause for `interface ObjectInterface` (only one field allowed at a time). """ input SortByRootObjectInterface { """ @@ -492,7 +491,7 @@ input SortByRootObjectInterface { } """ -Sort clause for `input Properties` (only one property allowed at a time). +Sort clause for `input Properties` (only one field allowed at a time). """ input SortByRootProperties { """ @@ -521,7 +520,7 @@ input SortByRootProperties { } """ -Sort clause for `input Nested` (only one property allowed at a time). +Sort clause for `input Nested` (only one field allowed at a time). """ input SortByScoutClauseNested { """ @@ -538,7 +537,7 @@ input SortByScoutClauseNested { } """ -Sort clause for `input Properties` (only one property allowed at a time). +Sort clause for `input Properties` (only one field allowed at a time). """ input SortByScoutClauseProperties { """ @@ -618,7 +617,7 @@ input SortByScoutClauseProperties { } """ -Sort clause for `input Properties` (only one property allowed at a time). +Sort clause for `input Properties` (only one field allowed at a time). """ input SortByScoutRootProperties { """ diff --git a/packages/graphql/src/SortBy/Directives/DirectiveTest/TypeRegistry.expected.graphql b/packages/graphql/src/SortBy/Directives/DirectiveTest/TypeRegistry.expected.graphql index f2e7e518e..2540b0f2d 100644 --- a/packages/graphql/src/SortBy/Directives/DirectiveTest/TypeRegistry.expected.graphql +++ b/packages/graphql/src/SortBy/Directives/DirectiveTest/TypeRegistry.expected.graphql @@ -54,7 +54,7 @@ enum SortByTypeDirection { } """ -Sort clause for `type Comment` (only one property allowed at a time). +Sort clause for `type Comment` (only one field allowed at a time). """ input SortByClauseComment { """ @@ -71,7 +71,7 @@ input SortByClauseComment { } """ -Sort clause for `type User` (only one property allowed at a time). +Sort clause for `type User` (only one field allowed at a time). """ input SortByClauseUser { """ @@ -88,7 +88,7 @@ input SortByClauseUser { } """ -Sort clause for `input UsersSort` (only one property allowed at a time). +Sort clause for `input UsersSort` (only one field allowed at a time). """ input SortByClauseUsersSort { """ @@ -105,7 +105,7 @@ input SortByClauseUsersSort { } """ -Sort clause for `type Comment` (only one property allowed at a time). +Sort clause for `type Comment` (only one field allowed at a time). """ input SortByRootComment { """ @@ -128,7 +128,7 @@ input SortByRootComment { } """ -Sort clause for `input UsersSort` (only one property allowed at a time). +Sort clause for `input UsersSort` (only one field allowed at a time). """ input SortByRootUsersSort { """ diff --git a/packages/graphql/src/SortBy/Directives/DirectiveTest/V5Compat.expected.graphql b/packages/graphql/src/SortBy/Directives/DirectiveTest/V5Compat.expected.graphql index 01adfac9e..3fdb692dd 100644 --- a/packages/graphql/src/SortBy/Directives/DirectiveTest/V5Compat.expected.graphql +++ b/packages/graphql/src/SortBy/Directives/DirectiveTest/V5Compat.expected.graphql @@ -48,7 +48,7 @@ enum SortByTypeDirection { } """ -Sort clause for `type Comment` (only one property allowed at a time). +Sort clause for `type Comment` (only one field allowed at a time). """ input SortByClauseComment { """ @@ -77,7 +77,7 @@ input SortByClauseComment { } """ -Sort clause for `type User` (only one property allowed at a time). +Sort clause for `type User` (only one field allowed at a time). """ input SortByClauseUser { """ @@ -106,7 +106,7 @@ input SortByClauseUser { } """ -Sort clause for `input UsersSort` (only one property allowed at a time). +Sort clause for `input UsersSort` (only one field allowed at a time). """ input SortByClauseUsersSort { """ diff --git a/packages/graphql/src/SortBy/Directives/DirectiveTest/V5CompatScout.expected.graphql b/packages/graphql/src/SortBy/Directives/DirectiveTest/V5CompatScout.expected.graphql index da1b02899..d146ba794 100644 --- a/packages/graphql/src/SortBy/Directives/DirectiveTest/V5CompatScout.expected.graphql +++ b/packages/graphql/src/SortBy/Directives/DirectiveTest/V5CompatScout.expected.graphql @@ -36,7 +36,7 @@ enum SortByTypeDirection { } """ -Sort clause for `type Comment` (only one property allowed at a time). +Sort clause for `type Comment` (only one field allowed at a time). """ input SortByScoutClauseComment { """ @@ -53,7 +53,7 @@ input SortByScoutClauseComment { } """ -Sort clause for `type User` (only one property allowed at a time). +Sort clause for `type User` (only one field allowed at a time). """ input SortByScoutClauseUser { """ @@ -70,7 +70,7 @@ input SortByScoutClauseUser { } """ -Sort clause for `input UsersSort` (only one property allowed at a time). +Sort clause for `input UsersSort` (only one field allowed at a time). """ input SortByScoutClauseUsersSort { """ diff --git a/packages/graphql/src/SortBy/Operators.php b/packages/graphql/src/SortBy/Operators.php index 75508cc4e..285fbc416 100644 --- a/packages/graphql/src/SortBy/Operators.php +++ b/packages/graphql/src/SortBy/Operators.php @@ -6,6 +6,7 @@ use LastDragon_ru\LaraASP\GraphQL\Builder\Operators as BuilderOperators; use LastDragon_ru\LaraASP\GraphQL\Package; use LastDragon_ru\LaraASP\GraphQL\SortBy\Definitions\SortByOperatorChildDirective; +use LastDragon_ru\LaraASP\GraphQL\SortBy\Definitions\SortByOperatorFieldDirective; use LastDragon_ru\LaraASP\GraphQL\SortBy\Definitions\SortByOperatorNullsFirstDirective; use LastDragon_ru\LaraASP\GraphQL\SortBy\Definitions\SortByOperatorNullsLastDirective; use LastDragon_ru\LaraASP\GraphQL\SortBy\Directives\Directive; @@ -22,6 +23,7 @@ class Operators extends BuilderOperators { */ protected array $default = [ self::Extra => [ + SortByOperatorFieldDirective::class, SortByOperatorNullsFirstDirective::class, SortByOperatorNullsLastDirective::class, ], diff --git a/packages/graphql/src/SortBy/Operators/Child.php b/packages/graphql/src/SortBy/Operators/Child.php index ef13277c3..e172981c5 100644 --- a/packages/graphql/src/SortBy/Operators/Child.php +++ b/packages/graphql/src/SortBy/Operators/Child.php @@ -8,7 +8,7 @@ use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\TypeProvider; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\TypeSource; use LastDragon_ru\LaraASP\GraphQL\Builder\Traits\HandlerOperator; -use LastDragon_ru\LaraASP\GraphQL\SortBy\Types\Clause\Clause as ClauseType; +use LastDragon_ru\LaraASP\GraphQL\SortBy\Types\Clause\Clause; use Override; use function is_a; @@ -22,17 +22,23 @@ public static function getName(): string { } #[Override] - public function getFieldType(TypeProvider $provider, TypeSource $source, Context $context): string { - return $provider->getType(ClauseType::class, $source, $context); + public function isAvailable(TypeProvider $provider, TypeSource $source, Context $context): bool { + return parent::isAvailable($provider, $source, $context) + && $source->isObject(); } #[Override] - public function getFieldDescription(): string { + public function getFieldType(TypeProvider $provider, TypeSource $source, Context $context): ?string { + return $provider->getType(Clause::class, $source, $context); + } + + #[Override] + public function getFieldDescription(): ?string { return 'Field clause.'; } #[Override] - public function isAvailable(string $builder, Context $context): bool { + protected function isBuilderSupported(string $builder): bool { return is_a($builder, EloquentBuilder::class, true) || is_a($builder, ScoutBuilder::class, true); } diff --git a/packages/graphql/src/SortBy/Operators/Extra/NullsFirst.php b/packages/graphql/src/SortBy/Operators/Extra/NullsFirst.php index 82b0c27f5..3568111c8 100644 --- a/packages/graphql/src/SortBy/Operators/Extra/NullsFirst.php +++ b/packages/graphql/src/SortBy/Operators/Extra/NullsFirst.php @@ -2,12 +2,12 @@ namespace LastDragon_ru\LaraASP\GraphQL\SortBy\Operators\Extra; -use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\BuilderPropertyResolver; +use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\BuilderFieldResolver; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Context; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Handler; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\TypeProvider; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\TypeSource; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\Builder\Traits\HandlerOperator; use LastDragon_ru\LaraASP\GraphQL\SortBy\Contracts\SorterFactory; use LastDragon_ru\LaraASP\GraphQL\SortBy\Enums\Nulls; @@ -25,7 +25,7 @@ class NullsFirst extends Operator { */ public function __construct( protected readonly SorterFactory $factory, - BuilderPropertyResolver $resolver, + BuilderFieldResolver $resolver, ) { parent::__construct($resolver); } @@ -36,17 +36,17 @@ public static function getName(): string { } #[Override] - public function getFieldType(TypeProvider $provider, TypeSource $source, Context $context): string { + public function getFieldType(TypeProvider $provider, TypeSource $source, Context $context): ?string { return $provider->getType(Clause::class, $source, $context); } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'NULLs first'; } #[Override] - public function isAvailable(string $builder, Context $context): bool { + protected function isBuilderSupported(string $builder): bool { return (bool) $this->factory->create($builder)?->isNullsSupported(); } @@ -54,11 +54,11 @@ public function isAvailable(string $builder, Context $context): bool { public function call( Handler $handler, object $builder, - Property $property, + Field $field, Argument $argument, Context $context, ): object { - return $this->handle($handler, $builder, $property->getParent(), $argument, $context->override([ + return $this->handle($handler, $builder, $field->getParent(), $argument, $context->override([ SortContextNulls::class => new SortContextNulls(Nulls::First), ])); } diff --git a/packages/graphql/src/SortBy/Operators/Extra/NullsFirstTest.php b/packages/graphql/src/SortBy/Operators/Extra/NullsFirstTest.php index 6cef0e50b..c671dd857 100644 --- a/packages/graphql/src/SortBy/Operators/Extra/NullsFirstTest.php +++ b/packages/graphql/src/SortBy/Operators/Extra/NullsFirstTest.php @@ -4,7 +4,7 @@ use Closure; use LastDragon_ru\LaraASP\GraphQL\Builder\Context; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\SortBy\Directives\Directive; use LastDragon_ru\LaraASP\GraphQL\SortBy\Enums\Direction; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\DataProviders\BuilderDataProvider; @@ -35,12 +35,12 @@ final class NullsFirstTest extends TestCase { * @param BuilderFactory $builderFactory * @param Closure(static): Argument $argumentFactory * @param Closure(static): Context|null $contextFactory - * @param Closure(object, Property): string|null $resolver + * @param Closure(object, Field): string|null $resolver */ public function testCall( array $expected, Closure $builderFactory, - Property $property, + Field $field, Closure $argumentFactory, ?Closure $contextFactory, ?Closure $resolver, @@ -49,7 +49,7 @@ public function testCall( Directive::class, $expected, $builderFactory, - $property, + $field, $argumentFactory, $contextFactory, $resolver, @@ -89,12 +89,12 @@ public static function dataProviderCall(): array { return (new CompositeDataProvider( new BuilderDataProvider(), new ArrayDataProvider([ - 'property' => [ + 'field' => [ [ 'query' => 'select * from "test_objects" order by "a" DESC NULLS FIRST', 'bindings' => [], ], - new Property('operator name should be ignored'), + new Field('operator name should be ignored'), $argument, null, null, @@ -104,11 +104,11 @@ public static function dataProviderCall(): array { 'query' => 'select * from "test_objects" order by "resolved__a" DESC NULLS FIRST', 'bindings' => [], ], - new Property('operator name should be ignored'), + new Field('operator name should be ignored'), $argument, null, - static function (object $builder, Property $property): string { - return 'resolved__'.implode('__', $property->getPath()); + static function (object $builder, Field $field): string { + return 'resolved__'.implode('__', $field->getPath()); }, ], ]), diff --git a/packages/graphql/src/SortBy/Operators/Extra/NullsLast.php b/packages/graphql/src/SortBy/Operators/Extra/NullsLast.php index 8f0a851fb..093813f18 100644 --- a/packages/graphql/src/SortBy/Operators/Extra/NullsLast.php +++ b/packages/graphql/src/SortBy/Operators/Extra/NullsLast.php @@ -2,12 +2,12 @@ namespace LastDragon_ru\LaraASP\GraphQL\SortBy\Operators\Extra; -use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\BuilderPropertyResolver; +use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\BuilderFieldResolver; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Context; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Handler; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\TypeProvider; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\TypeSource; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\Builder\Traits\HandlerOperator; use LastDragon_ru\LaraASP\GraphQL\SortBy\Contracts\SorterFactory; use LastDragon_ru\LaraASP\GraphQL\SortBy\Enums\Nulls; @@ -25,7 +25,7 @@ class NullsLast extends Operator { */ public function __construct( protected readonly SorterFactory $factory, - BuilderPropertyResolver $resolver, + BuilderFieldResolver $resolver, ) { parent::__construct($resolver); } @@ -36,17 +36,17 @@ public static function getName(): string { } #[Override] - public function getFieldType(TypeProvider $provider, TypeSource $source, Context $context): string { + public function getFieldType(TypeProvider $provider, TypeSource $source, Context $context): ?string { return $provider->getType(Clause::class, $source, $context); } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'NULLs last'; } #[Override] - public function isAvailable(string $builder, Context $context): bool { + protected function isBuilderSupported(string $builder): bool { return (bool) $this->factory->create($builder)?->isNullsSupported(); } @@ -54,11 +54,11 @@ public function isAvailable(string $builder, Context $context): bool { public function call( Handler $handler, object $builder, - Property $property, + Field $field, Argument $argument, Context $context, ): object { - return $this->handle($handler, $builder, $property->getParent(), $argument, $context->override([ + return $this->handle($handler, $builder, $field->getParent(), $argument, $context->override([ SortContextNulls::class => new SortContextNulls(Nulls::Last), ])); } diff --git a/packages/graphql/src/SortBy/Operators/Extra/NullsLastTest.php b/packages/graphql/src/SortBy/Operators/Extra/NullsLastTest.php index 00e222dfa..2a4bbe6da 100644 --- a/packages/graphql/src/SortBy/Operators/Extra/NullsLastTest.php +++ b/packages/graphql/src/SortBy/Operators/Extra/NullsLastTest.php @@ -4,7 +4,7 @@ use Closure; use LastDragon_ru\LaraASP\GraphQL\Builder\Context; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\SortBy\Directives\Directive; use LastDragon_ru\LaraASP\GraphQL\SortBy\Enums\Direction; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\DataProviders\BuilderDataProvider; @@ -35,12 +35,12 @@ final class NullsLastTest extends TestCase { * @param BuilderFactory $builderFactory * @param Closure(static): Argument $argumentFactory * @param Closure(static): Context|null $contextFactory - * @param Closure(object, Property): string|null $resolver + * @param Closure(object, Field): string|null $resolver */ public function testCall( array $expected, Closure $builderFactory, - Property $property, + Field $field, Closure $argumentFactory, ?Closure $contextFactory, ?Closure $resolver, @@ -49,7 +49,7 @@ public function testCall( Directive::class, $expected, $builderFactory, - $property, + $field, $argumentFactory, $contextFactory, $resolver, @@ -89,12 +89,12 @@ public static function dataProviderCall(): array { return (new CompositeDataProvider( new BuilderDataProvider(), new ArrayDataProvider([ - 'property' => [ + 'field' => [ [ 'query' => 'select * from "test_objects" order by "a" ASC NULLS LAST', 'bindings' => [], ], - new Property('operator name should be ignored'), + new Field('operator name should be ignored'), $argument, null, null, @@ -104,11 +104,11 @@ public static function dataProviderCall(): array { 'query' => 'select * from "test_objects" order by "resolved__a" ASC NULLS LAST', 'bindings' => [], ], - new Property('operator name should be ignored'), + new Field('operator name should be ignored'), $argument, null, - static function (object $builder, Property $property): string { - return 'resolved__'.implode('__', $property->getPath()); + static function (object $builder, Field $field): string { + return 'resolved__'.implode('__', $field->getPath()); }, ], ]), diff --git a/packages/graphql/src/SortBy/Operators/Extra/Random.php b/packages/graphql/src/SortBy/Operators/Extra/Random.php index b10065b73..5a112f200 100644 --- a/packages/graphql/src/SortBy/Operators/Extra/Random.php +++ b/packages/graphql/src/SortBy/Operators/Extra/Random.php @@ -2,7 +2,6 @@ namespace LastDragon_ru\LaraASP\GraphQL\SortBy\Operators\Extra; -use GraphQL\Language\DirectiveLocation; use Illuminate\Database\Eloquent\Builder as EloquentBuilder; use Illuminate\Database\Query\Builder as QueryBuilder; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Context; @@ -10,28 +9,13 @@ use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\TypeProvider; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\TypeSource; use LastDragon_ru\LaraASP\GraphQL\Builder\Exceptions\OperatorUnsupportedBuilder; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\SortBy\Operators\Operator; use LastDragon_ru\LaraASP\GraphQL\SortBy\Types\Flag; use Nuwave\Lighthouse\Execution\Arguments\Argument; use Override; -use function array_merge; - class Random extends Operator { - // - // ========================================================================= - /** - * @inheritDoc - */ - #[Override] - protected static function getDirectiveLocations(): array { - return array_merge(parent::getDirectiveLocations(), [ - DirectiveLocation::FIELD_DEFINITION, - ]); - } - // - // // ========================================================================= #[Override] @@ -40,12 +24,12 @@ public static function getName(): string { } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'By random'; } #[Override] - public function getFieldType(TypeProvider $provider, TypeSource $source, Context $context): string { + public function getFieldType(TypeProvider $provider, TypeSource $source, Context $context): ?string { return $provider->getType(Flag::class, $source, $context); } @@ -53,7 +37,7 @@ public function getFieldType(TypeProvider $provider, TypeSource $source, Context public function call( Handler $handler, object $builder, - Property $property, + Field $field, Argument $argument, Context $context, ): object { diff --git a/packages/graphql/src/SortBy/Operators/Extra/RandomTest.php b/packages/graphql/src/SortBy/Operators/Extra/RandomTest.php index 38a4a69dc..6e77b7b2c 100644 --- a/packages/graphql/src/SortBy/Operators/Extra/RandomTest.php +++ b/packages/graphql/src/SortBy/Operators/Extra/RandomTest.php @@ -4,7 +4,7 @@ use Closure; use LastDragon_ru\LaraASP\GraphQL\Builder\Context; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\SortBy\Directives\Directive; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\DataProviders\BuilderDataProvider; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\OperatorTests; @@ -32,12 +32,12 @@ final class RandomTest extends TestCase { * @param BuilderFactory $builderFactory * @param Closure(static): Argument $argumentFactory * @param Closure(static): Context|null $contextFactory - * @param Closure(object, Property): string|null $resolver + * @param Closure(object, Field): string|null $resolver */ public function testCall( array $expected, Closure $builderFactory, - Property $property, + Field $field, Closure $argumentFactory, ?Closure $contextFactory, ?Closure $resolver, @@ -46,7 +46,7 @@ public function testCall( Directive::class, $expected, $builderFactory, - $property, + $field, $argumentFactory, $contextFactory, $resolver, @@ -63,24 +63,24 @@ public static function dataProviderCall(): array { return (new CompositeDataProvider( new BuilderDataProvider(), new ArrayDataProvider([ - 'property' => [ + 'field' => [ [ 'query' => 'select * from "test_objects" order by RANDOM()', 'bindings' => [], ], - new Property('property', 'operator name should be ignored'), + new Field('field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('SortByTypeFlag', 'yes'); }, null, null, ], - 'property.path' => [ + 'field.path' => [ [ 'query' => 'select * from "test_objects" order by RANDOM()', 'bindings' => [], ], - new Property('path', 'to', 'property', 'operator name should be ignored'), + new Field('path', 'to', 'field', 'operator name should be ignored'), static function (self $test): Argument { return $test->getGraphQLArgument('SortByTypeFlag', 'yes'); }, diff --git a/packages/graphql/src/SortBy/Operators/Field.php b/packages/graphql/src/SortBy/Operators/Field.php index 6f0c7ae7b..b4569dc63 100644 --- a/packages/graphql/src/SortBy/Operators/Field.php +++ b/packages/graphql/src/SortBy/Operators/Field.php @@ -6,10 +6,10 @@ use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Handler; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\TypeProvider; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\TypeSource; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field as BuilderField; use LastDragon_ru\LaraASP\GraphQL\Builder\Traits\HandlerOperator; use LastDragon_ru\LaraASP\GraphQL\Builder\Traits\WithScoutSupport; -use LastDragon_ru\LaraASP\GraphQL\SortBy\Types\Clause\Clause as ClauseType; +use LastDragon_ru\LaraASP\GraphQL\SortBy\Types\Clause\Clause; use Nuwave\Lighthouse\Execution\Arguments\Argument; use Override; @@ -23,12 +23,18 @@ public static function getName(): string { } #[Override] - public function getFieldType(TypeProvider $provider, TypeSource $source, Context $context): string { - return $provider->getType(ClauseType::class, $source, $context); + public function isAvailable(TypeProvider $provider, TypeSource $source, Context $context): bool { + return parent::isAvailable($provider, $source, $context) + && $source->isObject(); } #[Override] - public function getFieldDescription(): string { + public function getFieldType(TypeProvider $provider, TypeSource $source, Context $context): ?string { + return $provider->getType(Clause::class, $source, $context); + } + + #[Override] + public function getFieldDescription(): ?string { return 'Field.'; } @@ -36,10 +42,10 @@ public function getFieldDescription(): string { public function call( Handler $handler, object $builder, - Property $property, + BuilderField $field, Argument $argument, Context $context, ): object { - return $this->handle($handler, $builder, $property->getParent(), $argument, $context); + return $this->handle($handler, $builder, $field->getParent(), $argument, $context); } } diff --git a/packages/graphql/src/SortBy/Operators/Operator.php b/packages/graphql/src/SortBy/Operators/Operator.php index 2a4c56dd0..9b39aed95 100644 --- a/packages/graphql/src/SortBy/Operators/Operator.php +++ b/packages/graphql/src/SortBy/Operators/Operator.php @@ -4,7 +4,6 @@ use Illuminate\Database\Eloquent\Builder as EloquentBuilder; use Illuminate\Database\Query\Builder as QueryBuilder; -use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Context; use LastDragon_ru\LaraASP\GraphQL\Builder\Directives\OperatorDirective; use LastDragon_ru\LaraASP\GraphQL\SortBy\Contracts\Operator as Marker; use Override; @@ -13,7 +12,7 @@ abstract class Operator extends OperatorDirective implements Marker { #[Override] - public function isAvailable(string $builder, Context $context): bool { + protected function isBuilderSupported(string $builder): bool { return is_a($builder, EloquentBuilder::class, true) || is_a($builder, QueryBuilder::class, true); } diff --git a/packages/graphql/src/SortBy/Operators/Root.php b/packages/graphql/src/SortBy/Operators/Root.php index a127a1f4c..9427cc6b2 100644 --- a/packages/graphql/src/SortBy/Operators/Root.php +++ b/packages/graphql/src/SortBy/Operators/Root.php @@ -20,12 +20,12 @@ public static function getName(): string { } #[Override] - public function getFieldType(TypeProvider $provider, TypeSource $source, Context $context): string { + public function getFieldType(TypeProvider $provider, TypeSource $source, Context $context): ?string { return '['.$provider->getType(RootType::class, $source, $context).'!]'; } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Directive root.'; } } diff --git a/packages/graphql/src/SortBy/Operators/Sort.php b/packages/graphql/src/SortBy/Operators/Sort.php index 96082d607..aec7271d6 100644 --- a/packages/graphql/src/SortBy/Operators/Sort.php +++ b/packages/graphql/src/SortBy/Operators/Sort.php @@ -2,13 +2,13 @@ namespace LastDragon_ru\LaraASP\GraphQL\SortBy\Operators; -use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\BuilderPropertyResolver; +use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\BuilderFieldResolver; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Context; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Handler; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\TypeProvider; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\TypeSource; use LastDragon_ru\LaraASP\GraphQL\Builder\Exceptions\OperatorUnsupportedBuilder; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\Package; use LastDragon_ru\LaraASP\GraphQL\SortBy\Contracts\Sorter; use LastDragon_ru\LaraASP\GraphQL\SortBy\Contracts\SorterFactory; @@ -27,7 +27,7 @@ class Sort extends Operator { */ public function __construct( protected readonly SorterFactory $factory, - BuilderPropertyResolver $resolver, + BuilderFieldResolver $resolver, ) { parent::__construct($resolver); } @@ -38,17 +38,23 @@ public static function getName(): string { } #[Override] - public function getFieldType(TypeProvider $provider, TypeSource $source, Context $context): string { + public function isAvailable(TypeProvider $provider, TypeSource $source, Context $context): bool { + return parent::isAvailable($provider, $source, $context) + && ($source->isScalar() || $source->isEnum()); + } + + #[Override] + public function getFieldType(TypeProvider $provider, TypeSource $source, Context $context): ?string { return $provider->getType(DirectionType::class, $source, $context); } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Field clause.'; } #[Override] - public function isAvailable(string $builder, Context $context): bool { + protected function isBuilderSupported(string $builder): bool { return $this->factory->isSupported($builder); } @@ -56,7 +62,7 @@ public function isAvailable(string $builder, Context $context): bool { public function call( Handler $handler, object $builder, - Property $property, + Field $field, Argument $argument, Context $context, ): object { @@ -66,7 +72,7 @@ public function call( $direction = $argument->value instanceof Direction ? $argument->value : Direction::Asc; $nulls = $this->getNulls($sorter, $context, $direction); - $sorter->sort($builder, $property, $direction, $nulls); + $sorter->sort($builder, $field, $direction, $nulls); } else { throw new OperatorUnsupportedBuilder($this, $builder); } diff --git a/packages/graphql/src/SortBy/Operators/SortTest.php b/packages/graphql/src/SortBy/Operators/SortTest.php index 20269c752..df7a982be 100644 --- a/packages/graphql/src/SortBy/Operators/SortTest.php +++ b/packages/graphql/src/SortBy/Operators/SortTest.php @@ -9,7 +9,7 @@ use Illuminate\Database\Query\Builder as QueryBuilder; use Laravel\Scout\Builder as ScoutBuilder; use LastDragon_ru\LaraASP\GraphQL\Builder\Context; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\Package; use LastDragon_ru\LaraASP\GraphQL\SortBy\Contracts\Sorter; use LastDragon_ru\LaraASP\GraphQL\SortBy\Directives\Directive; @@ -51,12 +51,12 @@ final class SortTest extends TestCase { * @param BuilderFactory $builderFactory * @param Closure(static): Argument $argumentFactory * @param Closure(static): Context|null $contextFactory - * @param Closure(object, Property): string|null $resolver + * @param Closure(object, Field): string|null $resolver */ public function testCall( array $expected, Closure $builderFactory, - Property $property, + Field $field, Closure $argumentFactory, ?Closure $contextFactory, ?Closure $resolver, @@ -65,7 +65,7 @@ public function testCall( Directive::class, $expected, $builderFactory, - $property, + $field, $argumentFactory, $contextFactory, $resolver, @@ -87,7 +87,7 @@ public function testCallEloquentBuilder(): void { }); $directive = Container::getInstance()->make(Directive::class); - $property = new Property(); + $field = new Field(); $operator = Container::getInstance()->make(Sort::class); $argument = $this->getGraphQLArgument( 'Test', @@ -97,7 +97,7 @@ public function testCallEloquentBuilder(): void { $context = new Context(); $builder = Mockery::mock(EloquentBuilder::class); - $operator->call($directive, $builder, $property, $argument, $context); + $operator->call($directive, $builder, $field, $argument, $context); } public function testCallQueryBuilder(): void { @@ -114,7 +114,7 @@ public function testCallQueryBuilder(): void { }); $directive = Container::getInstance()->make(Directive::class); - $property = new Property(); + $field = new Field(); $operator = Container::getInstance()->make(Sort::class); $argument = $this->getGraphQLArgument( 'Test', @@ -123,7 +123,7 @@ public function testCallQueryBuilder(): void { $context = new Context(); $builder = Mockery::mock(QueryBuilder::class); - $operator->call($directive, $builder, $property, $argument, $context); + $operator->call($directive, $builder, $field, $argument, $context); } #[RequiresLaravelScout] @@ -141,7 +141,7 @@ public function testCallScoutBuilder(): void { }); $directive = Container::getInstance()->make(Directive::class); - $property = new Property(); + $field = new Field(); $operator = Container::getInstance()->make(Sort::class); $argument = $this->getGraphQLArgument( 'Test', @@ -151,7 +151,7 @@ public function testCallScoutBuilder(): void { $context = new Context(); $builder = Mockery::mock(ScoutBuilder::class); - $operator->call($directive, $builder, $property, $argument, $context); + $operator->call($directive, $builder, $field, $argument, $context); } /** @@ -211,12 +211,12 @@ public static function dataProviderCall(): array { return (new CompositeDataProvider( new BuilderDataProvider(), new ArrayDataProvider([ - 'property' => [ + 'field' => [ [ 'query' => 'select * from "test_objects" order by "a" desc', 'bindings' => [], ], - new Property('a'), + new Field('a'), $factory, static function (): Context { return new Context(); @@ -229,7 +229,7 @@ static function (): Context { 'query' => 'select * from "test_objects" order by "a" DESC NULLS FIRST', 'bindings' => [], ], - new Property('a'), + new Field('a'), $factory, static function (): Context { return (new Context())->override([ @@ -244,13 +244,13 @@ static function (): Context { 'query' => 'select * from "test_objects" order by "resolved__a" desc', 'bindings' => [], ], - new Property('a'), + new Field('a'), $factory, static function (): Context { return new Context(); }, - static function (object $builder, Property $property): string { - return 'resolved__'.implode('__', $property->getPath()); + static function (object $builder, Field $field): string { + return 'resolved__'.implode('__', $field->getPath()); }, ], ]), @@ -288,7 +288,7 @@ public function isNullsSupported(): bool { #[Override] public function sort( object $builder, - Property $property, + Field $field, Direction $direction, Nulls $nulls = null, ): object { diff --git a/packages/graphql/src/SortBy/Sorters/DatabaseSorter.php b/packages/graphql/src/SortBy/Sorters/DatabaseSorter.php index 77013217e..30bbf47de 100644 --- a/packages/graphql/src/SortBy/Sorters/DatabaseSorter.php +++ b/packages/graphql/src/SortBy/Sorters/DatabaseSorter.php @@ -10,7 +10,7 @@ use Illuminate\Database\Query\Grammars\SQLiteGrammar; use Illuminate\Database\Query\Grammars\SqlServerGrammar; use Illuminate\Support\Str; -use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\BuilderPropertyResolver; +use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\BuilderFieldResolver; use LastDragon_ru\LaraASP\GraphQL\Exceptions\NotImplemented; use LastDragon_ru\LaraASP\GraphQL\Package; use LastDragon_ru\LaraASP\GraphQL\SortBy\Contracts\Sorter; @@ -30,7 +30,7 @@ */ abstract class DatabaseSorter implements Sorter { public function __construct( - protected readonly BuilderPropertyResolver $resolver, + protected readonly BuilderFieldResolver $resolver, ) { // empty } diff --git a/packages/graphql/src/SortBy/Sorters/DatabaseSorterTest.php b/packages/graphql/src/SortBy/Sorters/DatabaseSorterTest.php index c001de7f8..dcc6343ec 100644 --- a/packages/graphql/src/SortBy/Sorters/DatabaseSorterTest.php +++ b/packages/graphql/src/SortBy/Sorters/DatabaseSorterTest.php @@ -7,8 +7,8 @@ use Illuminate\Database\Eloquent\Builder as EloquentBuilder; use Illuminate\Database\Eloquent\Model as EloquentModel; use Illuminate\Database\Query\Builder as QueryBuilder; -use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\BuilderPropertyResolver; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\BuilderFieldResolver; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\SortBy\Enums\Direction; use LastDragon_ru\LaraASP\GraphQL\SortBy\Enums\Nulls; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\Models\Car; @@ -46,14 +46,14 @@ public function testSortByColumn( Direction $direction, ?Nulls $nulls, ): void { - $resolver = Mockery::mock(BuilderPropertyResolver::class); + $resolver = Mockery::mock(BuilderFieldResolver::class); $builder = $builderFactory($this); $column = is_string($columnFactory) ? $columnFactory : $columnFactory($this); $sorter = new class($nullsDefault, $nullsOrderable, $resolver) extends DatabaseSorter { public function __construct( private readonly Nulls $nullsDefault, private readonly bool $nullsOrderable, - BuilderPropertyResolver $resolver, + BuilderFieldResolver $resolver, ) { parent::__construct($resolver); } @@ -61,7 +61,7 @@ public function __construct( #[Override] public function sort( object $builder, - Property $property, + Field $field, Direction $direction, Nulls $nulls = null, ): object { @@ -93,13 +93,13 @@ public function sortByColumn( } public function testGetAlias(): void { - $resolver = Mockery::mock(BuilderPropertyResolver::class); + $resolver = Mockery::mock(BuilderFieldResolver::class); $builder = User::query()->where('name', '=', 'name'); $sorter = new class($resolver) extends DatabaseSorter { #[Override] public function sort( object $builder, - Property $property, + Field $field, Direction $direction, Nulls $nulls = null, ): object { diff --git a/packages/graphql/src/SortBy/Sorters/EloquentSorter.php b/packages/graphql/src/SortBy/Sorters/EloquentSorter.php index 89a5b8c24..cd1cff506 100644 --- a/packages/graphql/src/SortBy/Sorters/EloquentSorter.php +++ b/packages/graphql/src/SortBy/Sorters/EloquentSorter.php @@ -12,7 +12,7 @@ use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Database\Query\JoinClause; use LastDragon_ru\LaraASP\Eloquent\ModelHelper; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\SortBy\Enums\Direction; use LastDragon_ru\LaraASP\GraphQL\SortBy\Enums\Nulls; use LastDragon_ru\LaraASP\GraphQL\SortBy\Exceptions\RelationUnsupported; @@ -27,15 +27,15 @@ class EloquentSorter extends DatabaseSorter { // // ========================================================================= #[Override] - public function sort(object $builder, Property $property, Direction $direction, Nulls $nulls = null): object { + public function sort(object $builder, Field $field, Direction $direction, Nulls $nulls = null): object { // Column - $relation = $property->getParent()->getPath(); + $relation = $field->getParent()->getPath(); if ($relation) { - $column = $property->getName(); + $column = $field->getName(); $column = $this->getRelationColumn($builder, $relation, $column, $direction); } else { - $column = $this->resolver->getProperty($builder, $property); + $column = $this->resolver->getField($builder, $field); } // Order @@ -81,7 +81,7 @@ protected function getRelationColumn( } // We need only one row - $qualified = $this->resolver->getProperty($relation->getQuery(), new Property($alias, $column)); + $qualified = $this->resolver->getField($relation->getQuery(), new Field($alias, $column)); $query = $query->select($qualified)->reorder()->limit(1); $query = $this->sortByColumn($query, $qualified, $direction); diff --git a/packages/graphql/src/SortBy/Sorters/EloquentSorterTest.php b/packages/graphql/src/SortBy/Sorters/EloquentSorterTest.php index 04238d7dc..c05f3d7c6 100644 --- a/packages/graphql/src/SortBy/Sorters/EloquentSorterTest.php +++ b/packages/graphql/src/SortBy/Sorters/EloquentSorterTest.php @@ -17,8 +17,8 @@ use Illuminate\Database\Eloquent\Relations\MorphOne; use Illuminate\Database\Eloquent\Relations\MorphToMany; use LastDragon_ru\LaraASP\Eloquent\Exceptions\PropertyIsNotRelation; -use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\BuilderPropertyResolver; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\BuilderFieldResolver; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\SortBy\Enums\Direction; use LastDragon_ru\LaraASP\GraphQL\SortBy\Enums\Nulls; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\DataProviders\EloquentBuilderDataProvider; @@ -48,12 +48,12 @@ final class EloquentSorterTest extends TestCase { * * @param array{query: string, bindings: array}|Exception $expected * @param Closure(static): EloquentBuilder $builder - * @param Closure(object, Property): string|null $resolver + * @param Closure(object, Field): string|null $resolver */ public function testSort( array|Exception $expected, Closure $builder, - Property $property, + Field $field, Direction $direction, ?Nulls $nulls, ?Closure $resolver, @@ -64,10 +64,10 @@ public function testSort( if ($resolver) { $this->override( - BuilderPropertyResolver::class, + BuilderFieldResolver::class, static function (MockInterface $mock) use ($resolver): void { $mock - ->shouldReceive('getProperty') + ->shouldReceive('getField') ->once() ->andReturnUsing($resolver); }, @@ -76,7 +76,7 @@ static function (MockInterface $mock) use ($resolver): void { $sorter = Container::getInstance()->make(EloquentSorter::class); $builder = $builder($this); - $builder = $sorter->sort($builder, $property, $direction, $nulls); + $builder = $sorter->sort($builder, $field, $direction, $nulls); if (is_array($expected)) { self::assertDatabaseQueryEquals($expected, $builder); @@ -101,7 +101,7 @@ public static function dataProviderSort(): array { 'query' => 'select * from "test_objects" order by "name" desc', 'bindings' => [], ], - new Property('name'), + new Field('name'), Direction::Desc, null, null, @@ -114,7 +114,7 @@ public static function dataProviderSort(): array { static function (): EloquentBuilder { return User::query(); }, - new Property('unknown', 'name'), + new Field('unknown', 'name'), Direction::Asc, null, null, @@ -157,7 +157,7 @@ static function (): EloquentBuilder { static function (): EloquentBuilder { return Car::query(); }, - new Property('user', 'organization', 'name'), + new Field('user', 'organization', 'name'), Direction::Desc, null, null, @@ -203,7 +203,7 @@ static function (): EloquentBuilder { static function (): EloquentBuilder { return User::query(); }, - new Property('car', 'engine', 'id'), + new Field('car', 'engine', 'id'), Direction::Asc, null, null, @@ -238,7 +238,7 @@ static function (): EloquentBuilder { static function (): EloquentBuilder { return User::query(); }, - new Property('cars', 'name'), + new Field('cars', 'name'), Direction::Asc, null, null, @@ -274,7 +274,7 @@ static function (): EloquentBuilder { static function (): EloquentBuilder { return User::query(); }, - new Property('avatar', 'id'), + new Field('avatar', 'id'), Direction::Asc, null, null, @@ -321,7 +321,7 @@ static function (): EloquentBuilder { static function (): EloquentBuilder { return User::query(); }, - new Property('role', 'user', 'name'), + new Field('role', 'user', 'name'), Direction::Desc, null, null, @@ -369,7 +369,7 @@ static function (): EloquentBuilder { static function (): EloquentBuilder { return User::query(); }, - new Property('roles', 'users', 'name'), + new Field('roles', 'users', 'name'), Direction::Desc, null, null, @@ -415,7 +415,7 @@ static function (): EloquentBuilder { static function (): EloquentBuilder { return User::query(); }, - new Property('tags', 'users', 'name'), + new Field('tags', 'users', 'name'), Direction::Asc, null, null, @@ -451,7 +451,7 @@ static function (): EloquentBuilder { static function (): EloquentBuilder { return CarEngine::query(); }, - new Property('users', 'name'), + new Field('users', 'name'), Direction::Asc, null, null, @@ -487,7 +487,7 @@ static function (): EloquentBuilder { static function (): EloquentBuilder { return User::query(); }, - new Property('images', 'id'), + new Field('images', 'id'), Direction::Asc, null, null, @@ -510,7 +510,7 @@ static function (): EloquentBuilder { static function (): EloquentBuilder { return User::query(); }, - new Property('name'), + new Field('name'), Direction::Desc, Nulls::First, null, @@ -533,14 +533,14 @@ static function (): EloquentBuilder { static function (): EloquentBuilder { return User::query(); }, - new Property('name'), + new Field('name'), Direction::Asc, null, - static function (object $builder, Property $property): string { + static function (object $builder, Field $field): string { self::assertInstanceOf(EloquentBuilder::class, $builder); self::assertInstanceOf(User::class, $builder->getModel()); - return 'resolved__'.implode('__', $property->getPath()); + return 'resolved__'.implode('__', $field->getPath()); }, ], 'resolver (relation)' => [ @@ -595,14 +595,14 @@ static function (object $builder, Property $property): string { static function (): EloquentBuilder { return User::query(); }, - new Property('cars', 'user', 'roles', 'name'), + new Field('cars', 'user', 'roles', 'name'), Direction::Asc, null, - static function (object $builder, Property $property): string { + static function (object $builder, Field $field): string { self::assertInstanceOf(EloquentBuilder::class, $builder); self::assertInstanceOf(Role::class, $builder->getModel()); - return implode('.', $property->getParent()->getPath()).'.resolved__'.$property->getName(); + return implode('.', $field->getParent()->getPath()).'.resolved__'.$field->getName(); }, ], ])), diff --git a/packages/graphql/src/SortBy/Sorters/QuerySorter.php b/packages/graphql/src/SortBy/Sorters/QuerySorter.php index 2027c088b..3d7a808c5 100644 --- a/packages/graphql/src/SortBy/Sorters/QuerySorter.php +++ b/packages/graphql/src/SortBy/Sorters/QuerySorter.php @@ -3,7 +3,7 @@ namespace LastDragon_ru\LaraASP\GraphQL\SortBy\Sorters; use Illuminate\Database\Query\Builder as QueryBuilder; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\SortBy\Enums\Direction; use LastDragon_ru\LaraASP\GraphQL\SortBy\Enums\Nulls; use Override; @@ -13,8 +13,8 @@ */ class QuerySorter extends DatabaseSorter { #[Override] - public function sort(object $builder, Property $property, Direction $direction, Nulls $nulls = null): object { - $column = $this->resolver->getProperty($builder, $property); + public function sort(object $builder, Field $field, Direction $direction, Nulls $nulls = null): object { + $column = $this->resolver->getField($builder, $field); $builder = $this->sortByColumn($builder, $column, $direction, $nulls); return $builder; diff --git a/packages/graphql/src/SortBy/Sorters/QuerySorterTest.php b/packages/graphql/src/SortBy/Sorters/QuerySorterTest.php index d9e25dca6..3dd8ded6d 100644 --- a/packages/graphql/src/SortBy/Sorters/QuerySorterTest.php +++ b/packages/graphql/src/SortBy/Sorters/QuerySorterTest.php @@ -6,8 +6,8 @@ use Exception; use Illuminate\Container\Container; use Illuminate\Database\Query\Builder as QueryBuilder; -use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\BuilderPropertyResolver; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\BuilderFieldResolver; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\SortBy\Enums\Direction; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\DataProviders\QueryBuilderDataProvider; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\TestCase; @@ -31,12 +31,12 @@ final class QuerySorterTest extends TestCase { * * @param array{query: string, bindings: array}|Exception $expected * @param Closure(static): QueryBuilder $builder - * @param Closure(object, Property): string|null $resolver + * @param Closure(object, Field): string|null $resolver */ public function testSort( array|Exception $expected, Closure $builder, - Property $property, + Field $field, Direction $direction, ?Closure $resolver, ): void { @@ -46,10 +46,10 @@ public function testSort( if ($resolver) { $this->override( - BuilderPropertyResolver::class, + BuilderFieldResolver::class, static function (MockInterface $mock) use ($resolver): void { $mock - ->shouldReceive('getProperty') + ->shouldReceive('getField') ->once() ->andReturnUsing($resolver); }, @@ -58,7 +58,7 @@ static function (MockInterface $mock) use ($resolver): void { $sorter = Container::getInstance()->make(QuerySorter::class); $builder = $builder($this); - $builder = $sorter->sort($builder, $property, $direction, null); + $builder = $sorter->sort($builder, $field, $direction, null); if (is_array($expected)) { self::assertDatabaseQueryEquals($expected, $builder); @@ -82,28 +82,28 @@ public static function dataProviderSort(): array { 'query' => 'select * from "test_objects" order by "a" asc', 'bindings' => [], ], - new Property('a'), + new Field('a'), Direction::Asc, null, ], - 'property.path' => [ + 'field.path' => [ [ - 'query' => 'select * from "test_objects" order by "path"."to"."property" asc', + 'query' => 'select * from "test_objects" order by "path"."to"."field" asc', 'bindings' => [], ], - new Property('path', 'to', 'property'), + new Field('path', 'to', 'field'), Direction::Asc, null, ], 'resolver' => [ [ - 'query' => 'select * from "test_objects" order by "path__to__property" asc', + 'query' => 'select * from "test_objects" order by "path__to__field" asc', 'bindings' => [], ], - new Property('path', 'to', 'property'), + new Field('path', 'to', 'field'), Direction::Asc, - static function (object $builder, Property $property): string { - return implode('__', $property->getPath()); + static function (object $builder, Field $field): string { + return implode('__', $field->getPath()); }, ], ]), diff --git a/packages/graphql/src/SortBy/Sorters/ScoutSorter.php b/packages/graphql/src/SortBy/Sorters/ScoutSorter.php index 10a1ae1d2..b4f9a52eb 100644 --- a/packages/graphql/src/SortBy/Sorters/ScoutSorter.php +++ b/packages/graphql/src/SortBy/Sorters/ScoutSorter.php @@ -3,8 +3,8 @@ namespace LastDragon_ru\LaraASP\GraphQL\SortBy\Sorters; use Laravel\Scout\Builder as ScoutBuilder; -use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\BuilderPropertyResolver; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\BuilderFieldResolver; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\Exceptions\NotImplemented; use LastDragon_ru\LaraASP\GraphQL\SortBy\Contracts\Sorter; use LastDragon_ru\LaraASP\GraphQL\SortBy\Enums\Direction; @@ -16,7 +16,7 @@ */ class ScoutSorter implements Sorter { public function __construct( - protected readonly BuilderPropertyResolver $resolver, + protected readonly BuilderFieldResolver $resolver, ) { // empty } @@ -27,12 +27,12 @@ public function isNullsSupported(): bool { } #[Override] - public function sort(object $builder, Property $property, Direction $direction, Nulls $nulls = null): object { + public function sort(object $builder, Field $field, Direction $direction, Nulls $nulls = null): object { if ($nulls) { throw new NotImplemented('NULLs ordering'); } - $field = $this->resolver->getProperty($builder, $property); + $field = $this->resolver->getField($builder, $field); $builder = match ($direction) { Direction::Asc, Direction::asc => $builder->orderBy($field, 'asc'), Direction::Desc, Direction::desc => $builder->orderBy($field, 'desc'), diff --git a/packages/graphql/src/SortBy/Sorters/ScoutSorterTest.php b/packages/graphql/src/SortBy/Sorters/ScoutSorterTest.php index f45779d5c..907c717e3 100644 --- a/packages/graphql/src/SortBy/Sorters/ScoutSorterTest.php +++ b/packages/graphql/src/SortBy/Sorters/ScoutSorterTest.php @@ -7,9 +7,9 @@ use Illuminate\Container\Container; use Illuminate\Database\Eloquent\Model; use Laravel\Scout\Builder as ScoutBuilder; -use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\BuilderPropertyResolver; +use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\BuilderFieldResolver; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Scout\FieldResolver; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\SortBy\Enums\Direction; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\Requirements\RequiresLaravelScout; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\TestCase; @@ -31,13 +31,13 @@ final class ScoutSorterTest extends TestCase { /** * @dataProvider dataProviderSort * - * @param array|Exception $expected - * @param Closure(object, Property): string|null $resolver - * @param Closure():FieldResolver|null $fieldResolver + * @param array|Exception $expected + * @param Closure(object, Field): string|null $resolver + * @param Closure():FieldResolver|null $fieldResolver */ public function testSort( array|Exception $expected, - Property $property, + Field $field, Direction $direction, ?Closure $resolver, ?Closure $fieldResolver, @@ -48,10 +48,10 @@ public function testSort( if ($resolver) { $this->override( - BuilderPropertyResolver::class, + BuilderFieldResolver::class, static function (MockInterface $mock) use ($resolver): void { $mock - ->shouldReceive('getProperty') + ->shouldReceive('getField') ->atLeast() ->once() ->andReturnUsing($resolver); @@ -70,7 +70,7 @@ static function (MockInterface $mock) use ($resolver): void { // empty }, ]); - $builder = $sorter->sort($builder, $property, $direction, null); + $builder = $sorter->sort($builder, $field, $direction, null); if (is_array($expected)) { self::assertScoutQueryEquals($expected, $builder); @@ -94,7 +94,7 @@ public static function dataProviderSort(): array { ], ], ], - new Property('c', 'd', 'e'), + new Field('c', 'd', 'e'), Direction::Desc, null, null, @@ -108,7 +108,7 @@ public static function dataProviderSort(): array { ], ], ], - new Property('a', 'b'), + new Field('a', 'b'), Direction::Asc, null, static function (): FieldResolver { @@ -117,8 +117,8 @@ static function (): FieldResolver { * @inheritDoc */ #[Override] - public function getField(Model $model, Property $property): string { - return 'properties/'.implode('/', $property->getPath()); + public function getField(Model $model, Field $field): string { + return 'properties/'.implode('/', $field->getPath()); } }; }, @@ -132,10 +132,10 @@ public function getField(Model $model, Property $property): string { ], ], ], - new Property('a', 'b'), + new Field('a', 'b'), Direction::Asc, - static function (object $builder, Property $property): string { - return implode('__', $property->getPath()); + static function (object $builder, Field $field): string { + return implode('__', $field->getPath()); }, null, ], diff --git a/packages/graphql/src/SortBy/Types/Clause/Root.php b/packages/graphql/src/SortBy/Types/Clause/Root.php index 692fed6aa..475b7a5fa 100644 --- a/packages/graphql/src/SortBy/Types/Clause/Root.php +++ b/packages/graphql/src/SortBy/Types/Clause/Root.php @@ -7,29 +7,9 @@ use LastDragon_ru\LaraASP\GraphQL\Builder\Sources\InputSource; use LastDragon_ru\LaraASP\GraphQL\Builder\Sources\InterfaceSource; use LastDragon_ru\LaraASP\GraphQL\Builder\Sources\ObjectSource; -use LastDragon_ru\LaraASP\GraphQL\SortBy\Definitions\SortByOperatorFieldDirective; use Override; -use function array_merge; - class Root extends Type { - /** - * @inheritDoc - */ - #[Override] - protected function getOperators( - Manipulator $manipulator, - InterfaceSource|InputSource|ObjectSource $source, - Context $context, - ): array { - return array_merge( - parent::getOperators($manipulator, $source, $context), - [ - $manipulator->getOperator($this->getScope(), SortByOperatorFieldDirective::class), - ], - ); - } - /** * @inheritDoc */ diff --git a/packages/graphql/src/SortBy/Types/Clause/Type.php b/packages/graphql/src/SortBy/Types/Clause/Type.php index 70edfe94f..c7e5a4a23 100644 --- a/packages/graphql/src/SortBy/Types/Clause/Type.php +++ b/packages/graphql/src/SortBy/Types/Clause/Type.php @@ -2,9 +2,9 @@ namespace LastDragon_ru\LaraASP\GraphQL\SortBy\Types\Clause; -use GraphQL\Language\Parser; use LastDragon_ru\LaraASP\GraphQL\Builder\Context\HandlerContextBuilderInfo; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Context; +use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Operator as OperatorContract; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\TypeSource; use LastDragon_ru\LaraASP\GraphQL\Builder\Manipulator; use LastDragon_ru\LaraASP\GraphQL\Builder\Sources\InputFieldSource; @@ -20,12 +20,9 @@ use LastDragon_ru\LaraASP\GraphQL\SortBy\Definitions\SortByOperatorSortDirective; use LastDragon_ru\LaraASP\GraphQL\SortBy\Directives\Directive; use LastDragon_ru\LaraASP\GraphQL\SortBy\Operators; -use LastDragon_ru\LaraASP\GraphQL\SortBy\Types\Direction; use Override; use ReflectionClass; -use function is_string; - abstract class Type extends InputObject { #[Override] public function getTypeName(TypeSource $source, Context $context): string { @@ -48,7 +45,7 @@ protected function getDescription( InputSource|ObjectSource|InterfaceSource $source, Context $context, ): string { - return "Sort clause for `{$source}` (only one property allowed at a time)."; + return "Sort clause for `{$source}` (only one field allowed at a time)."; } #[Override] @@ -91,30 +88,21 @@ protected function getTypeForFieldOperator(): ?string { return Operators::Object; } - /** - * @inheritDoc - */ #[Override] protected function getFieldOperator( Manipulator $manipulator, InputFieldSource|ObjectFieldSource|InterfaceFieldSource $field, Context $context, - ): ?array { - $operator = match (true) { - $field->isScalar(), $field->isEnum() => Direction::class, + ): ?OperatorContract { + return match (true) { + $field->isScalar(), $field->isEnum() => $manipulator->getOperator( + SortByOperatorSortDirective::class, + $this->getScope(), + $field, + $context, + ), $field->isObject() => parent::getFieldOperator($manipulator, $field, $context), default => throw new NotImplemented($field), }; - - if (is_string($operator)) { - $type = $manipulator->getType($operator, $field, $context); - $source = $manipulator->getTypeSource(Parser::typeReference($type)); - $operator = $manipulator->getOperator($this->getScope(), SortByOperatorSortDirective::class); - $operator = [$operator, $source]; - } else { - // empty - } - - return $operator; } } diff --git a/packages/graphql/src/SortBy/Types/Clause/V5.php b/packages/graphql/src/SortBy/Types/Clause/V5.php index 69671d4b6..ece3eb2b3 100644 --- a/packages/graphql/src/SortBy/Types/Clause/V5.php +++ b/packages/graphql/src/SortBy/Types/Clause/V5.php @@ -5,9 +5,17 @@ use LastDragon_ru\LaraASP\GraphQL\Builder\Context\HandlerContextBuilderInfo; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Context; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\TypeSource; +use LastDragon_ru\LaraASP\GraphQL\Builder\Manipulator; +use LastDragon_ru\LaraASP\GraphQL\Builder\Sources\InputSource; +use LastDragon_ru\LaraASP\GraphQL\Builder\Sources\InterfaceSource; +use LastDragon_ru\LaraASP\GraphQL\Builder\Sources\ObjectSource; +use LastDragon_ru\LaraASP\GraphQL\SortBy\Definitions\SortByOperatorFieldDirective; use LastDragon_ru\LaraASP\GraphQL\SortBy\Directives\Directive; use Override; +use function array_filter; +use function array_values; + /** * @deprecated 5.5.0 Please migrate to the new query structure. */ @@ -21,4 +29,20 @@ public function getTypeName(TypeSource $source, Context $context): string { return "{$directiveName}{$builderName}{$name}{$typeName}"; } + + /** + * @inheritDoc + */ + #[Override] + protected function getOperators( + Manipulator $manipulator, + InterfaceSource|InputSource|ObjectSource $source, + Context $context, + ): array { + $operators = parent::getOperators($manipulator, $source, $context); + $operators = array_filter($operators, static fn ($o) => !($o instanceof SortByOperatorFieldDirective)); + $operators = array_values($operators); + + return $operators; + } } diff --git a/packages/graphql/src/Stream/Directives/DirectiveTest~schema-expected.graphql b/packages/graphql/src/Stream/Directives/DirectiveTest~schema-expected.graphql index 33152f99b..4137d5060 100644 --- a/packages/graphql/src/Stream/Directives/DirectiveTest~schema-expected.graphql +++ b/packages/graphql/src/Stream/Directives/DirectiveTest~schema-expected.graphql @@ -139,7 +139,7 @@ enum SortByTypeDirection { } """ -Available conditions for `type TestObject` (only one property allowed at a time). +Available conditions for `type TestObject` (only one field allowed at a time). """ input SearchByConditionTestObject { """ @@ -150,7 +150,7 @@ input SearchByConditionTestObject { } """ -Available conditions for `type TestObject` (only one property allowed at a time). +Available conditions for `type TestObject` (only one field allowed at a time). """ input SearchByRootTestObject { """ @@ -190,7 +190,7 @@ input SearchByScalarID { } """ -Sort clause for `type TestObject` (only one property allowed at a time). +Sort clause for `type TestObject` (only one field allowed at a time). """ input SortByClauseTestObject { """ @@ -201,7 +201,7 @@ input SortByClauseTestObject { } """ -Sort clause for `type TestObject` (only one property allowed at a time). +Sort clause for `type TestObject` (only one field allowed at a time). """ input SortByRootTestObject { """ diff --git a/packages/graphql/src/Stream/Directives/DirectiveTest~scout-expected.graphql b/packages/graphql/src/Stream/Directives/DirectiveTest~scout-expected.graphql index 521642037..d6ce77eef 100644 --- a/packages/graphql/src/Stream/Directives/DirectiveTest~scout-expected.graphql +++ b/packages/graphql/src/Stream/Directives/DirectiveTest~scout-expected.graphql @@ -115,7 +115,7 @@ enum SortByTypeDirection { } """ -Available conditions for `type TestObject` (only one property allowed at a time). +Available conditions for `type TestObject` (only one field allowed at a time). """ input SearchByScoutConditionTestObject { """ @@ -126,7 +126,7 @@ input SearchByScoutConditionTestObject { } """ -Available conditions for `type TestObject` (only one property allowed at a time). +Available conditions for `type TestObject` (only one field allowed at a time). """ input SearchByScoutRootTestObject { """ @@ -154,7 +154,7 @@ input SearchByScoutScalarID { } """ -Sort clause for `type TestObject` (only one property allowed at a time). +Sort clause for `type TestObject` (only one field allowed at a time). """ input SortByScoutClauseTestObject { """ @@ -165,7 +165,7 @@ input SortByScoutClauseTestObject { } """ -Sort clause for `type TestObject` (only one property allowed at a time). +Sort clause for `type TestObject` (only one field allowed at a time). """ input SortByScoutRootTestObject { """ diff --git a/packages/graphql/src/Testing/Package/OperatorTests.php b/packages/graphql/src/Testing/Package/OperatorTests.php index ac4e44a77..4e916b106 100644 --- a/packages/graphql/src/Testing/Package/OperatorTests.php +++ b/packages/graphql/src/Testing/Package/OperatorTests.php @@ -9,10 +9,10 @@ use Illuminate\Database\Query\Builder as QueryBuilder; use Laravel\Scout\Builder as ScoutBuilder; use LastDragon_ru\LaraASP\GraphQL\Builder\Context; -use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\BuilderPropertyResolver; +use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\BuilderFieldResolver; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Handler; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Operator; -use LastDragon_ru\LaraASP\GraphQL\Builder\Property; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\Testing\Package\DataProviders\BuilderDataProvider; use LogicException; use Mockery\MockInterface; @@ -39,18 +39,18 @@ trait OperatorTests { * PHPStorm or PHPUnit issue). Anyway, this approach requires less * copy-pasting. * - * @param class-string $directive - * @param array|Exception $expected - * @param Closure(static): object $builderFactory - * @param Closure(static): Argument $argumentFactory - * @param Closure(static): Context|null $contextFactory - * @param Closure(object, Property): string|null $resolver + * @param class-string $directive + * @param array|Exception $expected + * @param Closure(static): object $builderFactory + * @param Closure(static): Argument $argumentFactory + * @param Closure(static): Context|null $contextFactory + * @param Closure(object, Field): string|null $resolver */ private function testOperator( string $directive, array|Exception $expected, Closure $builderFactory, - Property $property, + Field $field, Closure $argumentFactory, ?Closure $contextFactory, ?Closure $resolver, @@ -61,10 +61,10 @@ private function testOperator( if ($resolver) { $this->override( - BuilderPropertyResolver::class, + BuilderFieldResolver::class, static function (MockInterface $mock) use ($resolver): void { $mock - ->shouldReceive('getProperty') + ->shouldReceive('getField') ->atLeast() ->once() ->andReturnUsing($resolver); @@ -77,7 +77,7 @@ static function (MockInterface $mock) use ($resolver): void { $context = $contextFactory ? $contextFactory($this) : new Context(); $handler = Container::getInstance()->make($directive); $builder = $builderFactory($this); - $actual = $operator->call($handler, $builder, $property, $argument, $context); + $actual = $operator->call($handler, $builder, $field, $argument, $context); if (is_array($expected)) { if ($builder instanceof EloquentBuilder) {