From a702eb6d35990eb0aa4c9b88a6f74c84a131b7ee Mon Sep 17 00:00:00 2001 From: Aleksei Lebedev <1329824+LastDragon-ru@users.noreply.github.com> Date: Thu, 8 Feb 2024 13:58:30 +0400 Subject: [PATCH 01/15] [`@searchBy`] `SearchByRelationshipRelationType` => `SearchByRelationshipType` (excess `Relation` removed). --- .../CustomComplexOperator.expected.graphql | 4 +- .../DirectiveTest/Example.expected.graphql | 4 +- .../DirectiveTest/Explicit.expected.graphql | 10 ++--- .../DirectiveTest/Implicit.expected.graphql | 38 +++++++++---------- .../TypeRegistry.expected.graphql | 4 +- .../DirectiveTest/V5Compat.expected.graphql | 4 +- .../Operators/Complex/RelationshipType.php | 4 +- 7 files changed, 33 insertions(+), 35 deletions(-) diff --git a/packages/graphql/src/SearchBy/Directives/DirectiveTest/CustomComplexOperator.expected.graphql b/packages/graphql/src/SearchBy/Directives/DirectiveTest/CustomComplexOperator.expected.graphql index a27e9e5a6..888104223 100644 --- a/packages/graphql/src/SearchBy/Directives/DirectiveTest/CustomComplexOperator.expected.graphql +++ b/packages/graphql/src/SearchBy/Directives/DirectiveTest/CustomComplexOperator.expected.graphql @@ -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. """ diff --git a/packages/graphql/src/SearchBy/Directives/DirectiveTest/Example.expected.graphql b/packages/graphql/src/SearchBy/Directives/DirectiveTest/Example.expected.graphql index a36b5a928..fd87cbbe1 100644 --- a/packages/graphql/src/SearchBy/Directives/DirectiveTest/Example.expected.graphql +++ b/packages/graphql/src/SearchBy/Directives/DirectiveTest/Example.expected.graphql @@ -228,7 +228,7 @@ input SearchByConditionCommentsQuery { """ Relationship condition. """ - user: SearchByRelationshipRelationUsersQuery + user: SearchByRelationshipUsersQuery @searchByOperatorRelationship } @@ -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. """ diff --git a/packages/graphql/src/SearchBy/Directives/DirectiveTest/Explicit.expected.graphql b/packages/graphql/src/SearchBy/Directives/DirectiveTest/Explicit.expected.graphql index a7e636fde..ea829cf4b 100644 --- a/packages/graphql/src/SearchBy/Directives/DirectiveTest/Explicit.expected.graphql +++ b/packages/graphql/src/SearchBy/Directives/DirectiveTest/Explicit.expected.graphql @@ -230,13 +230,13 @@ input SearchByConditionA { """ Relationship condition. """ - field: SearchByRelationshipRelationB + field: SearchByRelationshipB @searchByOperatorRelationship """ Relationship condition. """ - fields: SearchByRelationshipRelationB + fields: SearchByRelationshipB @searchByOperatorRelationship """ @@ -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. """ diff --git a/packages/graphql/src/SearchBy/Directives/DirectiveTest/Implicit.expected.graphql b/packages/graphql/src/SearchBy/Directives/DirectiveTest/Implicit.expected.graphql index 59c07c8e6..1b31d7cd2 100644 --- a/packages/graphql/src/SearchBy/Directives/DirectiveTest/Implicit.expected.graphql +++ b/packages/graphql/src/SearchBy/Directives/DirectiveTest/Implicit.expected.graphql @@ -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 """ @@ -371,7 +371,7 @@ input SearchByConditionB { """ Relationship condition. """ - parent: SearchByRelationshipRelationA + parent: SearchByRelationshipA @searchByOperatorRelationship } @@ -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. """ diff --git a/packages/graphql/src/SearchBy/Directives/DirectiveTest/TypeRegistry.expected.graphql b/packages/graphql/src/SearchBy/Directives/DirectiveTest/TypeRegistry.expected.graphql index a8f93da5a..cf420715f 100644 --- a/packages/graphql/src/SearchBy/Directives/DirectiveTest/TypeRegistry.expected.graphql +++ b/packages/graphql/src/SearchBy/Directives/DirectiveTest/TypeRegistry.expected.graphql @@ -238,7 +238,7 @@ 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. """ diff --git a/packages/graphql/src/SearchBy/Directives/DirectiveTest/V5Compat.expected.graphql b/packages/graphql/src/SearchBy/Directives/DirectiveTest/V5Compat.expected.graphql index 776069b5c..86a7ff58a 100644 --- a/packages/graphql/src/SearchBy/Directives/DirectiveTest/V5Compat.expected.graphql +++ b/packages/graphql/src/SearchBy/Directives/DirectiveTest/V5Compat.expected.graphql @@ -240,7 +240,7 @@ input SearchByConditionCommentsQuery { """ Relationship condition. """ - user: SearchByRelationshipRelationUsersQuery + user: SearchByRelationshipUsersQuery @searchByOperatorRelationship } @@ -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/Operators/Complex/RelationshipType.php b/packages/graphql/src/SearchBy/Operators/Complex/RelationshipType.php index 99dbff373..6e3425eeb 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] From 2782209ed09376a478b2197b30a24ddcb3e18520 Mon Sep 17 00:00:00 2001 From: Aleksei Lebedev <1329824+LastDragon-ru@users.noreply.github.com> Date: Fri, 9 Feb 2024 09:47:10 +0400 Subject: [PATCH 02/15] The "field" will be used instead of "property". --- packages/graphql/README.md | 10 +-- packages/graphql/UPGRADE.md | 12 ++- .../Contracts/BuilderFieldResolver.php | 12 +++ .../Contracts/BuilderPropertyResolver.php | 12 --- .../graphql/src/Builder/Contracts/Handler.php | 4 +- .../src/Builder/Contracts/Operator.php | 4 +- .../Builder/Contracts/Scout/FieldResolver.php | 6 +- ...yResolver.php => BuilderFieldResolver.php} | 11 +-- .../Builder/Directives/HandlerDirective.php | 22 ++--- .../Builder/Directives/OperatorDirective.php | 4 +- ...perties.php => ConditionTooManyFields.php} | 14 ++-- packages/graphql/src/Builder/Field.php | 42 ++++++++++ .../graphql/src/Builder/ManipulatorTest.php | 6 +- .../graphql/src/Builder/OperatorsTest.php | 2 +- packages/graphql/src/Builder/Property.php | 42 ++-------- .../src/Builder/Traits/HandlerOperator.php | 10 +-- packages/graphql/src/Provider.php | 6 +- .../src/SearchBy/Directives/Directive.php | 10 +-- .../src/SearchBy/Directives/DirectiveTest.php | 49 +++++------ .../AllowedDirectives.expected.graphql | 8 +- .../CustomComplexOperator.expected.graphql | 8 +- .../DirectiveTest/Example.expected.graphql | 12 +-- .../DirectiveTest/Explicit.expected.graphql | 8 +- .../DirectiveTest/Ignored.expected.graphql | 8 +- .../DirectiveTest/Implicit.expected.graphql | 30 +++---- .../DirectiveTest/Implicit.schema.graphql | 4 +- .../InterfaceUpdate.expected.graphql | 8 +- .../DirectiveTest/Query.expected.graphql | 8 +- .../ScalarOperators.expected.graphql | 4 +- .../DirectiveTest/Scout.expected.graphql | 32 ++++---- .../Scout.expected.v10.3.0.graphql | 32 ++++---- .../TypeRegistry.expected.graphql | 12 +-- .../DirectiveTest/V5Compat.expected.graphql | 6 +- .../V5CompatScout.expected.graphql | 16 ++-- .../SearchBy/Operators/Comparison/Between.php | 10 +-- .../Operators/Comparison/BetweenTest.php | 30 +++---- .../Operators/Comparison/BitwiseAnd.php | 10 +-- .../Operators/Comparison/BitwiseAndTest.php | 30 +++---- .../Operators/Comparison/BitwiseLeftShift.php | 10 +-- .../Comparison/BitwiseLeftShiftTest.php | 30 +++---- .../Operators/Comparison/BitwiseOr.php | 10 +-- .../Operators/Comparison/BitwiseOrTest.php | 30 +++---- .../Comparison/BitwiseRightShift.php | 10 +-- .../Comparison/BitwiseRightShiftTest.php | 30 +++---- .../Operators/Comparison/BitwiseXor.php | 10 +-- .../Operators/Comparison/BitwiseXorTest.php | 30 +++---- .../Operators/Comparison/Contains.php | 10 +-- .../Operators/Comparison/ContainsTest.php | 38 ++++----- .../Operators/Comparison/EndsWithTest.php | 30 +++---- .../SearchBy/Operators/Comparison/Equal.php | 12 +-- .../Operators/Comparison/EqualTest.php | 59 ++++++------- .../Operators/Comparison/GreaterThan.php | 10 +-- .../Comparison/GreaterThanOrEqual.php | 10 +-- .../Comparison/GreaterThanOrEqualTest.php | 30 +++---- .../Operators/Comparison/GreaterThanTest.php | 30 +++---- .../src/SearchBy/Operators/Comparison/In.php | 12 +-- .../SearchBy/Operators/Comparison/InTest.php | 59 ++++++------- .../Operators/Comparison/IsNotNull.php | 8 +- .../Operators/Comparison/IsNotNullTest.php | 30 +++---- .../SearchBy/Operators/Comparison/IsNull.php | 8 +- .../Operators/Comparison/IsNullTest.php | 30 +++---- .../Operators/Comparison/LessThan.php | 10 +-- .../Operators/Comparison/LessThanOrEqual.php | 10 +-- .../Comparison/LessThanOrEqualTest.php | 30 +++---- .../Operators/Comparison/LessThanTest.php | 30 +++---- .../SearchBy/Operators/Comparison/Like.php | 10 +-- .../Operators/Comparison/LikeTest.php | 30 +++---- .../Operators/Comparison/NotBetween.php | 10 +-- .../Operators/Comparison/NotBetweenTest.php | 30 +++---- .../Operators/Comparison/NotContainsTest.php | 38 ++++----- .../Operators/Comparison/NotEndsWithTest.php | 30 +++---- .../Operators/Comparison/NotEqual.php | 10 +-- .../Operators/Comparison/NotEqualTest.php | 30 +++---- .../SearchBy/Operators/Comparison/NotIn.php | 12 +-- .../Operators/Comparison/NotInTest.php | 59 ++++++------- .../SearchBy/Operators/Comparison/NotLike.php | 10 +-- .../Operators/Comparison/NotLikeTest.php | 30 +++---- .../Comparison/NotStartsWithTest.php | 30 +++---- .../Operators/Comparison/StartsWithTest.php | 30 +++---- .../Operators/Complex/Relationship.php | 20 ++--- .../Operators/Complex/RelationshipTest.php | 66 +++++++-------- .../graphql/src/SearchBy/Operators/Field.php | 6 +- .../src/SearchBy/Operators/Logical/AllOf.php | 10 +-- .../SearchBy/Operators/Logical/AllOfTest.php | 82 +++++++++---------- .../SearchBy/Operators/Logical/AnyOfTest.php | 32 ++++---- .../SearchBy/Operators/Logical/Logical.php | 14 ++-- .../SearchBy/Operators/Logical/NotTest.php | 32 ++++---- .../src/SearchBy/Types/Condition/Type.php | 2 +- .../graphql/src/SortBy/Contracts/Sorter.php | 4 +- .../src/SortBy/Directives/DirectiveTest.php | 31 +++---- .../AllowedDirectives.expected.graphql | 8 +- .../DirectiveTest/Example.expected.graphql | 10 +-- .../DirectiveTest/Explicit.expected.graphql | 6 +- .../DirectiveTest/Ignored.expected.graphql | 8 +- .../DirectiveTest/Implicit.expected.graphql | 28 ++++--- .../DirectiveTest/Implicit.schema.graphql | 4 +- .../InterfaceUpdate.expected.graphql | 8 +- .../DirectiveTest/Query.expected.graphql | 8 +- .../DirectiveTest/Scout.expected.graphql | 26 +++--- .../TypeRegistry.expected.graphql | 10 +-- .../DirectiveTest/V5Compat.expected.graphql | 6 +- .../V5CompatScout.expected.graphql | 6 +- .../src/SortBy/Operators/Extra/NullsFirst.php | 10 +-- .../SortBy/Operators/Extra/NullsFirstTest.php | 18 ++-- .../src/SortBy/Operators/Extra/NullsLast.php | 10 +-- .../SortBy/Operators/Extra/NullsLastTest.php | 18 ++-- .../src/SortBy/Operators/Extra/Random.php | 4 +- .../src/SortBy/Operators/Extra/RandomTest.php | 16 ++-- .../graphql/src/SortBy/Operators/Field.php | 10 +-- .../graphql/src/SortBy/Operators/Sort.php | 10 +-- .../graphql/src/SortBy/Operators/SortTest.php | 34 ++++---- .../src/SortBy/Sorters/DatabaseSorter.php | 4 +- .../src/SortBy/Sorters/DatabaseSorterTest.php | 14 ++-- .../src/SortBy/Sorters/EloquentSorter.php | 12 +-- .../src/SortBy/Sorters/EloquentSorterTest.php | 50 +++++------ .../src/SortBy/Sorters/QuerySorter.php | 6 +- .../src/SortBy/Sorters/QuerySorterTest.php | 30 +++---- .../src/SortBy/Sorters/ScoutSorter.php | 10 +-- .../src/SortBy/Sorters/ScoutSorterTest.php | 32 ++++---- .../graphql/src/SortBy/Types/Clause/Type.php | 2 +- .../DirectiveTest~schema-expected.graphql | 8 +- .../DirectiveTest~scout-expected.graphql | 8 +- .../src/Testing/Package/OperatorTests.php | 24 +++--- 123 files changed, 1155 insertions(+), 1131 deletions(-) create mode 100644 packages/graphql/src/Builder/Contracts/BuilderFieldResolver.php delete mode 100644 packages/graphql/src/Builder/Contracts/BuilderPropertyResolver.php rename packages/graphql/src/Builder/Defaults/{BuilderPropertyResolver.php => BuilderFieldResolver.php} (56%) rename packages/graphql/src/Builder/Exceptions/Client/{ConditionTooManyProperties.php => ConditionTooManyFields.php} (53%) create mode 100644 packages/graphql/src/Builder/Field.php 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..35588a50e 100644 --- a/packages/graphql/UPGRADE.md +++ b/packages/graphql/UPGRADE.md @@ -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: @@ -147,19 +147,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..0ce25beec 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); } // diff --git a/packages/graphql/src/Builder/Directives/OperatorDirective.php b/packages/graphql/src/Builder/Directives/OperatorDirective.php index 62cfff346..0e07e5d37 100644 --- a/packages/graphql/src/Builder/Directives/OperatorDirective.php +++ b/packages/graphql/src/Builder/Directives/OperatorDirective.php @@ -3,7 +3,7 @@ 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\Contracts\BuilderFieldResolver; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Operator; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Scope; use Nuwave\Lighthouse\Schema\DirectiveLocator; @@ -15,7 +15,7 @@ abstract class OperatorDirective extends BaseDirective implements Operator { public function __construct( - protected readonly BuilderPropertyResolver $resolver, + protected readonly BuilderFieldResolver $resolver, ) { // empty } diff --git a/packages/graphql/src/Builder/Exceptions/Client/ConditionTooManyProperties.php b/packages/graphql/src/Builder/Exceptions/Client/ConditionTooManyFields.php similarity index 53% rename from packages/graphql/src/Builder/Exceptions/Client/ConditionTooManyProperties.php rename to packages/graphql/src/Builder/Exceptions/Client/ConditionTooManyFields.php index e0348b4ad..40ffab525 100644 --- a/packages/graphql/src/Builder/Exceptions/Client/ConditionTooManyProperties.php +++ b/packages/graphql/src/Builder/Exceptions/Client/ConditionTooManyFields.php @@ -7,24 +7,24 @@ use function implode; use function sprintf; -class ConditionTooManyProperties extends ClientException { +class ConditionTooManyFields extends ClientException { /** - * @param list $properties + * @param list $fields */ public function __construct( - protected array $properties, + protected readonly array $fields, Throwable $previous = null, ) { parent::__construct(sprintf( - 'Only one property allowed, found: `%s`.', - implode('`, `', $this->getProperties()), + 'Only one field allowed, found: `%s`.', + implode('`, `', $this->getFields()), ), $previous); } /** * @return list */ - public function getProperties(): array { - return $this->properties; + public function getFields(): array { + return $this->fields; } } 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/ManipulatorTest.php b/packages/graphql/src/Builder/ManipulatorTest.php index 6efb9437d..8edd3fbd7 100644 --- a/packages/graphql/src/Builder/ManipulatorTest.php +++ b/packages/graphql/src/Builder/ManipulatorTest.php @@ -225,7 +225,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 { @@ -262,7 +262,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 { @@ -299,7 +299,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 { diff --git a/packages/graphql/src/Builder/OperatorsTest.php b/packages/graphql/src/Builder/OperatorsTest.php index d8d00832b..551a7aa9d 100644 --- a/packages/graphql/src/Builder/OperatorsTest.php +++ b/packages/graphql/src/Builder/OperatorsTest.php @@ -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..cfdf7c4f2 100644 --- a/packages/graphql/src/Builder/Traits/HandlerOperator.php +++ b/packages/graphql/src/Builder/Traits/HandlerOperator.php @@ -8,7 +8,7 @@ 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\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\Utils\ArgumentFactory; use Nuwave\Lighthouse\Execution\Arguments\Argument; use Nuwave\Lighthouse\Execution\Arguments\ArgumentSet; @@ -24,11 +24,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,7 +41,7 @@ public function call( private function handle( Handler $handler, object $builder, - Property $property, + Field $field, Argument $argument, Context $context, ): object { @@ -62,6 +62,6 @@ private function handle( } // Apply - return $handler->handle($builder, $property, $argument->value, $context); + return $handler->handle($builder, $field, $argument->value, $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/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..bd41d122f 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,9 @@ 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\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\Field; use LastDragon_ru\LaraASP\GraphQL\Builder\Manipulator; use LastDragon_ru\LaraASP\GraphQL\Builder\Property; use LastDragon_ru\LaraASP\GraphQL\Exceptions\TypeDefinitionUnknown; @@ -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); @@ -980,7 +981,7 @@ public static function dataProviderHandleBuilderV5Compat(): array { ], ], 'too many properties' => [ - new ConditionTooManyProperties(['id', 'value']), + new ConditionTooManyFields(['id', 'value']), [ 'id' => [ 'notEqual' => 1, @@ -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, @@ -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, ], @@ -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 888104223..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 { """ @@ -280,7 +280,7 @@ input SearchByRelationshipChild { } """ -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 fd87cbbe1..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 { """ @@ -233,7 +233,7 @@ input SearchByConditionCommentsQuery { } """ -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 { """ @@ -296,7 +296,7 @@ input SearchByRelationshipUsersQuery { } """ -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 ea829cf4b..ade34c2cd 100644 --- a/packages/graphql/src/SearchBy/Directives/DirectiveTest/Explicit.expected.graphql +++ b/packages/graphql/src/SearchBy/Directives/DirectiveTest/Explicit.expected.graphql @@ -224,7 +224,7 @@ 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 { """ @@ -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 { """ @@ -334,7 +334,7 @@ input SearchByRelationshipB { } """ -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 1b31d7cd2..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 { """ @@ -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 { """ @@ -376,7 +376,7 @@ input SearchByConditionB { } """ -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 { """ @@ -517,7 +517,7 @@ input SearchByRelationshipB { } """ -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/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 cf420715f..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,7 +232,7 @@ 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 { """ @@ -319,7 +319,7 @@ input SearchByRelationshipTestTypeA { } """ -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 86a7ff58a..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 { """ @@ -245,7 +245,7 @@ input SearchByConditionCommentsQuery { } """ -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 { """ 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/Comparison/Between.php b/packages/graphql/src/SearchBy/Operators/Comparison/Between.php index d066c0ad3..d95f24fe4 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; @@ -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..7a7bd237a 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; @@ -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..ec2e777b8 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; @@ -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..63f5c52bd 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; @@ -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..42711d123 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; @@ -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..2467d2d24 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; @@ -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..2b24fc9cb 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; @@ -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/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..b075be439 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; @@ -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..e69c7eead 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; @@ -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..46c803050 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; @@ -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..9ca2077eb 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; @@ -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..6e39bdbe8 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; @@ -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..46fea498c 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; @@ -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..027118ddc 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; @@ -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..dfd7e6d3a 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; @@ -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..86f8162c7 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; @@ -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..6c0d722f5 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; @@ -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/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/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..f5e8f96e6 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; @@ -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..50e83e5e6 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; @@ -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..5088753e9 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; @@ -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/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/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..e24425b82 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); } @@ -72,7 +72,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 +93,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 +105,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 +119,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 +128,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 +145,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..daaa7e10c 100644 --- a/packages/graphql/src/SearchBy/Operators/Complex/RelationshipTest.php +++ b/packages/graphql/src/SearchBy/Operators/Complex/RelationshipTest.php @@ -8,7 +8,7 @@ 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\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 }}' => [ + '{count: { multiple operators }}' => [ new ConditionTooManyOperators(['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/Field.php b/packages/graphql/src/SearchBy/Operators/Field.php index 7de399ab5..f5da78cda 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; @@ -36,10 +36,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..db4ac8fcf 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; @@ -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/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..848e6e910 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; @@ -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/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/Types/Condition/Type.php b/packages/graphql/src/SearchBy/Types/Condition/Type.php index 8c743b722..e741c0e9e 100644 --- a/packages/graphql/src/SearchBy/Types/Condition/Type.php +++ b/packages/graphql/src/SearchBy/Types/Condition/Type.php @@ -49,7 +49,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] diff --git a/packages/graphql/src/SortBy/Contracts/Sorter.php b/packages/graphql/src/SortBy/Contracts/Sorter.php index b241f4a65..9ce5eb100 100644 --- a/packages/graphql/src/SortBy/Contracts/Sorter.php +++ b/packages/graphql/src/SortBy/Contracts/Sorter.php @@ -2,7 +2,7 @@ namespace LastDragon_ru\LaraASP\GraphQL\SortBy\Contracts; -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; @@ -20,5 +20,5 @@ public function isNullsSupported(): bool; * * @return TBuilder */ - 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; } diff --git a/packages/graphql/src/SortBy/Directives/DirectiveTest.php b/packages/graphql/src/SortBy/Directives/DirectiveTest.php index 0e6618722..e729d4c76 100644 --- a/packages/graphql/src/SortBy/Directives/DirectiveTest.php +++ b/packages/graphql/src/SortBy/Directives/DirectiveTest.php @@ -13,11 +13,12 @@ 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\Scout\FieldResolver; +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\TypeDefinitionImpossibleToCreateType; +use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\Builder\Property; use LastDragon_ru\LaraASP\GraphQL\Package; use LastDragon_ru\LaraASP\GraphQL\SortBy\Contracts\Ignored; @@ -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); @@ -779,7 +780,7 @@ public static function dataProviderHandleBuilder(): array { null, ], 'too many fields (operators)' => [ - new ConditionTooManyProperties(['nullsFirst', 'field']), + new ConditionTooManyFields(['nullsFirst', 'field']), [ [ 'field' => [ @@ -1001,7 +1002,7 @@ public static function dataProviderHandleBuilderV5Compat(): array { null, ], 'too many properties' => [ - new ConditionTooManyProperties(['id', 'value']), + new ConditionTooManyFields(['id', 'value']), [ [ 'id' => 'asc', @@ -1328,8 +1329,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' => 'asc', @@ -1496,8 +1497,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..8fc6099d8 100644 --- a/packages/graphql/src/SortBy/Directives/DirectiveTest/Scout.expected.graphql +++ b/packages/graphql/src/SortBy/Directives/DirectiveTest/Scout.expected.graphql @@ -93,7 +93,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 +110,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 +178,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 +246,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 +257,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 +337,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 +405,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 +434,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 +463,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 +492,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 +521,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 +538,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 +618,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/Extra/NullsFirst.php b/packages/graphql/src/SortBy/Operators/Extra/NullsFirst.php index 82b0c27f5..745bf3ccf 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); } @@ -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..9fb3898d4 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); } @@ -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..4fec028ff 100644 --- a/packages/graphql/src/SortBy/Operators/Extra/Random.php +++ b/packages/graphql/src/SortBy/Operators/Extra/Random.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\SortBy\Operators\Operator; use LastDragon_ru\LaraASP\GraphQL\SortBy\Types\Flag; use Nuwave\Lighthouse\Execution\Arguments\Argument; @@ -53,7 +53,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..fbc82204d 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; @@ -24,7 +24,7 @@ public static function getName(): string { #[Override] public function getFieldType(TypeProvider $provider, TypeSource $source, Context $context): string { - return $provider->getType(ClauseType::class, $source, $context); + return $provider->getType(Clause::class, $source, $context); } #[Override] @@ -36,10 +36,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/Sort.php b/packages/graphql/src/SortBy/Operators/Sort.php index 96082d607..0a4b78bfc 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); } @@ -56,7 +56,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 +66,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/Type.php b/packages/graphql/src/SortBy/Types/Clause/Type.php index 70edfe94f..e197f24dd 100644 --- a/packages/graphql/src/SortBy/Types/Clause/Type.php +++ b/packages/graphql/src/SortBy/Types/Clause/Type.php @@ -48,7 +48,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] 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) { From a340a0affc8732ec792e8b6a4702152531529347 Mon Sep 17 00:00:00 2001 From: Aleksei Lebedev <1329824+LastDragon-ru@users.noreply.github.com> Date: Fri, 9 Feb 2024 10:18:22 +0400 Subject: [PATCH 03/15] `HandlerOperator::handle()` will not throw `ConditionTooManyOperators`. --- .../graphql/src/Builder/Traits/HandlerOperator.php | 10 +--------- .../src/SearchBy/Directives/DirectiveTest.php | 13 ++++++------- .../SearchBy/Operators/Complex/RelationshipTest.php | 4 ++-- .../graphql/src/SortBy/Directives/DirectiveTest.php | 5 ++--- 4 files changed, 11 insertions(+), 21 deletions(-) diff --git a/packages/graphql/src/Builder/Traits/HandlerOperator.php b/packages/graphql/src/Builder/Traits/HandlerOperator.php index cfdf7c4f2..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\Field; -use LastDragon_ru\LaraASP\GraphQL\Utils\ArgumentFactory; use Nuwave\Lighthouse\Execution\Arguments\Argument; use Nuwave\Lighthouse\Execution\Arguments\ArgumentSet; use Override; @@ -45,6 +43,7 @@ private function handle( Argument $argument, Context $context, ): object { + // Valid? if (!($argument->value instanceof ArgumentSet)) { throw new HandlerInvalidConditions($handler); } @@ -54,13 +53,6 @@ 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, $field, $argument->value, $context); } diff --git a/packages/graphql/src/SearchBy/Directives/DirectiveTest.php b/packages/graphql/src/SearchBy/Directives/DirectiveTest.php index bd41d122f..70802a677 100644 --- a/packages/graphql/src/SearchBy/Directives/DirectiveTest.php +++ b/packages/graphql/src/SearchBy/Directives/DirectiveTest.php @@ -25,7 +25,6 @@ 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\ConditionTooManyFields; -use LastDragon_ru\LaraASP\GraphQL\Builder\Exceptions\Client\ConditionTooManyOperators; use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\Builder\Manipulator; use LastDragon_ru\LaraASP\GraphQL\Builder\Property; @@ -782,7 +781,7 @@ public static function dataProviderHandleBuilder(): array { ], ], 'too many fields (operators)' => [ - new ConditionTooManyOperators(['equal', 'notEqual']), + new ConditionTooManyFields(['equal', 'notEqual']), [ 'field' => [ 'id' => [ @@ -793,7 +792,7 @@ public static function dataProviderHandleBuilder(): array { ], ], 'too many fields (fields)' => [ - new ConditionTooManyOperators(['id', 'value']), + new ConditionTooManyFields(['id', 'value']), [ 'field' => [ 'id' => [ @@ -992,7 +991,7 @@ public static function dataProviderHandleBuilderV5Compat(): array { ], ], 'too many operators' => [ - new ConditionTooManyOperators(['equal', 'notEqual']), + new ConditionTooManyFields(['equal', 'notEqual']), [ 'id' => [ 'equal' => 1, @@ -1160,7 +1159,7 @@ public static function dataProviderHandleScoutBuilder(): array { null, ], 'too many fields (operators)' => [ - new ConditionTooManyOperators(['equal', 'in']), + new ConditionTooManyFields(['equal', 'in']), [ 'field' => [ 'a' => [ @@ -1173,7 +1172,7 @@ public static function dataProviderHandleScoutBuilder(): array { null, ], 'too many fields (fields)' => [ - new ConditionTooManyOperators(['a', 'b']), + new ConditionTooManyFields(['a', 'b']), [ 'field' => [ 'a' => [ @@ -1383,7 +1382,7 @@ public static function dataProviderHandleScoutBuilderV5Compat(): array { null, ], 'too many operators' => [ - new ConditionTooManyOperators(['equal', 'in']), + new ConditionTooManyFields(['equal', 'in']), [ 'a' => [ 'equal' => 1, diff --git a/packages/graphql/src/SearchBy/Operators/Complex/RelationshipTest.php b/packages/graphql/src/SearchBy/Operators/Complex/RelationshipTest.php index daaa7e10c..653617ce8 100644 --- a/packages/graphql/src/SearchBy/Operators/Complex/RelationshipTest.php +++ b/packages/graphql/src/SearchBy/Operators/Complex/RelationshipTest.php @@ -7,7 +7,7 @@ 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\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; @@ -232,7 +232,7 @@ static function (self $test) use ($graphql): Argument { null, ], '{count: { multiple operators }}' => [ - new ConditionTooManyOperators(['lessThan', 'equal']), + new ConditionTooManyFields(['lessThan', 'equal']), static function (): EloquentBuilder { return User::query(); }, diff --git a/packages/graphql/src/SortBy/Directives/DirectiveTest.php b/packages/graphql/src/SortBy/Directives/DirectiveTest.php index e729d4c76..46a8e68d9 100644 --- a/packages/graphql/src/SortBy/Directives/DirectiveTest.php +++ b/packages/graphql/src/SortBy/Directives/DirectiveTest.php @@ -16,7 +16,6 @@ use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\BuilderFieldResolver; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Scout\FieldResolver; 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\TypeDefinitionImpossibleToCreateType; use LastDragon_ru\LaraASP\GraphQL\Builder\Field; use LastDragon_ru\LaraASP\GraphQL\Builder\Property; @@ -794,7 +793,7 @@ public static function dataProviderHandleBuilder(): array { null, ], 'too many fields (fields)' => [ - new ConditionTooManyOperators(['id', 'value']), + new ConditionTooManyFields(['id', 'value']), [ [ 'field' => [ @@ -1182,7 +1181,7 @@ public static function dataProviderHandleScoutBuilder(): array { null, ], 'too many fields (fields)' => [ - new ConditionTooManyOperators(['a', 'b']), + new ConditionTooManyFields(['a', 'b']), [ [ 'field' => [ From 8571d6421877bdf0eddae99ee8bb93654a343bb2 Mon Sep 17 00:00:00 2001 From: Aleksei Lebedev <1329824+LastDragon-ru@users.noreply.github.com> Date: Fri, 9 Feb 2024 11:32:13 +0400 Subject: [PATCH 04/15] `Manipulator::getOperator()` will check `Operator::isAvailable()` and return `null` if not available. --- .../Builder/Directives/HandlerDirective.php | 5 ++-- packages/graphql/src/Builder/Manipulator.php | 28 +++++++++++++++++-- .../src/SearchBy/Types/Condition/Root.php | 16 +++++------ .../src/SearchBy/Types/Condition/Type.php | 5 ++-- .../graphql/src/SortBy/Types/Clause/Root.php | 16 +++++------ .../graphql/src/SortBy/Types/Clause/Type.php | 4 +-- 6 files changed, 48 insertions(+), 26 deletions(-) diff --git a/packages/graphql/src/Builder/Directives/HandlerDirective.php b/packages/graphql/src/Builder/Directives/HandlerDirective.php index 0ce25beec..7ce8d4f79 100644 --- a/packages/graphql/src/Builder/Directives/HandlerDirective.php +++ b/packages/graphql/src/Builder/Directives/HandlerDirective.php @@ -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(static::getScope(), $operator, $context); - if (!$builder || !$operator->isAvailable($builder, $context)) { + if (!$operator) { return null; } diff --git a/packages/graphql/src/Builder/Manipulator.php b/packages/graphql/src/Builder/Manipulator.php index 11a3cda9f..a5897906f 100644 --- a/packages/graphql/src/Builder/Manipulator.php +++ b/packages/graphql/src/Builder/Manipulator.php @@ -118,10 +118,32 @@ public function addOperators(Operators $operators): static { * @param class-string $scope * @param class-string $operator * - * @return T + * @return T|null */ - public function getOperator(string $scope, string $operator): Operator { - return Container::getInstance()->make($operator); + public function getOperator(string $scope, string $operator, Context $context): ?Operator { + // Builder? + $builder = $context->get(HandlerContextBuilderInfo::class)?->value->getBuilder(); + + if (!$builder) { + return null; + } + + // Provider? + $provider = $this->operators[$scope] ?? null; + + if (!$provider) { + return null; + } + + // Available? + $operator = $provider->getOperator($operator); + + if (!$operator->isAvailable($builder, $context)) { + return null; + } + + // Return + return $operator; } /** diff --git a/packages/graphql/src/SearchBy/Types/Condition/Root.php b/packages/graphql/src/SearchBy/Types/Condition/Root.php index 6add0add8..bf8298977 100644 --- a/packages/graphql/src/SearchBy/Types/Condition/Root.php +++ b/packages/graphql/src/SearchBy/Types/Condition/Root.php @@ -10,8 +10,6 @@ use LastDragon_ru\LaraASP\GraphQL\SearchBy\Definitions\SearchByOperatorFieldDirective; use Override; -use function array_merge; - class Root extends Type { /** * @inheritDoc @@ -22,12 +20,14 @@ protected function getOperators( InterfaceSource|InputSource|ObjectSource $source, Context $context, ): array { - return array_merge( - parent::getOperators($manipulator, $source, $context), - [ - $manipulator->getOperator($this->getScope(), SearchByOperatorFieldDirective::class), - ], - ); + $operators = parent::getOperators($manipulator, $source, $context); + $operator = $manipulator->getOperator($this->getScope(), SearchByOperatorFieldDirective::class, $context); + + if ($operator) { + $operators[] = $operator; + } + + return $operators; } /** diff --git a/packages/graphql/src/SearchBy/Types/Condition/Type.php b/packages/graphql/src/SearchBy/Types/Condition/Type.php index e741c0e9e..83774f2c1 100644 --- a/packages/graphql/src/SearchBy/Types/Condition/Type.php +++ b/packages/graphql/src/SearchBy/Types/Condition/Type.php @@ -91,8 +91,9 @@ protected function getFieldOperator( 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]; + $operator = SearchByOperatorConditionDirective::class; + $operator = $manipulator->getOperator($this->getScope(), $operator, $context); + $operator = $operator ? [$operator, $source] : null; } return $operator; diff --git a/packages/graphql/src/SortBy/Types/Clause/Root.php b/packages/graphql/src/SortBy/Types/Clause/Root.php index 692fed6aa..9741803d7 100644 --- a/packages/graphql/src/SortBy/Types/Clause/Root.php +++ b/packages/graphql/src/SortBy/Types/Clause/Root.php @@ -10,8 +10,6 @@ use LastDragon_ru\LaraASP\GraphQL\SortBy\Definitions\SortByOperatorFieldDirective; use Override; -use function array_merge; - class Root extends Type { /** * @inheritDoc @@ -22,12 +20,14 @@ protected function getOperators( InterfaceSource|InputSource|ObjectSource $source, Context $context, ): array { - return array_merge( - parent::getOperators($manipulator, $source, $context), - [ - $manipulator->getOperator($this->getScope(), SortByOperatorFieldDirective::class), - ], - ); + $operators = parent::getOperators($manipulator, $source, $context); + $operator = $manipulator->getOperator($this->getScope(), SortByOperatorFieldDirective::class, $context); + + if ($operator) { + $operators[] = $operator; + } + + return $operators; } /** diff --git a/packages/graphql/src/SortBy/Types/Clause/Type.php b/packages/graphql/src/SortBy/Types/Clause/Type.php index e197f24dd..55b4a43ef 100644 --- a/packages/graphql/src/SortBy/Types/Clause/Type.php +++ b/packages/graphql/src/SortBy/Types/Clause/Type.php @@ -109,8 +109,8 @@ protected function getFieldOperator( 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]; + $operator = $manipulator->getOperator($this->getScope(), SortByOperatorSortDirective::class, $context); + $operator = $operator ? [$operator, $source] : null; } else { // empty } From 560a75453717591c2f21353be7dbd62a91111d8d Mon Sep 17 00:00:00 2001 From: Aleksei Lebedev <1329824+LastDragon-ru@users.noreply.github.com> Date: Fri, 9 Feb 2024 14:19:52 +0400 Subject: [PATCH 05/15] `Operator::getFieldType()` can return `null`. --- .../src/Builder/Contracts/Operator.php | 2 +- .../Builder/Directives/HandlerDirective.php | 2 +- .../OperatorImpossibleToCreateField.php | 40 +++++++++++++++++++ packages/graphql/src/Builder/Manipulator.php | 9 ++++- .../graphql/src/Builder/ManipulatorTest.php | 6 +-- .../graphql/src/Builder/OperatorsTest.php | 2 +- .../src/SearchBy/Directives/DirectiveTest.php | 2 +- .../graphql/src/SearchBy/Operators/Child.php | 2 +- .../SearchBy/Operators/Comparison/Between.php | 2 +- .../src/SearchBy/Operators/Comparison/In.php | 2 +- .../Operators/Comparison/IsNotNull.php | 2 +- .../SearchBy/Operators/Comparison/IsNull.php | 2 +- .../SearchBy/Operators/Comparison/NotIn.php | 2 +- .../Operators/Complex/Relationship.php | 2 +- .../graphql/src/SearchBy/Operators/Field.php | 2 +- .../src/SearchBy/Operators/Logical/AllOf.php | 4 +- .../src/SearchBy/Operators/Logical/AnyOf.php | 4 +- .../SearchBy/Operators/Logical/Logical.php | 2 +- .../src/SearchBy/Operators/Operator.php | 2 +- .../graphql/src/SearchBy/Operators/Root.php | 2 +- .../graphql/src/SortBy/Operators/Child.php | 2 +- .../src/SortBy/Operators/Extra/NullsFirst.php | 2 +- .../src/SortBy/Operators/Extra/NullsLast.php | 2 +- .../src/SortBy/Operators/Extra/Random.php | 2 +- .../graphql/src/SortBy/Operators/Field.php | 2 +- .../graphql/src/SortBy/Operators/Root.php | 2 +- .../graphql/src/SortBy/Operators/Sort.php | 2 +- 27 files changed, 77 insertions(+), 30 deletions(-) create mode 100644 packages/graphql/src/Builder/Exceptions/OperatorImpossibleToCreateField.php diff --git a/packages/graphql/src/Builder/Contracts/Operator.php b/packages/graphql/src/Builder/Contracts/Operator.php index d36ac985a..46f70f709 100644 --- a/packages/graphql/src/Builder/Contracts/Operator.php +++ b/packages/graphql/src/Builder/Contracts/Operator.php @@ -13,7 +13,7 @@ interface Operator extends Directive { */ public static function getName(): string; - public function getFieldType(TypeProvider $provider, TypeSource $source, Context $context): string; + public function getFieldType(TypeProvider $provider, TypeSource $source, Context $context): ?string; public function getFieldDescription(): string; diff --git a/packages/graphql/src/Builder/Directives/HandlerDirective.php b/packages/graphql/src/Builder/Directives/HandlerDirective.php index 7ce8d4f79..10d12e512 100644 --- a/packages/graphql/src/Builder/Directives/HandlerDirective.php +++ b/packages/graphql/src/Builder/Directives/HandlerDirective.php @@ -276,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/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/Manipulator.php b/packages/graphql/src/Builder/Manipulator.php index a5897906f..53e813f25 100644 --- a/packages/graphql/src/Builder/Manipulator.php +++ b/packages/graphql/src/Builder/Manipulator.php @@ -27,6 +27,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; @@ -250,8 +251,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", diff --git a/packages/graphql/src/Builder/ManipulatorTest.php b/packages/graphql/src/Builder/ManipulatorTest.php index 8edd3fbd7..c5e862550 100644 --- a/packages/graphql/src/Builder/ManipulatorTest.php +++ b/packages/graphql/src/Builder/ManipulatorTest.php @@ -207,7 +207,7 @@ 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(); } @@ -244,7 +244,7 @@ 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(); } @@ -281,7 +281,7 @@ 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(); } diff --git a/packages/graphql/src/Builder/OperatorsTest.php b/packages/graphql/src/Builder/OperatorsTest.php index 551a7aa9d..51e85156a 100644 --- a/packages/graphql/src/Builder/OperatorsTest.php +++ b/packages/graphql/src/Builder/OperatorsTest.php @@ -169,7 +169,7 @@ 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 { throw new Exception('Should not be called'); } diff --git a/packages/graphql/src/SearchBy/Directives/DirectiveTest.php b/packages/graphql/src/SearchBy/Directives/DirectiveTest.php index 70802a677..e84d0d65d 100644 --- a/packages/graphql/src/SearchBy/Directives/DirectiveTest.php +++ b/packages/graphql/src/SearchBy/Directives/DirectiveTest.php @@ -1561,7 +1561,7 @@ public function getFieldType( TypeProvider $provider, TypeSource $source, Context $context, - ): string { + ): ?string { return $provider->getType(static::class, $provider->getTypeSource(Type::int()), $context); } diff --git a/packages/graphql/src/SearchBy/Operators/Child.php b/packages/graphql/src/SearchBy/Operators/Child.php index facb33fca..768e0cecd 100644 --- a/packages/graphql/src/SearchBy/Operators/Child.php +++ b/packages/graphql/src/SearchBy/Operators/Child.php @@ -21,7 +21,7 @@ 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(Root::class, $source, $context); } diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/Between.php b/packages/graphql/src/SearchBy/Operators/Comparison/Between.php index d95f24fe4..0e2e26681 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/Between.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/Between.php @@ -28,7 +28,7 @@ public function getFieldDescription(): 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(Range::class, $source, $context); } diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/In.php b/packages/graphql/src/SearchBy/Operators/Comparison/In.php index 9ca2077eb..7ad65d406 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/In.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/In.php @@ -30,7 +30,7 @@ public function getFieldDescription(): string { } #[Override] - public function getFieldType(TypeProvider $provider, TypeSource $source, Context $context): string { + public function getFieldType(TypeProvider $provider, TypeSource $source, Context $context): ?string { return "[{$source->getTypeName()}!]"; } diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/IsNotNull.php b/packages/graphql/src/SearchBy/Operators/Comparison/IsNotNull.php index 6e39bdbe8..bed3f88a3 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/IsNotNull.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/IsNotNull.php @@ -30,7 +30,7 @@ public function getFieldDescription(): 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(Flag::class, $source, $context); } diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/IsNull.php b/packages/graphql/src/SearchBy/Operators/Comparison/IsNull.php index 46fea498c..0d122d673 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/IsNull.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/IsNull.php @@ -30,7 +30,7 @@ public function getFieldDescription(): 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(Flag::class, $source, $context); } diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/NotIn.php b/packages/graphql/src/SearchBy/Operators/Comparison/NotIn.php index 50e83e5e6..bd5f36335 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/NotIn.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/NotIn.php @@ -30,7 +30,7 @@ public function getFieldDescription(): string { } #[Override] - public function getFieldType(TypeProvider $provider, TypeSource $source, Context $context): string { + public function getFieldType(TypeProvider $provider, TypeSource $source, Context $context): ?string { return "[{$source->getTypeName()}!]"; } diff --git a/packages/graphql/src/SearchBy/Operators/Complex/Relationship.php b/packages/graphql/src/SearchBy/Operators/Complex/Relationship.php index e24425b82..48d84ed47 100644 --- a/packages/graphql/src/SearchBy/Operators/Complex/Relationship.php +++ b/packages/graphql/src/SearchBy/Operators/Complex/Relationship.php @@ -54,7 +54,7 @@ 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(RelationshipType::class, $source, $context); } diff --git a/packages/graphql/src/SearchBy/Operators/Field.php b/packages/graphql/src/SearchBy/Operators/Field.php index f5da78cda..ef9645b49 100644 --- a/packages/graphql/src/SearchBy/Operators/Field.php +++ b/packages/graphql/src/SearchBy/Operators/Field.php @@ -23,7 +23,7 @@ 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(Condition::class, $source, $context); } diff --git a/packages/graphql/src/SearchBy/Operators/Logical/AllOf.php b/packages/graphql/src/SearchBy/Operators/Logical/AllOf.php index db4ac8fcf..26912bda8 100644 --- a/packages/graphql/src/SearchBy/Operators/Logical/AllOf.php +++ b/packages/graphql/src/SearchBy/Operators/Logical/AllOf.php @@ -29,9 +29,9 @@ public function getFieldDescription(): string { } #[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/AnyOf.php b/packages/graphql/src/SearchBy/Operators/Logical/AnyOf.php index 184fcf061..7a0ffc8bd 100644 --- a/packages/graphql/src/SearchBy/Operators/Logical/AnyOf.php +++ b/packages/graphql/src/SearchBy/Operators/Logical/AnyOf.php @@ -22,9 +22,9 @@ public function getFieldDescription(): string { } #[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/Logical.php b/packages/graphql/src/SearchBy/Operators/Logical/Logical.php index 848e6e910..a8f6c53e4 100644 --- a/packages/graphql/src/SearchBy/Operators/Logical/Logical.php +++ b/packages/graphql/src/SearchBy/Operators/Logical/Logical.php @@ -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); } diff --git a/packages/graphql/src/SearchBy/Operators/Operator.php b/packages/graphql/src/SearchBy/Operators/Operator.php index 2efe9451d..a54083787 100644 --- a/packages/graphql/src/SearchBy/Operators/Operator.php +++ b/packages/graphql/src/SearchBy/Operators/Operator.php @@ -15,7 +15,7 @@ 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(); } diff --git a/packages/graphql/src/SearchBy/Operators/Root.php b/packages/graphql/src/SearchBy/Operators/Root.php index 8f7a45704..bfa069319 100644 --- a/packages/graphql/src/SearchBy/Operators/Root.php +++ b/packages/graphql/src/SearchBy/Operators/Root.php @@ -20,7 +20,7 @@ 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); } diff --git a/packages/graphql/src/SortBy/Operators/Child.php b/packages/graphql/src/SortBy/Operators/Child.php index ef13277c3..0a778348d 100644 --- a/packages/graphql/src/SortBy/Operators/Child.php +++ b/packages/graphql/src/SortBy/Operators/Child.php @@ -22,7 +22,7 @@ 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(ClauseType::class, $source, $context); } diff --git a/packages/graphql/src/SortBy/Operators/Extra/NullsFirst.php b/packages/graphql/src/SortBy/Operators/Extra/NullsFirst.php index 745bf3ccf..40066e682 100644 --- a/packages/graphql/src/SortBy/Operators/Extra/NullsFirst.php +++ b/packages/graphql/src/SortBy/Operators/Extra/NullsFirst.php @@ -36,7 +36,7 @@ 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); } diff --git a/packages/graphql/src/SortBy/Operators/Extra/NullsLast.php b/packages/graphql/src/SortBy/Operators/Extra/NullsLast.php index 9fb3898d4..2bd0ddec0 100644 --- a/packages/graphql/src/SortBy/Operators/Extra/NullsLast.php +++ b/packages/graphql/src/SortBy/Operators/Extra/NullsLast.php @@ -36,7 +36,7 @@ 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); } diff --git a/packages/graphql/src/SortBy/Operators/Extra/Random.php b/packages/graphql/src/SortBy/Operators/Extra/Random.php index 4fec028ff..73e6b07be 100644 --- a/packages/graphql/src/SortBy/Operators/Extra/Random.php +++ b/packages/graphql/src/SortBy/Operators/Extra/Random.php @@ -45,7 +45,7 @@ public function getFieldDescription(): 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(Flag::class, $source, $context); } diff --git a/packages/graphql/src/SortBy/Operators/Field.php b/packages/graphql/src/SortBy/Operators/Field.php index fbc82204d..5127c4641 100644 --- a/packages/graphql/src/SortBy/Operators/Field.php +++ b/packages/graphql/src/SortBy/Operators/Field.php @@ -23,7 +23,7 @@ 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); } diff --git a/packages/graphql/src/SortBy/Operators/Root.php b/packages/graphql/src/SortBy/Operators/Root.php index a127a1f4c..2e78c3704 100644 --- a/packages/graphql/src/SortBy/Operators/Root.php +++ b/packages/graphql/src/SortBy/Operators/Root.php @@ -20,7 +20,7 @@ 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).'!]'; } diff --git a/packages/graphql/src/SortBy/Operators/Sort.php b/packages/graphql/src/SortBy/Operators/Sort.php index 0a4b78bfc..d8baa410c 100644 --- a/packages/graphql/src/SortBy/Operators/Sort.php +++ b/packages/graphql/src/SortBy/Operators/Sort.php @@ -38,7 +38,7 @@ 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(DirectionType::class, $source, $context); } From 182f8d2257d6b19deb1f90a0ab2266e5878d667b Mon Sep 17 00:00:00 2001 From: Aleksei Lebedev <1329824+LastDragon-ru@users.noreply.github.com> Date: Fri, 9 Feb 2024 14:25:23 +0400 Subject: [PATCH 06/15] `Operator::getFieldDescription()` can return `null`. --- packages/graphql/src/Builder/Contracts/Operator.php | 2 +- packages/graphql/src/Builder/Manipulator.php | 2 +- packages/graphql/src/Builder/ManipulatorTest.php | 6 +++--- packages/graphql/src/Builder/OperatorsTest.php | 2 +- packages/graphql/src/SearchBy/Directives/DirectiveTest.php | 2 +- packages/graphql/src/SearchBy/Operators/Child.php | 2 +- .../graphql/src/SearchBy/Operators/Comparison/Between.php | 2 +- .../src/SearchBy/Operators/Comparison/BitwiseAnd.php | 2 +- .../src/SearchBy/Operators/Comparison/BitwiseLeftShift.php | 2 +- .../graphql/src/SearchBy/Operators/Comparison/BitwiseOr.php | 2 +- .../src/SearchBy/Operators/Comparison/BitwiseRightShift.php | 2 +- .../src/SearchBy/Operators/Comparison/BitwiseXor.php | 2 +- .../graphql/src/SearchBy/Operators/Comparison/Contains.php | 2 +- .../graphql/src/SearchBy/Operators/Comparison/EndsWith.php | 2 +- .../graphql/src/SearchBy/Operators/Comparison/Equal.php | 2 +- .../src/SearchBy/Operators/Comparison/GreaterThan.php | 2 +- .../SearchBy/Operators/Comparison/GreaterThanOrEqual.php | 2 +- packages/graphql/src/SearchBy/Operators/Comparison/In.php | 2 +- .../graphql/src/SearchBy/Operators/Comparison/IsNotNull.php | 2 +- .../graphql/src/SearchBy/Operators/Comparison/IsNull.php | 2 +- .../graphql/src/SearchBy/Operators/Comparison/LessThan.php | 2 +- .../src/SearchBy/Operators/Comparison/LessThanOrEqual.php | 2 +- packages/graphql/src/SearchBy/Operators/Comparison/Like.php | 2 +- .../src/SearchBy/Operators/Comparison/NotBetween.php | 2 +- .../src/SearchBy/Operators/Comparison/NotContains.php | 2 +- .../src/SearchBy/Operators/Comparison/NotEndsWith.php | 2 +- .../graphql/src/SearchBy/Operators/Comparison/NotEqual.php | 2 +- .../graphql/src/SearchBy/Operators/Comparison/NotIn.php | 2 +- .../graphql/src/SearchBy/Operators/Comparison/NotLike.php | 2 +- .../src/SearchBy/Operators/Comparison/NotStartsWith.php | 2 +- .../src/SearchBy/Operators/Comparison/StartsWith.php | 2 +- .../graphql/src/SearchBy/Operators/Complex/Relationship.php | 2 +- packages/graphql/src/SearchBy/Operators/Condition.php | 2 +- packages/graphql/src/SearchBy/Operators/Field.php | 2 +- packages/graphql/src/SearchBy/Operators/Logical/AllOf.php | 2 +- packages/graphql/src/SearchBy/Operators/Logical/AnyOf.php | 2 +- packages/graphql/src/SearchBy/Operators/Logical/Not.php | 2 +- packages/graphql/src/SearchBy/Operators/Root.php | 2 +- packages/graphql/src/SortBy/Operators/Child.php | 2 +- packages/graphql/src/SortBy/Operators/Extra/NullsFirst.php | 2 +- packages/graphql/src/SortBy/Operators/Extra/NullsLast.php | 2 +- packages/graphql/src/SortBy/Operators/Extra/Random.php | 2 +- packages/graphql/src/SortBy/Operators/Field.php | 2 +- packages/graphql/src/SortBy/Operators/Root.php | 2 +- packages/graphql/src/SortBy/Operators/Sort.php | 2 +- 45 files changed, 47 insertions(+), 47 deletions(-) diff --git a/packages/graphql/src/Builder/Contracts/Operator.php b/packages/graphql/src/Builder/Contracts/Operator.php index 46f70f709..3991712de 100644 --- a/packages/graphql/src/Builder/Contracts/Operator.php +++ b/packages/graphql/src/Builder/Contracts/Operator.php @@ -15,7 +15,7 @@ public static function getName(): string; public function getFieldType(TypeProvider $provider, TypeSource $source, Context $context): ?string; - public function getFieldDescription(): string; + public function getFieldDescription(): ?string; /** * @param class-string $builder diff --git a/packages/graphql/src/Builder/Manipulator.php b/packages/graphql/src/Builder/Manipulator.php index 53e813f25..fc4af83c3 100644 --- a/packages/graphql/src/Builder/Manipulator.php +++ b/packages/graphql/src/Builder/Manipulator.php @@ -268,7 +268,7 @@ public function getOperatorField( ), ); $description = $description ?: $operator->getFieldDescription(); - $description = BlockString::print($description); + $description = BlockString::print((string) $description); return <<>`).'; } diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/BitwiseXor.php b/packages/graphql/src/SearchBy/Operators/Comparison/BitwiseXor.php index 2467d2d24..c4d56f659 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/BitwiseXor.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/BitwiseXor.php @@ -19,7 +19,7 @@ public static function getName(): string { } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Bitwise XOR (`^`).'; } diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/Contains.php b/packages/graphql/src/SearchBy/Operators/Comparison/Contains.php index 2b24fc9cb..f4131bceb 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/Contains.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/Contains.php @@ -24,7 +24,7 @@ public static function getName(): string { } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Contains.'; } 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/Equal.php b/packages/graphql/src/SearchBy/Operators/Comparison/Equal.php index b075be439..b29f098b7 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/Equal.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/Equal.php @@ -23,7 +23,7 @@ public static function getName(): string { } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Equal (`=`).'; } diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/GreaterThan.php b/packages/graphql/src/SearchBy/Operators/Comparison/GreaterThan.php index e69c7eead..6bb2a825d 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/GreaterThan.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/GreaterThan.php @@ -19,7 +19,7 @@ public static function getName(): string { } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Greater than (`>`).'; } diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/GreaterThanOrEqual.php b/packages/graphql/src/SearchBy/Operators/Comparison/GreaterThanOrEqual.php index 46c803050..48cd90ba0 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/GreaterThanOrEqual.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/GreaterThanOrEqual.php @@ -19,7 +19,7 @@ public static function getName(): string { } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Greater than or equal to (`>=`).'; } diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/In.php b/packages/graphql/src/SearchBy/Operators/Comparison/In.php index 7ad65d406..45fde623e 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/In.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/In.php @@ -25,7 +25,7 @@ public static function getName(): string { } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Within a set of values.'; } diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/IsNotNull.php b/packages/graphql/src/SearchBy/Operators/Comparison/IsNotNull.php index bed3f88a3..30f53d6a7 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/IsNotNull.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/IsNotNull.php @@ -25,7 +25,7 @@ public static function getName(): string { } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Is NOT NULL?'; } diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/IsNull.php b/packages/graphql/src/SearchBy/Operators/Comparison/IsNull.php index 0d122d673..383da73ea 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/IsNull.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/IsNull.php @@ -25,7 +25,7 @@ public static function getName(): string { } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Is NULL?'; } diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/LessThan.php b/packages/graphql/src/SearchBy/Operators/Comparison/LessThan.php index 027118ddc..38a8e3f59 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/LessThan.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/LessThan.php @@ -19,7 +19,7 @@ public static function getName(): string { } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Less than (`<`).'; } diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/LessThanOrEqual.php b/packages/graphql/src/SearchBy/Operators/Comparison/LessThanOrEqual.php index dfd7e6d3a..bad619a8a 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/LessThanOrEqual.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/LessThanOrEqual.php @@ -19,7 +19,7 @@ public static function getName(): string { } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Less than or equal to (`<=`).'; } diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/Like.php b/packages/graphql/src/SearchBy/Operators/Comparison/Like.php index 86f8162c7..c2086fba7 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/Like.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/Like.php @@ -20,7 +20,7 @@ public static function getName(): string { } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Like.'; } diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/NotBetween.php b/packages/graphql/src/SearchBy/Operators/Comparison/NotBetween.php index 6c0d722f5..38c7f2d98 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/NotBetween.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/NotBetween.php @@ -19,7 +19,7 @@ public static function getName(): string { } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Outside a range.'; } 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/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/NotEqual.php b/packages/graphql/src/SearchBy/Operators/Comparison/NotEqual.php index f5e8f96e6..15fcda3f5 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/NotEqual.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/NotEqual.php @@ -19,7 +19,7 @@ public static function getName(): string { } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Not Equal (`!=`).'; } diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/NotIn.php b/packages/graphql/src/SearchBy/Operators/Comparison/NotIn.php index bd5f36335..6db8a425f 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/NotIn.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/NotIn.php @@ -25,7 +25,7 @@ public static function getName(): string { } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Outside a set of values.'; } diff --git a/packages/graphql/src/SearchBy/Operators/Comparison/NotLike.php b/packages/graphql/src/SearchBy/Operators/Comparison/NotLike.php index 5088753e9..168ac3201 100644 --- a/packages/graphql/src/SearchBy/Operators/Comparison/NotLike.php +++ b/packages/graphql/src/SearchBy/Operators/Comparison/NotLike.php @@ -20,7 +20,7 @@ public static function getName(): string { } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Not like.'; } 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/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/Complex/Relationship.php b/packages/graphql/src/SearchBy/Operators/Complex/Relationship.php index 48d84ed47..27e33f9d0 100644 --- a/packages/graphql/src/SearchBy/Operators/Complex/Relationship.php +++ b/packages/graphql/src/SearchBy/Operators/Complex/Relationship.php @@ -59,7 +59,7 @@ public function getFieldType(TypeProvider $provider, TypeSource $source, Context } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Relationship condition.'; } diff --git a/packages/graphql/src/SearchBy/Operators/Condition.php b/packages/graphql/src/SearchBy/Operators/Condition.php index 15a4995e5..bd790904a 100644 --- a/packages/graphql/src/SearchBy/Operators/Condition.php +++ b/packages/graphql/src/SearchBy/Operators/Condition.php @@ -16,7 +16,7 @@ public static function getName(): string { } #[Override] - public function getFieldDescription(): string { + 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 ef9645b49..5ea45f462 100644 --- a/packages/graphql/src/SearchBy/Operators/Field.php +++ b/packages/graphql/src/SearchBy/Operators/Field.php @@ -28,7 +28,7 @@ public function getFieldType(TypeProvider $provider, TypeSource $source, Context } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Field.'; } diff --git a/packages/graphql/src/SearchBy/Operators/Logical/AllOf.php b/packages/graphql/src/SearchBy/Operators/Logical/AllOf.php index 26912bda8..5dccf66b6 100644 --- a/packages/graphql/src/SearchBy/Operators/Logical/AllOf.php +++ b/packages/graphql/src/SearchBy/Operators/Logical/AllOf.php @@ -24,7 +24,7 @@ public static function getName(): string { } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'All of the conditions must be true.'; } diff --git a/packages/graphql/src/SearchBy/Operators/Logical/AnyOf.php b/packages/graphql/src/SearchBy/Operators/Logical/AnyOf.php index 7a0ffc8bd..2242b1ad9 100644 --- a/packages/graphql/src/SearchBy/Operators/Logical/AnyOf.php +++ b/packages/graphql/src/SearchBy/Operators/Logical/AnyOf.php @@ -17,7 +17,7 @@ public static function getName(): string { } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Any of the conditions must be true.'; } 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/Root.php b/packages/graphql/src/SearchBy/Operators/Root.php index bfa069319..8afc656f4 100644 --- a/packages/graphql/src/SearchBy/Operators/Root.php +++ b/packages/graphql/src/SearchBy/Operators/Root.php @@ -25,7 +25,7 @@ public function getFieldType(TypeProvider $provider, TypeSource $source, Context } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Directive root.'; } } diff --git a/packages/graphql/src/SortBy/Operators/Child.php b/packages/graphql/src/SortBy/Operators/Child.php index 0a778348d..f8e319186 100644 --- a/packages/graphql/src/SortBy/Operators/Child.php +++ b/packages/graphql/src/SortBy/Operators/Child.php @@ -27,7 +27,7 @@ public function getFieldType(TypeProvider $provider, TypeSource $source, Context } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Field clause.'; } diff --git a/packages/graphql/src/SortBy/Operators/Extra/NullsFirst.php b/packages/graphql/src/SortBy/Operators/Extra/NullsFirst.php index 40066e682..5595aa748 100644 --- a/packages/graphql/src/SortBy/Operators/Extra/NullsFirst.php +++ b/packages/graphql/src/SortBy/Operators/Extra/NullsFirst.php @@ -41,7 +41,7 @@ public function getFieldType(TypeProvider $provider, TypeSource $source, Context } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'NULLs first'; } diff --git a/packages/graphql/src/SortBy/Operators/Extra/NullsLast.php b/packages/graphql/src/SortBy/Operators/Extra/NullsLast.php index 2bd0ddec0..94b1d3fc0 100644 --- a/packages/graphql/src/SortBy/Operators/Extra/NullsLast.php +++ b/packages/graphql/src/SortBy/Operators/Extra/NullsLast.php @@ -41,7 +41,7 @@ public function getFieldType(TypeProvider $provider, TypeSource $source, Context } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'NULLs last'; } diff --git a/packages/graphql/src/SortBy/Operators/Extra/Random.php b/packages/graphql/src/SortBy/Operators/Extra/Random.php index 73e6b07be..5af2f19e1 100644 --- a/packages/graphql/src/SortBy/Operators/Extra/Random.php +++ b/packages/graphql/src/SortBy/Operators/Extra/Random.php @@ -40,7 +40,7 @@ public static function getName(): string { } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'By random'; } diff --git a/packages/graphql/src/SortBy/Operators/Field.php b/packages/graphql/src/SortBy/Operators/Field.php index 5127c4641..255098d31 100644 --- a/packages/graphql/src/SortBy/Operators/Field.php +++ b/packages/graphql/src/SortBy/Operators/Field.php @@ -28,7 +28,7 @@ public function getFieldType(TypeProvider $provider, TypeSource $source, Context } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Field.'; } diff --git a/packages/graphql/src/SortBy/Operators/Root.php b/packages/graphql/src/SortBy/Operators/Root.php index 2e78c3704..9427cc6b2 100644 --- a/packages/graphql/src/SortBy/Operators/Root.php +++ b/packages/graphql/src/SortBy/Operators/Root.php @@ -25,7 +25,7 @@ public function getFieldType(TypeProvider $provider, TypeSource $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 d8baa410c..635ef2f16 100644 --- a/packages/graphql/src/SortBy/Operators/Sort.php +++ b/packages/graphql/src/SortBy/Operators/Sort.php @@ -43,7 +43,7 @@ public function getFieldType(TypeProvider $provider, TypeSource $source, Context } #[Override] - public function getFieldDescription(): string { + public function getFieldDescription(): ?string { return 'Field clause.'; } From 8faa2023c21e9dd404f17efe582797c3c5cdb974 Mon Sep 17 00:00:00 2001 From: Aleksei Lebedev <1329824+LastDragon-ru@users.noreply.github.com> Date: Sat, 10 Feb 2024 09:47:16 +0400 Subject: [PATCH 07/15] `Operator::isAvailable()` arguments update (will be the same as `Operator::getFieldType()`). --- .../src/Builder/Contracts/Operator.php | 7 ++-- .../Builder/Directives/HandlerDirective.php | 2 +- .../Builder/Directives/OperatorDirective.php | 22 ++++++++++++ packages/graphql/src/Builder/Manipulator.php | 35 +++++++------------ .../graphql/src/Builder/ManipulatorTest.php | 29 ++++++++++----- .../graphql/src/Builder/OperatorsTest.php | 6 ++-- .../src/Builder/Traits/WithScoutSupport.php | 9 +++-- .../graphql/src/Builder/Types/InputObject.php | 25 +++---------- .../graphql/src/SearchBy/Operators/Child.php | 2 +- .../Operators/Complex/Relationship.php | 2 +- .../src/SearchBy/Operators/Operator.php | 2 +- .../src/SearchBy/Types/Condition/Root.php | 7 +++- .../src/SearchBy/Types/Condition/Type.php | 2 +- .../src/SearchBy/Types/Enumeration.php | 4 +-- .../graphql/src/SearchBy/Types/Scalar.php | 2 +- .../graphql/src/SortBy/Operators/Child.php | 2 +- .../src/SortBy/Operators/Extra/NullsFirst.php | 2 +- .../src/SortBy/Operators/Extra/NullsLast.php | 2 +- .../graphql/src/SortBy/Operators/Operator.php | 3 +- .../graphql/src/SortBy/Operators/Sort.php | 2 +- .../graphql/src/SortBy/Types/Clause/Root.php | 7 +++- .../graphql/src/SortBy/Types/Clause/Type.php | 7 +++- 22 files changed, 100 insertions(+), 81 deletions(-) diff --git a/packages/graphql/src/Builder/Contracts/Operator.php b/packages/graphql/src/Builder/Contracts/Operator.php index 3991712de..73f85db17 100644 --- a/packages/graphql/src/Builder/Contracts/Operator.php +++ b/packages/graphql/src/Builder/Contracts/Operator.php @@ -13,15 +13,12 @@ interface Operator extends Directive { */ public static function getName(): string; + public function isAvailable(TypeProvider $provider, TypeSource $source, Context $context): bool; + public function getFieldType(TypeProvider $provider, TypeSource $source, Context $context): ?string; public function getFieldDescription(): ?string; - /** - * @param class-string $builder - */ - public function isAvailable(string $builder, Context $context): bool; - /** * @template TBuilder of object * diff --git a/packages/graphql/src/Builder/Directives/HandlerDirective.php b/packages/graphql/src/Builder/Directives/HandlerDirective.php index 10d12e512..b319c41fd 100644 --- a/packages/graphql/src/Builder/Directives/HandlerDirective.php +++ b/packages/graphql/src/Builder/Directives/HandlerDirective.php @@ -264,7 +264,7 @@ protected function getArgumentTypeDefinitionNode( string $operator, ): ListTypeNode|NamedTypeNode|NonNullTypeNode|null { // Supported? - $operator = $manipulator->getOperator(static::getScope(), $operator, $context); + $operator = $manipulator->getOperator($operator, static::getScope(), $argument, $context); if (!$operator) { return null; diff --git a/packages/graphql/src/Builder/Directives/OperatorDirective.php b/packages/graphql/src/Builder/Directives/OperatorDirective.php index 0e07e5d37..f49e0e0d5 100644 --- a/packages/graphql/src/Builder/Directives/OperatorDirective.php +++ b/packages/graphql/src/Builder/Directives/OperatorDirective.php @@ -3,9 +3,13 @@ namespace LastDragon_ru\LaraASP\GraphQL\Builder\Directives; use GraphQL\Language\DirectiveLocation; +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; @@ -45,4 +49,22 @@ protected static function getDirectiveLocations(): array { return $locations; } + + #[Override] + public function isAvailable(TypeProvider $provider, TypeSource $source, Context $context): bool { + // Builder? + $builder = $context->get(HandlerContextBuilderInfo::class)?->value->getBuilder(); + + if (!$builder || !$this->isBuilderSupported($builder)) { + return false; + } + + // Ok + return true; + } + + /** + * @param class-string $builder + */ + abstract protected function isBuilderSupported(string $builder): bool; } diff --git a/packages/graphql/src/Builder/Manipulator.php b/packages/graphql/src/Builder/Manipulator.php index fc4af83c3..4ca2b6f0b 100644 --- a/packages/graphql/src/Builder/Manipulator.php +++ b/packages/graphql/src/Builder/Manipulator.php @@ -18,7 +18,6 @@ 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\Operator; use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Scope; @@ -116,19 +115,12 @@ public function addOperators(Operators $operators): static { /** * @template T of Operator * - * @param class-string $scope * @param class-string $operator + * @param class-string $scope * * @return T|null */ - public function getOperator(string $scope, string $operator, Context $context): ?Operator { - // Builder? - $builder = $context->get(HandlerContextBuilderInfo::class)?->value->getBuilder(); - - if (!$builder) { - return null; - } - + public function getOperator(string $operator, string $scope, TypeSource $source, Context $context): ?Operator { // Provider? $provider = $this->operators[$scope] ?? null; @@ -139,7 +131,7 @@ public function getOperator(string $scope, string $operator, Context $context): // Available? $operator = $provider->getOperator($operator); - if (!$operator->isAvailable($builder, $context)) { + if (!$operator->isAvailable($this, $source, $context)) { return null; } @@ -152,7 +144,13 @@ public function getOperator(string $scope, string $operator, Context $context): * * @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; @@ -160,13 +158,6 @@ public function getTypeOperators(string $scope, string $type, Context $context, return []; } - // Builder? - $builder = $context->get(HandlerContextBuilderInfo::class)?->value->getBuilder(); - - if (!$builder) { - return []; - } - // Operators $operators = []; @@ -179,7 +170,7 @@ public function getTypeOperators(string $scope, string $type, Context $context, $directiveType = $directive->getType(); if ($type !== $directiveType) { - array_push($operators, ...$this->getTypeOperators($scope, $directiveType, $context)); + array_push($operators, ...$this->getTypeOperators($directiveType, $scope, $source, $context)); } else { array_push($operators, ...$provider->getOperators($type)); } @@ -201,7 +192,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->getTypeOperators($extra, $scope, $source, $context)); } // Unique @@ -212,7 +203,7 @@ public function getTypeOperators(string $scope, string $type, Context $context, continue; } - if (!$operator->isAvailable($builder, $context)) { + if (!$operator->isAvailable($this, $source, $context)) { continue; } diff --git a/packages/graphql/src/Builder/ManipulatorTest.php b/packages/graphql/src/Builder/ManipulatorTest.php index 41db81960..a51007157 100644 --- a/packages/graphql/src/Builder/ManipulatorTest.php +++ b/packages/graphql/src/Builder/ManipulatorTest.php @@ -14,6 +14,7 @@ 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; @@ -123,6 +124,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 +146,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 +155,42 @@ 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), + ), ); } // @@ -217,7 +228,7 @@ public function getFieldDescription(): ?string { } #[Override] - public function isAvailable(string $builder, ContextContract $context): bool { + protected function isBuilderSupported(string $builder): bool { return is_a($builder, stdClass::class, true); } @@ -254,7 +265,7 @@ public function getFieldDescription(): ?string { } #[Override] - public function isAvailable(string $builder, ContextContract $context): bool { + protected function isBuilderSupported(string $builder): bool { return false; } @@ -291,7 +302,7 @@ public function getFieldDescription(): ?string { } #[Override] - public function isAvailable(string $builder, ContextContract $context): bool { + protected function isBuilderSupported(string $builder): bool { return is_a($builder, stdClass::class, true); } diff --git a/packages/graphql/src/Builder/OperatorsTest.php b/packages/graphql/src/Builder/OperatorsTest.php index cd9bf4580..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'); } 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..8d535b6ae 100644 --- a/packages/graphql/src/Builder/Types/InputObject.php +++ b/packages/graphql/src/Builder/Types/InputObject.php @@ -12,7 +12,6 @@ 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\Operator; @@ -137,7 +136,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; @@ -300,17 +299,10 @@ 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]; - if ($operator === null || !$operator->isAvailable($builder, $context)) { + if ($operator === null || !$operator->isAvailable($manipulator, $field, $context)) { return null; } @@ -348,7 +340,7 @@ protected function getFieldOperator( $type = $this->getTypeForFieldOperator(); if ($type) { - $operators = $manipulator->getTypeOperators($this->getScope(), $type, $context); + $operators = $manipulator->getTypeOperators($type, $this->getScope(), $field, $context); $operator = reset($operators) ?: null; } } @@ -371,13 +363,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 +371,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/SearchBy/Operators/Child.php b/packages/graphql/src/SearchBy/Operators/Child.php index 8cb40d997..2af36606c 100644 --- a/packages/graphql/src/SearchBy/Operators/Child.php +++ b/packages/graphql/src/SearchBy/Operators/Child.php @@ -31,7 +31,7 @@ public function getFieldDescription(): ?string { } #[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/Complex/Relationship.php b/packages/graphql/src/SearchBy/Operators/Complex/Relationship.php index 27e33f9d0..34ea403d0 100644 --- a/packages/graphql/src/SearchBy/Operators/Complex/Relationship.php +++ b/packages/graphql/src/SearchBy/Operators/Complex/Relationship.php @@ -64,7 +64,7 @@ public function getFieldDescription(): ?string { } #[Override] - public function isAvailable(string $builder, Context $context): bool { + protected function isBuilderSupported(string $builder): bool { return is_a($builder, EloquentBuilder::class, true); } diff --git a/packages/graphql/src/SearchBy/Operators/Operator.php b/packages/graphql/src/SearchBy/Operators/Operator.php index a54083787..85a91422c 100644 --- a/packages/graphql/src/SearchBy/Operators/Operator.php +++ b/packages/graphql/src/SearchBy/Operators/Operator.php @@ -20,7 +20,7 @@ public function getFieldType(TypeProvider $provider, TypeSource $source, Context } #[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/Types/Condition/Root.php b/packages/graphql/src/SearchBy/Types/Condition/Root.php index bf8298977..2acef798a 100644 --- a/packages/graphql/src/SearchBy/Types/Condition/Root.php +++ b/packages/graphql/src/SearchBy/Types/Condition/Root.php @@ -21,7 +21,12 @@ protected function getOperators( Context $context, ): array { $operators = parent::getOperators($manipulator, $source, $context); - $operator = $manipulator->getOperator($this->getScope(), SearchByOperatorFieldDirective::class, $context); + $operator = $manipulator->getOperator( + SearchByOperatorFieldDirective::class, + $this->getScope(), + $source, + $context, + ); if ($operator) { $operators[] = $operator; diff --git a/packages/graphql/src/SearchBy/Types/Condition/Type.php b/packages/graphql/src/SearchBy/Types/Condition/Type.php index 83774f2c1..e1a2e751e 100644 --- a/packages/graphql/src/SearchBy/Types/Condition/Type.php +++ b/packages/graphql/src/SearchBy/Types/Condition/Type.php @@ -92,7 +92,7 @@ protected function getFieldOperator( $type = $manipulator->getType($operator, $field, $context); $source = $manipulator->getTypeSource(Parser::typeReference($type)); $operator = SearchByOperatorConditionDirective::class; - $operator = $manipulator->getOperator($this->getScope(), $operator, $context); + $operator = $manipulator->getOperator($operator, $this->getScope(), $field, $context); $operator = $operator ? [$operator, $source] : null; } diff --git a/packages/graphql/src/SearchBy/Types/Enumeration.php b/packages/graphql/src/SearchBy/Types/Enumeration.php index 9073abc03..785dde525 100644 --- a/packages/graphql/src/SearchBy/Types/Enumeration.php +++ b/packages/graphql/src/SearchBy/Types/Enumeration.php @@ -42,8 +42,8 @@ public function getTypeDefinition( // Operators $scope = Directive::getScope(); $extras = $source->isNullable() ? [Operators::Null] : []; - $operators = $manipulator->getTypeOperators($scope, $source->getTypeName(), $context, ...$extras) - ?: $manipulator->getTypeOperators($scope, Operators::Enum, $context, ...$extras); + $operators = $manipulator->getTypeOperators($source->getTypeName(), $scope, $source, $context, ...$extras) + ?: $manipulator->getTypeOperators(Operators::Enum, $scope, $source, $context, ...$extras); if (!$operators) { return null; diff --git a/packages/graphql/src/SearchBy/Types/Scalar.php b/packages/graphql/src/SearchBy/Types/Scalar.php index cf2ccf978..9ca58138c 100644 --- a/packages/graphql/src/SearchBy/Types/Scalar.php +++ b/packages/graphql/src/SearchBy/Types/Scalar.php @@ -42,7 +42,7 @@ public function getTypeDefinition( // Operators $scope = Directive::getScope(); $extras = $source->isNullable() ? [Operators::Null] : []; - $operators = $manipulator->getTypeOperators($scope, $source->getTypeName(), $context, ...$extras); + $operators = $manipulator->getTypeOperators($source->getTypeName(), $scope, $source, $context, ...$extras); if (!$operators) { return null; diff --git a/packages/graphql/src/SortBy/Operators/Child.php b/packages/graphql/src/SortBy/Operators/Child.php index f8e319186..cd08e4c97 100644 --- a/packages/graphql/src/SortBy/Operators/Child.php +++ b/packages/graphql/src/SortBy/Operators/Child.php @@ -32,7 +32,7 @@ public function getFieldDescription(): ?string { } #[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 5595aa748..3568111c8 100644 --- a/packages/graphql/src/SortBy/Operators/Extra/NullsFirst.php +++ b/packages/graphql/src/SortBy/Operators/Extra/NullsFirst.php @@ -46,7 +46,7 @@ public function getFieldDescription(): ?string { } #[Override] - public function isAvailable(string $builder, Context $context): bool { + protected function isBuilderSupported(string $builder): bool { return (bool) $this->factory->create($builder)?->isNullsSupported(); } diff --git a/packages/graphql/src/SortBy/Operators/Extra/NullsLast.php b/packages/graphql/src/SortBy/Operators/Extra/NullsLast.php index 94b1d3fc0..093813f18 100644 --- a/packages/graphql/src/SortBy/Operators/Extra/NullsLast.php +++ b/packages/graphql/src/SortBy/Operators/Extra/NullsLast.php @@ -46,7 +46,7 @@ public function getFieldDescription(): ?string { } #[Override] - public function isAvailable(string $builder, Context $context): bool { + protected function isBuilderSupported(string $builder): bool { return (bool) $this->factory->create($builder)?->isNullsSupported(); } 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/Sort.php b/packages/graphql/src/SortBy/Operators/Sort.php index 635ef2f16..5be53c005 100644 --- a/packages/graphql/src/SortBy/Operators/Sort.php +++ b/packages/graphql/src/SortBy/Operators/Sort.php @@ -48,7 +48,7 @@ public function getFieldDescription(): ?string { } #[Override] - public function isAvailable(string $builder, Context $context): bool { + protected function isBuilderSupported(string $builder): bool { return $this->factory->isSupported($builder); } diff --git a/packages/graphql/src/SortBy/Types/Clause/Root.php b/packages/graphql/src/SortBy/Types/Clause/Root.php index 9741803d7..7554fee91 100644 --- a/packages/graphql/src/SortBy/Types/Clause/Root.php +++ b/packages/graphql/src/SortBy/Types/Clause/Root.php @@ -21,7 +21,12 @@ protected function getOperators( Context $context, ): array { $operators = parent::getOperators($manipulator, $source, $context); - $operator = $manipulator->getOperator($this->getScope(), SortByOperatorFieldDirective::class, $context); + $operator = $manipulator->getOperator( + SortByOperatorFieldDirective::class, + $this->getScope(), + $source, + $context, + ); if ($operator) { $operators[] = $operator; diff --git a/packages/graphql/src/SortBy/Types/Clause/Type.php b/packages/graphql/src/SortBy/Types/Clause/Type.php index 55b4a43ef..ff1767fbd 100644 --- a/packages/graphql/src/SortBy/Types/Clause/Type.php +++ b/packages/graphql/src/SortBy/Types/Clause/Type.php @@ -109,7 +109,12 @@ protected function getFieldOperator( if (is_string($operator)) { $type = $manipulator->getType($operator, $field, $context); $source = $manipulator->getTypeSource(Parser::typeReference($type)); - $operator = $manipulator->getOperator($this->getScope(), SortByOperatorSortDirective::class, $context); + $operator = $manipulator->getOperator( + SortByOperatorSortDirective::class, + $this->getScope(), + $field, + $context, + ); $operator = $operator ? [$operator, $source] : null; } else { // empty From 4eb75fcf1d1f4e5f3080a2fa776f2fa8ecc2483b Mon Sep 17 00:00:00 2001 From: Aleksei Lebedev <1329824+LastDragon-ru@users.noreply.github.com> Date: Mon, 12 Feb 2024 09:33:04 +0400 Subject: [PATCH 08/15] `Manipulator::getTypeOperators()` rework (less `isAvailable()` calls). --- packages/graphql/src/Builder/Manipulator.php | 67 +++++++++++-------- .../graphql/src/Builder/ManipulatorTest.php | 21 ++++-- .../graphql/src/Builder/Types/InputObject.php | 4 +- .../src/SearchBy/Types/Enumeration.php | 4 +- .../graphql/src/SearchBy/Types/Scalar.php | 2 +- 5 files changed, 59 insertions(+), 39 deletions(-) diff --git a/packages/graphql/src/Builder/Manipulator.php b/packages/graphql/src/Builder/Manipulator.php index 4ca2b6f0b..67d6c9b5e 100644 --- a/packages/graphql/src/Builder/Manipulator.php +++ b/packages/graphql/src/Builder/Manipulator.php @@ -145,10 +145,10 @@ public function getOperator(string $operator, string $scope, TypeSource $source, * @return list */ public function getTypeOperators( - string $type, string $scope, TypeSource $source, Context $context, + string $type, string ...$extras, ): array { // Provider? @@ -159,32 +159,7 @@ public function getTypeOperators( } // 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($directiveType, $scope, $source, $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 []; @@ -192,7 +167,7 @@ public function getTypeOperators( // Extra foreach ($extras as $extra) { - array_push($operators, ...$this->getTypeOperators($extra, $scope, $source, $context)); + array_push($operators, ...$this->getOperators($provider, $scope, $extra)); } // Unique @@ -316,5 +291,41 @@ protected function removeFakeTypeDefinition(string $name): void { // Remove $this->removeTypeDefinition($name); } + + /** + * @param class-string $scope + * + * @return array + */ + private function getOperators(Operators $provider, string $scope, string $type): array { + $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->getOperators($provider, $scope, $directiveType)); + } 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)); + } + + return $operators; + } // } diff --git a/packages/graphql/src/Builder/ManipulatorTest.php b/packages/graphql/src/Builder/ManipulatorTest.php index a51007157..fb18836ba 100644 --- a/packages/graphql/src/Builder/ManipulatorTest.php +++ b/packages/graphql/src/Builder/ManipulatorTest.php @@ -146,7 +146,7 @@ public function getScope(): string { [ $aOperator, ], - array_map($map, $manipulator->getTypeOperators(Operators::ID, $operators->getScope(), $source, $context)), + array_map($map, $manipulator->getTypeOperators($operators->getScope(), $source, $context, Operators::ID)), ); self::assertEquals( [ @@ -156,10 +156,10 @@ public function getScope(): string { array_map( $map, $manipulator->getTypeOperators( - Operators::ID, $operators->getScope(), $source, $context, + Operators::ID, Operators::Int, ), ), @@ -168,19 +168,19 @@ public function getScope(): string { [ // empty (another scope) ], - array_map($map, $manipulator->getTypeOperators(Operators::ID, $scope::class, $source, $context)), + array_map($map, $manipulator->getTypeOperators($scope::class, $source, $context, Operators::ID)), ); self::assertEquals( [ $aOperator, ], - array_map($map, $manipulator->getTypeOperators('TestScalar', $operators->getScope(), $source, $context)), + array_map($map, $manipulator->getTypeOperators($operators->getScope(), $source, $context, 'TestScalar')), ); self::assertEquals( [ $aOperator, ], - array_map($map, $manipulator->getTypeOperators('TestOperators', $operators->getScope(), $source, $context)), + array_map($map, $manipulator->getTypeOperators($operators->getScope(), $source, $context, 'TestOperators')), ); self::assertEquals( [ @@ -189,7 +189,16 @@ public function getScope(): string { ], array_map( $map, - $manipulator->getTypeOperators('TestBuiltinOperators', $operators->getScope(), $source, $context), + $manipulator->getTypeOperators($operators->getScope(), $source, $context, 'TestBuiltinOperators'), + ), + ); + self::assertEquals( + [ + // empty + ], + array_map( + $map, + $manipulator->getTypeOperators($operators->getScope(), $source, $context, 'Unknown', Operators::ID), ), ); } diff --git a/packages/graphql/src/Builder/Types/InputObject.php b/packages/graphql/src/Builder/Types/InputObject.php index 8d535b6ae..6f0a40646 100644 --- a/packages/graphql/src/Builder/Types/InputObject.php +++ b/packages/graphql/src/Builder/Types/InputObject.php @@ -136,7 +136,7 @@ protected function getOperators( ): array { $type = $this->getTypeForOperators(); $operators = $type - ? $manipulator->getTypeOperators($type, $this->getScope(), $source, $context) + ? $manipulator->getTypeOperators($this->getScope(), $source, $context, $type) : []; return $operators; @@ -340,7 +340,7 @@ protected function getFieldOperator( $type = $this->getTypeForFieldOperator(); if ($type) { - $operators = $manipulator->getTypeOperators($type, $this->getScope(), $field, $context); + $operators = $manipulator->getTypeOperators($this->getScope(), $field, $context, $type); $operator = reset($operators) ?: null; } } diff --git a/packages/graphql/src/SearchBy/Types/Enumeration.php b/packages/graphql/src/SearchBy/Types/Enumeration.php index 785dde525..99e7498ba 100644 --- a/packages/graphql/src/SearchBy/Types/Enumeration.php +++ b/packages/graphql/src/SearchBy/Types/Enumeration.php @@ -42,8 +42,8 @@ public function getTypeDefinition( // Operators $scope = Directive::getScope(); $extras = $source->isNullable() ? [Operators::Null] : []; - $operators = $manipulator->getTypeOperators($source->getTypeName(), $scope, $source, $context, ...$extras) - ?: $manipulator->getTypeOperators(Operators::Enum, $scope, $source, $context, ...$extras); + $operators = $manipulator->getTypeOperators($scope, $source, $context, $source->getTypeName(), ...$extras) + ?: $manipulator->getTypeOperators($scope, $source, $context, Operators::Enum, ...$extras); if (!$operators) { return null; diff --git a/packages/graphql/src/SearchBy/Types/Scalar.php b/packages/graphql/src/SearchBy/Types/Scalar.php index 9ca58138c..76c37ddcc 100644 --- a/packages/graphql/src/SearchBy/Types/Scalar.php +++ b/packages/graphql/src/SearchBy/Types/Scalar.php @@ -42,7 +42,7 @@ public function getTypeDefinition( // Operators $scope = Directive::getScope(); $extras = $source->isNullable() ? [Operators::Null] : []; - $operators = $manipulator->getTypeOperators($source->getTypeName(), $scope, $source, $context, ...$extras); + $operators = $manipulator->getTypeOperators($scope, $source, $context, $source->getTypeName(), ...$extras); if (!$operators) { return null; From f31e9b49e4fbab9f7e5d9b5bdf1eab17b8da9c10 Mon Sep 17 00:00:00 2001 From: Aleksei Lebedev <1329824+LastDragon-ru@users.noreply.github.com> Date: Mon, 12 Feb 2024 09:43:19 +0400 Subject: [PATCH 09/15] `Manipulator::getOperator()` better arguments order. --- packages/graphql/src/Builder/Directives/HandlerDirective.php | 2 +- packages/graphql/src/Builder/Manipulator.php | 4 ++-- packages/graphql/src/SearchBy/Types/Condition/Root.php | 2 +- packages/graphql/src/SearchBy/Types/Condition/Type.php | 2 +- packages/graphql/src/SortBy/Types/Clause/Root.php | 2 +- packages/graphql/src/SortBy/Types/Clause/Type.php | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/graphql/src/Builder/Directives/HandlerDirective.php b/packages/graphql/src/Builder/Directives/HandlerDirective.php index b319c41fd..1acbe41ba 100644 --- a/packages/graphql/src/Builder/Directives/HandlerDirective.php +++ b/packages/graphql/src/Builder/Directives/HandlerDirective.php @@ -264,7 +264,7 @@ protected function getArgumentTypeDefinitionNode( string $operator, ): ListTypeNode|NamedTypeNode|NonNullTypeNode|null { // Supported? - $operator = $manipulator->getOperator($operator, static::getScope(), $argument, $context); + $operator = $manipulator->getOperator(static::getScope(), $argument, $context, $operator); if (!$operator) { return null; diff --git a/packages/graphql/src/Builder/Manipulator.php b/packages/graphql/src/Builder/Manipulator.php index 67d6c9b5e..ebcd9af9a 100644 --- a/packages/graphql/src/Builder/Manipulator.php +++ b/packages/graphql/src/Builder/Manipulator.php @@ -115,12 +115,12 @@ public function addOperators(Operators $operators): static { /** * @template T of Operator * - * @param class-string $operator * @param class-string $scope + * @param class-string $operator * * @return T|null */ - public function getOperator(string $operator, string $scope, TypeSource $source, Context $context): ?Operator { + public function getOperator(string $scope, TypeSource $source, Context $context, string $operator): ?Operator { // Provider? $provider = $this->operators[$scope] ?? null; diff --git a/packages/graphql/src/SearchBy/Types/Condition/Root.php b/packages/graphql/src/SearchBy/Types/Condition/Root.php index 2acef798a..bf7398218 100644 --- a/packages/graphql/src/SearchBy/Types/Condition/Root.php +++ b/packages/graphql/src/SearchBy/Types/Condition/Root.php @@ -22,10 +22,10 @@ protected function getOperators( ): array { $operators = parent::getOperators($manipulator, $source, $context); $operator = $manipulator->getOperator( - SearchByOperatorFieldDirective::class, $this->getScope(), $source, $context, + SearchByOperatorFieldDirective::class, ); if ($operator) { diff --git a/packages/graphql/src/SearchBy/Types/Condition/Type.php b/packages/graphql/src/SearchBy/Types/Condition/Type.php index e1a2e751e..3c3b8ea35 100644 --- a/packages/graphql/src/SearchBy/Types/Condition/Type.php +++ b/packages/graphql/src/SearchBy/Types/Condition/Type.php @@ -92,7 +92,7 @@ protected function getFieldOperator( $type = $manipulator->getType($operator, $field, $context); $source = $manipulator->getTypeSource(Parser::typeReference($type)); $operator = SearchByOperatorConditionDirective::class; - $operator = $manipulator->getOperator($operator, $this->getScope(), $field, $context); + $operator = $manipulator->getOperator($this->getScope(), $field, $context, $operator); $operator = $operator ? [$operator, $source] : null; } diff --git a/packages/graphql/src/SortBy/Types/Clause/Root.php b/packages/graphql/src/SortBy/Types/Clause/Root.php index 7554fee91..260ced53e 100644 --- a/packages/graphql/src/SortBy/Types/Clause/Root.php +++ b/packages/graphql/src/SortBy/Types/Clause/Root.php @@ -22,10 +22,10 @@ protected function getOperators( ): array { $operators = parent::getOperators($manipulator, $source, $context); $operator = $manipulator->getOperator( - SortByOperatorFieldDirective::class, $this->getScope(), $source, $context, + SortByOperatorFieldDirective::class, ); if ($operator) { diff --git a/packages/graphql/src/SortBy/Types/Clause/Type.php b/packages/graphql/src/SortBy/Types/Clause/Type.php index ff1767fbd..8c7da538c 100644 --- a/packages/graphql/src/SortBy/Types/Clause/Type.php +++ b/packages/graphql/src/SortBy/Types/Clause/Type.php @@ -110,10 +110,10 @@ protected function getFieldOperator( $type = $manipulator->getType($operator, $field, $context); $source = $manipulator->getTypeSource(Parser::typeReference($type)); $operator = $manipulator->getOperator( - SortByOperatorSortDirective::class, $this->getScope(), $field, $context, + SortByOperatorSortDirective::class, ); $operator = $operator ? [$operator, $source] : null; } else { From ab4c33474286d7ca457ae45de735cc3837275e86 Mon Sep 17 00:00:00 2001 From: Aleksei Lebedev <1329824+LastDragon-ru@users.noreply.github.com> Date: Mon, 12 Feb 2024 10:41:19 +0400 Subject: [PATCH 10/15] `Manipulator::getTypeOperators()` aligned with `InputObject` to return empty operators for ignored type. --- .../graphql/src/Builder/Contracts/Ignored.php | 11 +++++++ packages/graphql/src/Builder/Manipulator.php | 14 +++++++-- .../graphql/src/Builder/ManipulatorTest.php | 29 +++++++++++++++++++ .../graphql/src/Builder/Types/InputObject.php | 3 +- .../src/SearchBy/Contracts/Ignored.php | 4 ++- .../graphql/src/SortBy/Contracts/Ignored.php | 4 ++- 6 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 packages/graphql/src/Builder/Contracts/Ignored.php diff --git a/packages/graphql/src/Builder/Contracts/Ignored.php b/packages/graphql/src/Builder/Contracts/Ignored.php new file mode 100644 index 000000000..2e6eaa885 --- /dev/null +++ b/packages/graphql/src/Builder/Contracts/Ignored.php @@ -0,0 +1,11 @@ + */ 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, $scope); + $directives = $this->getDirectives($node); foreach ($directives as $directive) { + if (!($directive instanceof $scope)) { + continue; + } + if ($directive instanceof OperatorsDirective) { $directiveType = $directive->getType(); @@ -315,13 +321,17 @@ private function getOperators(Operators $provider, string $scope, string $type): } } elseif ($directive instanceof Operator) { $operators[] = $directive; + } elseif ($directive instanceof Ignored) { + $ignored = true; + $operators = []; + break; } else { // empty } } } - if (!$operators && $provider->hasOperators($type)) { + if (!$operators && !$ignored && $provider->hasOperators($type)) { array_push($operators, ...$provider->getOperators($type)); } diff --git a/packages/graphql/src/Builder/ManipulatorTest.php b/packages/graphql/src/Builder/ManipulatorTest.php index fb18836ba..cdcf3139e 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; @@ -18,6 +19,7 @@ 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; @@ -65,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); @@ -78,6 +81,10 @@ public function testGetTypeOperators(): void { @bOperator @cOperator + scalar TestIgnored + @aOperator + @ignored + scalar TestOperators @operators(type: "TestScalar") @@ -201,6 +208,15 @@ public function getScope(): string { $manipulator->getTypeOperators($operators->getScope(), $source, $context, 'Unknown', Operators::ID), ), ); + self::assertEquals( + [ + // empty + ], + array_map( + $map, + $manipulator->getTypeOperators($operators->getScope(), $source, $context, 'TestIgnored'), + ), + ); } // } @@ -326,3 +342,16 @@ public function call( 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/Types/InputObject.php b/packages/graphql/src/Builder/Types/InputObject.php index 6f0a40646..4bf3a9848 100644 --- a/packages/graphql/src/Builder/Types/InputObject.php +++ b/packages/graphql/src/Builder/Types/InputObject.php @@ -14,6 +14,7 @@ use GraphQL\Type\Definition\Type; 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; @@ -288,7 +289,7 @@ abstract protected function getFieldMarkerOperator(): string; /** * @see self::isFieldConvertableIgnored() * - * @return class-string|null + * @return class-string|null */ protected function getFieldMarkerIgnored(): ?string { return null; 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/SortBy/Contracts/Ignored.php b/packages/graphql/src/SortBy/Contracts/Ignored.php index 42dc2eaad..fd620dcac 100644 --- a/packages/graphql/src/SortBy/Contracts/Ignored.php +++ b/packages/graphql/src/SortBy/Contracts/Ignored.php @@ -2,9 +2,11 @@ namespace LastDragon_ru\LaraASP\GraphQL\SortBy\Contracts; +use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Ignored as IgnoredContract; + /** * Marks that field/definition should be excluded from sort. */ -interface Ignored { +interface Ignored extends IgnoredContract, Scope { // empty } From 8e778fb649898768c2d2e8336ffb469119a9f149 Mon Sep 17 00:00:00 2001 From: Aleksei Lebedev <1329824+LastDragon-ru@users.noreply.github.com> Date: Mon, 12 Feb 2024 11:19:20 +0400 Subject: [PATCH 11/15] `SearchByOperatorFieldDirective` and `SortByOperatorFieldDirective` added to the "extra" operators. --- packages/graphql/UPGRADE.md | 2 +- .../Client/ConditionTooManyFields.php | 12 ++++++--- .../Client/ConditionTooManyOperators.php | 12 ++++++--- .../src/SearchBy/Directives/DirectiveTest.php | 7 +++--- .../ScalarOperators.schema.graphql | 1 + packages/graphql/src/SearchBy/Operators.php | 2 ++ .../src/SearchBy/Types/Condition/Root.php | 25 ------------------- .../src/SearchBy/Types/Condition/V5.php | 24 ++++++++++++++++++ .../src/SortBy/Directives/DirectiveTest.php | 11 +++++--- packages/graphql/src/SortBy/Operators.php | 2 ++ .../graphql/src/SortBy/Types/Clause/Root.php | 25 ------------------- .../graphql/src/SortBy/Types/Clause/V5.php | 24 ++++++++++++++++++ 12 files changed, 81 insertions(+), 66 deletions(-) diff --git a/packages/graphql/UPGRADE.md b/packages/graphql/UPGRADE.md index 35588a50e..fe384cd6c 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 = [ diff --git a/packages/graphql/src/Builder/Exceptions/Client/ConditionTooManyFields.php b/packages/graphql/src/Builder/Exceptions/Client/ConditionTooManyFields.php index 40ffab525..db8f027d3 100644 --- a/packages/graphql/src/Builder/Exceptions/Client/ConditionTooManyFields.php +++ b/packages/graphql/src/Builder/Exceptions/Client/ConditionTooManyFields.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 readonly array $fields, Throwable $previous = null, ) { - parent::__construct(sprintf( - 'Only one field allowed, found: `%s`.', - implode('`, `', $this->getFields()), - ), $previous); + parent::__construct( + sprintf( + 'Only one field allowed, found: `%s`.', + implode('`, `', Arr::sort($this->getFields())), + ), + $previous, + ); } /** 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/SearchBy/Directives/DirectiveTest.php b/packages/graphql/src/SearchBy/Directives/DirectiveTest.php index b0a8fa66c..85abf1a4f 100644 --- a/packages/graphql/src/SearchBy/Directives/DirectiveTest.php +++ b/packages/graphql/src/SearchBy/Directives/DirectiveTest.php @@ -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; @@ -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, ], ]); }, 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/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/Types/Condition/Root.php b/packages/graphql/src/SearchBy/Types/Condition/Root.php index bf7398218..ac1809921 100644 --- a/packages/graphql/src/SearchBy/Types/Condition/Root.php +++ b/packages/graphql/src/SearchBy/Types/Condition/Root.php @@ -7,34 +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; class Root extends Type { - /** - * @inheritDoc - */ - #[Override] - protected function getOperators( - Manipulator $manipulator, - InterfaceSource|InputSource|ObjectSource $source, - Context $context, - ): array { - $operators = parent::getOperators($manipulator, $source, $context); - $operator = $manipulator->getOperator( - $this->getScope(), - $source, - $context, - SearchByOperatorFieldDirective::class, - ); - - if ($operator) { - $operators[] = $operator; - } - - return $operators; - } - /** * @inheritDoc */ 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/SortBy/Directives/DirectiveTest.php b/packages/graphql/src/SortBy/Directives/DirectiveTest.php index 46a8e68d9..4e1dcfa0d 100644 --- a/packages/graphql/src/SortBy/Directives/DirectiveTest.php +++ b/packages/graphql/src/SortBy/Directives/DirectiveTest.php @@ -21,6 +21,7 @@ use LastDragon_ru\LaraASP\GraphQL\Builder\Property; use LastDragon_ru\LaraASP\GraphQL\Package; use LastDragon_ru\LaraASP\GraphQL\SortBy\Contracts\Ignored; +use LastDragon_ru\LaraASP\GraphQL\SortBy\Definitions\SortByOperatorFieldDirective; use LastDragon_ru\LaraASP\GraphQL\SortBy\Definitions\SortByOperatorRandomDirective; use LastDragon_ru\LaraASP\GraphQL\SortBy\Enums\Direction; use LastDragon_ru\LaraASP\GraphQL\SortBy\Enums\Nulls; @@ -147,7 +148,7 @@ public function testManipulateArgDefinitionTypeRegistryEmpty(): void { config([ Package::Name.'.sort_by.operators' => [ Operators::Extra => [ - // empty + SortByOperatorFieldDirective::class, ], ], ]); @@ -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, ], ]); }, @@ -854,6 +855,7 @@ static function (): void { config([ "{$package}.sort_by.operators" => [ Operators::Extra => [ + SortByOperatorFieldDirective::class, SortByOperatorRandomDirective::class, ], ], @@ -1056,6 +1058,7 @@ static function (): void { config([ "{$package}.sort_by.operators" => [ Operators::Extra => [ + SortByOperatorFieldDirective::class, SortByOperatorRandomDirective::class, ], ], 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/Types/Clause/Root.php b/packages/graphql/src/SortBy/Types/Clause/Root.php index 260ced53e..475b7a5fa 100644 --- a/packages/graphql/src/SortBy/Types/Clause/Root.php +++ b/packages/graphql/src/SortBy/Types/Clause/Root.php @@ -7,34 +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; class Root extends Type { - /** - * @inheritDoc - */ - #[Override] - protected function getOperators( - Manipulator $manipulator, - InterfaceSource|InputSource|ObjectSource $source, - Context $context, - ): array { - $operators = parent::getOperators($manipulator, $source, $context); - $operator = $manipulator->getOperator( - $this->getScope(), - $source, - $context, - SortByOperatorFieldDirective::class, - ); - - if ($operator) { - $operators[] = $operator; - } - - return $operators; - } - /** * @inheritDoc */ 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; + } } From 7ef60ed35aa51d1ca8e0445b3f26019b20528c8e Mon Sep 17 00:00:00 2001 From: Aleksei Lebedev <1329824+LastDragon-ru@users.noreply.github.com> Date: Mon, 12 Feb 2024 13:17:13 +0400 Subject: [PATCH 12/15] `TypeProvider::getTypeSource($type)` typehint fix. --- packages/graphql/src/Builder/Contracts/TypeProvider.php | 8 +++----- packages/graphql/src/Builder/Manipulator.php | 8 ++------ 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/packages/graphql/src/Builder/Contracts/TypeProvider.php b/packages/graphql/src/Builder/Contracts/TypeProvider.php index a9d79df3c..93dec50d6 100644 --- a/packages/graphql/src/Builder/Contracts/TypeProvider.php +++ b/packages/graphql/src/Builder/Contracts/TypeProvider.php @@ -2,11 +2,9 @@ namespace LastDragon_ru\LaraASP\GraphQL\Builder\Contracts; -use GraphQL\Language\AST\ListTypeNode; -use GraphQL\Language\AST\NamedTypeNode; use GraphQL\Language\AST\Node; -use GraphQL\Language\AST\NonNullTypeNode; use GraphQL\Language\AST\TypeDefinitionNode; +use GraphQL\Language\AST\TypeNode; use GraphQL\Type\Definition\Type; interface TypeProvider { @@ -16,7 +14,7 @@ interface TypeProvider { public function getType(string $definition, TypeSource $source, Context $context): string; /** - * @param (TypeDefinitionNode&Node)|NamedTypeNode|ListTypeNode|NonNullTypeNode|Type $type + * @param (TypeDefinitionNode&Node)|(TypeNode&Node)|Type $type */ - public function getTypeSource(TypeDefinitionNode|NamedTypeNode|ListTypeNode|NonNullTypeNode|Type $type): TypeSource; + public function getTypeSource(TypeDefinitionNode|TypeNode|Type $type): TypeSource; } diff --git a/packages/graphql/src/Builder/Manipulator.php b/packages/graphql/src/Builder/Manipulator.php index 8a2cfe8e8..63ec59966 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; @@ -86,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) { From 37def80925aafe14a70d86bff3197f1d90eaee79 Mon Sep 17 00:00:00 2001 From: Aleksei Lebedev <1329824+LastDragon-ru@users.noreply.github.com> Date: Mon, 12 Feb 2024 13:45:59 +0400 Subject: [PATCH 13/15] `InputObject::getFieldOperator()` simplification (will not overwrite source). --- .../graphql/src/Builder/Types/InputObject.php | 19 ++++------ .../graphql/src/SearchBy/Operators/Child.php | 6 ++++ .../Operators/Complex/Relationship.php | 6 ++++ .../Operators/Complex/RelationshipType.php | 15 +++++--- .../src/SearchBy/Operators/Condition.php | 20 +++++++++++ .../graphql/src/SearchBy/Operators/Field.php | 6 ++++ .../src/SearchBy/Types/Condition/Type.php | 35 ++++++------------- .../src/SearchBy/Types/Enumeration.php | 17 +++++---- .../graphql/src/SearchBy/Types/Scalar.php | 15 +++++--- .../graphql/src/SortBy/Operators/Child.php | 10 ++++-- .../graphql/src/SortBy/Operators/Field.php | 6 ++++ .../graphql/src/SortBy/Operators/Sort.php | 6 ++++ .../graphql/src/SortBy/Types/Clause/Type.php | 33 +++++------------ 13 files changed, 115 insertions(+), 79 deletions(-) diff --git a/packages/graphql/src/Builder/Types/InputObject.php b/packages/graphql/src/Builder/Types/InputObject.php index 4bf3a9848..5a72d8953 100644 --- a/packages/graphql/src/Builder/Types/InputObject.php +++ b/packages/graphql/src/Builder/Types/InputObject.php @@ -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) ) { @@ -301,23 +303,19 @@ protected function getFieldDefinition( Context $context, ): ?InputValueDefinitionNode { // Operator? - [$operator, $type] = $this->getFieldOperator($manipulator, $field, $context) ?? [null, null]; + $operator = $this->getFieldOperator($manipulator, $field, $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, @@ -327,14 +325,11 @@ 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) { @@ -346,9 +341,7 @@ protected function getFieldOperator( } } - return $operator - ? [$operator, null] - : null; + return $operator; } /** diff --git a/packages/graphql/src/SearchBy/Operators/Child.php b/packages/graphql/src/SearchBy/Operators/Child.php index 2af36606c..8cd291293 100644 --- a/packages/graphql/src/SearchBy/Operators/Child.php +++ b/packages/graphql/src/SearchBy/Operators/Child.php @@ -20,6 +20,12 @@ public static function getName(): string { return 'child'; } + #[Override] + 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); diff --git a/packages/graphql/src/SearchBy/Operators/Complex/Relationship.php b/packages/graphql/src/SearchBy/Operators/Complex/Relationship.php index 34ea403d0..c743346a9 100644 --- a/packages/graphql/src/SearchBy/Operators/Complex/Relationship.php +++ b/packages/graphql/src/SearchBy/Operators/Complex/Relationship.php @@ -53,6 +53,12 @@ public static function getName(): string { return 'relation'; } + #[Override] + 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); diff --git a/packages/graphql/src/SearchBy/Operators/Complex/RelationshipType.php b/packages/graphql/src/SearchBy/Operators/Complex/RelationshipType.php index 6e3425eeb..79680d5a9 100644 --- a/packages/graphql/src/SearchBy/Operators/Complex/RelationshipType.php +++ b/packages/graphql/src/SearchBy/Operators/Complex/RelationshipType.php @@ -36,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 5ea45f462..b5457d60d 100644 --- a/packages/graphql/src/SearchBy/Operators/Field.php +++ b/packages/graphql/src/SearchBy/Operators/Field.php @@ -22,6 +22,12 @@ public static function getName(): string { return 'field'; } + #[Override] + 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); diff --git a/packages/graphql/src/SearchBy/Types/Condition/Type.php b/packages/graphql/src/SearchBy/Types/Condition/Type.php index 3c3b8ea35..077a72bce 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 { @@ -72,30 +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( + $this->getScope(), + $field, + $context, + SearchByOperatorConditionDirective::class, + ), + $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 = SearchByOperatorConditionDirective::class; - $operator = $manipulator->getOperator($this->getScope(), $field, $context, $operator); - $operator = $operator ? [$operator, $source] : null; - } - - return $operator; } } diff --git a/packages/graphql/src/SearchBy/Types/Enumeration.php b/packages/graphql/src/SearchBy/Types/Enumeration.php index 99e7498ba..58bd6b29f 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, $context, $source->getTypeName(), ...$extras) - ?: $manipulator->getTypeOperators($scope, $source, $context, Operators::Enum, ...$extras); + $extras = $type->isNullable() ? [Operators::Null] : []; + $operators = $manipulator->getTypeOperators($scope, $type, $context, $type->getTypeName(), ...$extras) + ?: $manipulator->getTypeOperators($scope, $type, $context, Operators::Enum, ...$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, $context, $source->getTypeName(), ...$extras); + $extras = $type->isNullable() ? [Operators::Null] : []; + $operators = $manipulator->getTypeOperators($scope, $type, $context, $type->getTypeName(), ...$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( <<isObject(); + } + #[Override] public function getFieldType(TypeProvider $provider, TypeSource $source, Context $context): ?string { - return $provider->getType(ClauseType::class, $source, $context); + return $provider->getType(Clause::class, $source, $context); } #[Override] diff --git a/packages/graphql/src/SortBy/Operators/Field.php b/packages/graphql/src/SortBy/Operators/Field.php index 255098d31..b4569dc63 100644 --- a/packages/graphql/src/SortBy/Operators/Field.php +++ b/packages/graphql/src/SortBy/Operators/Field.php @@ -22,6 +22,12 @@ public static function getName(): string { return 'field'; } + #[Override] + 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(Clause::class, $source, $context); diff --git a/packages/graphql/src/SortBy/Operators/Sort.php b/packages/graphql/src/SortBy/Operators/Sort.php index 5be53c005..aec7271d6 100644 --- a/packages/graphql/src/SortBy/Operators/Sort.php +++ b/packages/graphql/src/SortBy/Operators/Sort.php @@ -37,6 +37,12 @@ public static function getName(): string { return 'sort'; } + #[Override] + 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); diff --git a/packages/graphql/src/SortBy/Types/Clause/Type.php b/packages/graphql/src/SortBy/Types/Clause/Type.php index 8c7da538c..e8702086d 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 { @@ -91,35 +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, - $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( + ): ?OperatorContract { + return match (true) { + $field->isScalar(), $field->isEnum() => $manipulator->getOperator( $this->getScope(), $field, $context, SortByOperatorSortDirective::class, - ); - $operator = $operator ? [$operator, $source] : null; - } else { - // empty - } - - return $operator; + ), + $field->isObject() => parent::getFieldOperator($manipulator, $field, $context), + default => throw new NotImplemented($field), + }; } } From b5b3eb5c7f38e0ec9918a9e90842d76ac27fae5e Mon Sep 17 00:00:00 2001 From: Aleksei Lebedev <1329824+LastDragon-ru@users.noreply.github.com> Date: Mon, 12 Feb 2024 14:00:25 +0400 Subject: [PATCH 14/15] `Manipulator::getOperator()`/`Manipulator::getTypeOperators()` revert order of arguments. --- .../src/Builder/Directives/HandlerDirective.php | 2 +- packages/graphql/src/Builder/Manipulator.php | 6 +++--- packages/graphql/src/Builder/ManipulatorTest.php | 16 ++++++++-------- .../graphql/src/Builder/Types/InputObject.php | 4 ++-- .../src/SearchBy/Types/Condition/Type.php | 2 +- .../graphql/src/SearchBy/Types/Enumeration.php | 4 ++-- packages/graphql/src/SearchBy/Types/Scalar.php | 2 +- .../graphql/src/SortBy/Types/Clause/Type.php | 2 +- 8 files changed, 19 insertions(+), 19 deletions(-) diff --git a/packages/graphql/src/Builder/Directives/HandlerDirective.php b/packages/graphql/src/Builder/Directives/HandlerDirective.php index 1acbe41ba..b319c41fd 100644 --- a/packages/graphql/src/Builder/Directives/HandlerDirective.php +++ b/packages/graphql/src/Builder/Directives/HandlerDirective.php @@ -264,7 +264,7 @@ protected function getArgumentTypeDefinitionNode( string $operator, ): ListTypeNode|NamedTypeNode|NonNullTypeNode|null { // Supported? - $operator = $manipulator->getOperator(static::getScope(), $argument, $context, $operator); + $operator = $manipulator->getOperator($operator, static::getScope(), $argument, $context); if (!$operator) { return null; diff --git a/packages/graphql/src/Builder/Manipulator.php b/packages/graphql/src/Builder/Manipulator.php index 63ec59966..1d85cd319 100644 --- a/packages/graphql/src/Builder/Manipulator.php +++ b/packages/graphql/src/Builder/Manipulator.php @@ -112,12 +112,12 @@ public function addOperators(Operators $operators): static { /** * @template T of Operator * - * @param class-string $scope * @param class-string $operator + * @param class-string $scope * * @return T|null */ - public function getOperator(string $scope, TypeSource $source, Context $context, string $operator): ?Operator { + public function getOperator(string $operator, string $scope, TypeSource $source, Context $context): ?Operator { // Provider? $provider = $this->operators[$scope] ?? null; @@ -142,10 +142,10 @@ public function getOperator(string $scope, TypeSource $source, Context $context, * @return list */ public function getTypeOperators( + string $type, string $scope, TypeSource $source, Context $context, - string $type, string ...$extras, ): array { // Provider? diff --git a/packages/graphql/src/Builder/ManipulatorTest.php b/packages/graphql/src/Builder/ManipulatorTest.php index cdcf3139e..01ecc03a2 100644 --- a/packages/graphql/src/Builder/ManipulatorTest.php +++ b/packages/graphql/src/Builder/ManipulatorTest.php @@ -153,7 +153,7 @@ public function getScope(): string { [ $aOperator, ], - array_map($map, $manipulator->getTypeOperators($operators->getScope(), $source, $context, Operators::ID)), + array_map($map, $manipulator->getTypeOperators(Operators::ID, $operators->getScope(), $source, $context)), ); self::assertEquals( [ @@ -163,10 +163,10 @@ public function getScope(): string { array_map( $map, $manipulator->getTypeOperators( + Operators::ID, $operators->getScope(), $source, $context, - Operators::ID, Operators::Int, ), ), @@ -175,19 +175,19 @@ public function getScope(): string { [ // empty (another scope) ], - array_map($map, $manipulator->getTypeOperators($scope::class, $source, $context, Operators::ID)), + array_map($map, $manipulator->getTypeOperators(Operators::ID, $scope::class, $source, $context)), ); self::assertEquals( [ $aOperator, ], - array_map($map, $manipulator->getTypeOperators($operators->getScope(), $source, $context, 'TestScalar')), + array_map($map, $manipulator->getTypeOperators('TestScalar', $operators->getScope(), $source, $context)), ); self::assertEquals( [ $aOperator, ], - array_map($map, $manipulator->getTypeOperators($operators->getScope(), $source, $context, 'TestOperators')), + array_map($map, $manipulator->getTypeOperators('TestOperators', $operators->getScope(), $source, $context)), ); self::assertEquals( [ @@ -196,7 +196,7 @@ public function getScope(): string { ], array_map( $map, - $manipulator->getTypeOperators($operators->getScope(), $source, $context, 'TestBuiltinOperators'), + $manipulator->getTypeOperators('TestBuiltinOperators', $operators->getScope(), $source, $context), ), ); self::assertEquals( @@ -205,7 +205,7 @@ public function getScope(): string { ], array_map( $map, - $manipulator->getTypeOperators($operators->getScope(), $source, $context, 'Unknown', Operators::ID), + $manipulator->getTypeOperators('Unknown', $operators->getScope(), $source, $context, Operators::ID), ), ); self::assertEquals( @@ -214,7 +214,7 @@ public function getScope(): string { ], array_map( $map, - $manipulator->getTypeOperators($operators->getScope(), $source, $context, 'TestIgnored'), + $manipulator->getTypeOperators('TestIgnored', $operators->getScope(), $source, $context), ), ); } diff --git a/packages/graphql/src/Builder/Types/InputObject.php b/packages/graphql/src/Builder/Types/InputObject.php index 5a72d8953..e0c517273 100644 --- a/packages/graphql/src/Builder/Types/InputObject.php +++ b/packages/graphql/src/Builder/Types/InputObject.php @@ -139,7 +139,7 @@ protected function getOperators( ): array { $type = $this->getTypeForOperators(); $operators = $type - ? $manipulator->getTypeOperators($this->getScope(), $source, $context, $type) + ? $manipulator->getTypeOperators($type, $this->getScope(), $source, $context) : []; return $operators; @@ -336,7 +336,7 @@ protected function getFieldOperator( $type = $this->getTypeForFieldOperator(); if ($type) { - $operators = $manipulator->getTypeOperators($this->getScope(), $field, $context, $type); + $operators = $manipulator->getTypeOperators($type, $this->getScope(), $field, $context); $operator = reset($operators) ?: null; } } diff --git a/packages/graphql/src/SearchBy/Types/Condition/Type.php b/packages/graphql/src/SearchBy/Types/Condition/Type.php index 077a72bce..ba8d7372f 100644 --- a/packages/graphql/src/SearchBy/Types/Condition/Type.php +++ b/packages/graphql/src/SearchBy/Types/Condition/Type.php @@ -76,10 +76,10 @@ protected function getFieldOperator( ): ?OperatorContract { return match (true) { $field->isScalar(), $field->isEnum() => $manipulator->getOperator( + SearchByOperatorConditionDirective::class, $this->getScope(), $field, $context, - SearchByOperatorConditionDirective::class, ), $field->isObject() => parent::getFieldOperator($manipulator, $field, $context), default => throw new NotImplemented($field), diff --git a/packages/graphql/src/SearchBy/Types/Enumeration.php b/packages/graphql/src/SearchBy/Types/Enumeration.php index 58bd6b29f..177417ca4 100644 --- a/packages/graphql/src/SearchBy/Types/Enumeration.php +++ b/packages/graphql/src/SearchBy/Types/Enumeration.php @@ -48,8 +48,8 @@ public function getTypeDefinition( $type = $manipulator->getTypeSource($source->getType()); $scope = Directive::getScope(); $extras = $type->isNullable() ? [Operators::Null] : []; - $operators = $manipulator->getTypeOperators($scope, $type, $context, $type->getTypeName(), ...$extras) - ?: $manipulator->getTypeOperators($scope, $type, $context, Operators::Enum, ...$extras); + $operators = $manipulator->getTypeOperators($type->getTypeName(), $scope, $type, $context, ...$extras) + ?: $manipulator->getTypeOperators(Operators::Enum, $scope, $type, $context, ...$extras); if (!$operators) { return null; diff --git a/packages/graphql/src/SearchBy/Types/Scalar.php b/packages/graphql/src/SearchBy/Types/Scalar.php index d4f1fc569..3620172b9 100644 --- a/packages/graphql/src/SearchBy/Types/Scalar.php +++ b/packages/graphql/src/SearchBy/Types/Scalar.php @@ -48,7 +48,7 @@ public function getTypeDefinition( $type = $manipulator->getTypeSource($source->getType()); $scope = Directive::getScope(); $extras = $type->isNullable() ? [Operators::Null] : []; - $operators = $manipulator->getTypeOperators($scope, $type, $context, $type->getTypeName(), ...$extras); + $operators = $manipulator->getTypeOperators($type->getTypeName(), $scope, $type, $context, ...$extras); if (!$operators) { return null; diff --git a/packages/graphql/src/SortBy/Types/Clause/Type.php b/packages/graphql/src/SortBy/Types/Clause/Type.php index e8702086d..c7e5a4a23 100644 --- a/packages/graphql/src/SortBy/Types/Clause/Type.php +++ b/packages/graphql/src/SortBy/Types/Clause/Type.php @@ -96,10 +96,10 @@ protected function getFieldOperator( ): ?OperatorContract { return match (true) { $field->isScalar(), $field->isEnum() => $manipulator->getOperator( + SortByOperatorSortDirective::class, $this->getScope(), $field, $context, - SortByOperatorSortDirective::class, ), $field->isObject() => parent::getFieldOperator($manipulator, $field, $context), default => throw new NotImplemented($field), From 2f4b37ed5cd2833ef36dfe8ee51ce7759a03c6ee Mon Sep 17 00:00:00 2001 From: Aleksei Lebedev <1329824+LastDragon-ru@users.noreply.github.com> Date: Mon, 12 Feb 2024 14:32:00 +0400 Subject: [PATCH 15/15] Directive-operator location fixes. --- packages/graphql/UPGRADE.md | 2 ++ .../Builder/Directives/OperatorDirective.php | 30 +++++++++++-------- .../Builder/Directives/OperatorsDirective.php | 3 +- .../DirectiveTest/Scout.expected.graphql | 1 - .../src/SortBy/Operators/Extra/Random.php | 16 ---------- 5 files changed, 22 insertions(+), 30 deletions(-) diff --git a/packages/graphql/UPGRADE.md b/packages/graphql/UPGRADE.md index fe384cd6c..54ea3bdc6 100644 --- a/packages/graphql/UPGRADE.md +++ b/packages/graphql/UPGRADE.md @@ -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): diff --git a/packages/graphql/src/Builder/Directives/OperatorDirective.php b/packages/graphql/src/Builder/Directives/OperatorDirective.php index f49e0e0d5..2bc0a40c9 100644 --- a/packages/graphql/src/Builder/Directives/OperatorDirective.php +++ b/packages/graphql/src/Builder/Directives/OperatorDirective.php @@ -7,15 +7,15 @@ 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( @@ -27,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, ]; - - if (is_a(static::class, Scope::class, true)) { - $locations[] = DirectiveLocation::SCALAR; - $locations[] = DirectiveLocation::ENUM; - } - - return $locations; } #[Override] 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 << - // ========================================================================= - /** - * @inheritDoc - */ - #[Override] - protected static function getDirectiveLocations(): array { - return array_merge(parent::getDirectiveLocations(), [ - DirectiveLocation::FIELD_DEFINITION, - ]); - } - // - // // ========================================================================= #[Override]