diff --git a/packages/graphql/src/SearchBy/Directives/DirectiveTest.php b/packages/graphql/src/SearchBy/Directives/DirectiveTest.php index cf71f4d86..d93de1669 100644 --- a/packages/graphql/src/SearchBy/Directives/DirectiveTest.php +++ b/packages/graphql/src/SearchBy/Directives/DirectiveTest.php @@ -402,10 +402,17 @@ public function dataProviderHandleBuilder(): array { from "tmp" where - not ( - ("a" != ?) - and ( - ("a" = ?) or ("b" != ?) + ( + not ( + ( + ("a" != ?) + and ( + ( + ("a" = ?) + or ("b" != ?) + ) + ) + ) ) ) SQL diff --git a/packages/graphql/src/SearchBy/Operators/Logical/AllOfTest.php b/packages/graphql/src/SearchBy/Operators/Logical/AllOfTest.php index e0c948919..166a2fb66 100644 --- a/packages/graphql/src/SearchBy/Operators/Logical/AllOfTest.php +++ b/packages/graphql/src/SearchBy/Operators/Logical/AllOfTest.php @@ -88,7 +88,7 @@ public function dataProviderCall(): array { new ArrayDataProvider([ 'property' => [ [ - 'query' => 'select * from "tmp" where ("a" = ?) and ("b" != ?)', + 'query' => 'select * from "tmp" where (("a" = ?) and ("b" != ?))', 'bindings' => [ 2, 22, @@ -99,7 +99,7 @@ public function dataProviderCall(): array { ], 'with alias' => [ [ - 'query' => 'select * from "tmp" where ("alias"."a" = ?) and ("alias"."b" != ?)', + 'query' => 'select * from "tmp" where (("alias"."a" = ?) and ("alias"."b" != ?))', 'bindings' => [ 2, 22, diff --git a/packages/graphql/src/SearchBy/Operators/Logical/AnyOfTest.php b/packages/graphql/src/SearchBy/Operators/Logical/AnyOfTest.php index acb916cdf..5a16a8600 100644 --- a/packages/graphql/src/SearchBy/Operators/Logical/AnyOfTest.php +++ b/packages/graphql/src/SearchBy/Operators/Logical/AnyOfTest.php @@ -88,7 +88,7 @@ public function dataProviderCall(): array { new ArrayDataProvider([ 'property' => [ [ - 'query' => 'select * from "tmp" where ("a" = ?) or ("b" != ?)', + 'query' => 'select * from "tmp" where (("a" = ?) or ("b" != ?))', 'bindings' => [ 2, 22, @@ -99,7 +99,7 @@ public function dataProviderCall(): array { ], 'with alias' => [ [ - 'query' => 'select * from "tmp" where ("alias"."a" = ?) or ("alias"."b" != ?)', + 'query' => 'select * from "tmp" where (("alias"."a" = ?) or ("alias"."b" != ?))', 'bindings' => [ 2, 22, diff --git a/packages/graphql/src/SearchBy/Operators/Logical/Logical.php b/packages/graphql/src/SearchBy/Operators/Logical/Logical.php index 1411e4496..15f08a0e0 100644 --- a/packages/graphql/src/SearchBy/Operators/Logical/Logical.php +++ b/packages/graphql/src/SearchBy/Operators/Logical/Logical.php @@ -22,24 +22,28 @@ public function call(Handler $handler, object $builder, Property $property, Argu throw new OperatorUnsupportedBuilder($this, $builder); } - // The last item is the name of the operator not a property - $property = $property->getParent(); - $conditions = $this->getConditions($argument); + $builder->where( + function (EloquentBuilder|QueryBuilder $builder) use ($handler, $property, $argument): void { + // The last item is the name of the operator not a property + $property = $property->getParent(); + $conditions = $this->getConditions($argument); - foreach ($conditions as $arguments) { - $builder->where( - static function (EloquentBuilder|QueryBuilder $builder) use ( - $handler, - $arguments, - $property - ): void { - $handler->handle($builder, $property, $arguments); - }, - null, - null, - $this->getBoolean(), - ); - } + foreach ($conditions as $arguments) { + $builder->where( + static function (EloquentBuilder|QueryBuilder $builder) use ( + $handler, + $arguments, + $property + ): void { + $handler->handle($builder, $property, $arguments); + }, + null, + null, + $this->getBoolean(), + ); + } + }, + ); return $builder; } diff --git a/packages/graphql/src/SearchBy/Operators/Logical/NotTest.php b/packages/graphql/src/SearchBy/Operators/Logical/NotTest.php index 48472124a..e016ca308 100644 --- a/packages/graphql/src/SearchBy/Operators/Logical/NotTest.php +++ b/packages/graphql/src/SearchBy/Operators/Logical/NotTest.php @@ -89,7 +89,7 @@ public function dataProviderCall(): array { new ArrayDataProvider([ 'property' => [ [ - 'query' => 'select * from "tmp" where not ("a" = ?)', + 'query' => 'select * from "tmp" where (not ("a" = ?))', 'bindings' => [ 2, ], @@ -99,7 +99,7 @@ public function dataProviderCall(): array { ], 'with alias' => [ [ - 'query' => 'select * from "tmp" where not ("alias"."a" = ?)', + 'query' => 'select * from "tmp" where (not ("alias"."a" = ?))', 'bindings' => [ 2, ],