diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a2d01b9c3..5e4c1a1ef7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add compatibility layer to allow `@middleware` to support Lumen https://github.com/nuwave/lighthouse/pull/786 - Add option `decode` to `@globaldId` to control the result of decoding https://github.com/nuwave/lighthouse/pull/796 +### Fixed + +- Fix querying for falsy values through `@whereConstraints` https://github.com/nuwave/lighthouse/pull/800 + ## [3.6.1](https://github.com/nuwave/lighthouse/compare/v3.6.0...v3.6.1) ### Fixed diff --git a/src/WhereConstraints/WhereConstraintsDirective.php b/src/WhereConstraints/WhereConstraintsDirective.php index 1754cdc730..929aa01b9e 100644 --- a/src/WhereConstraints/WhereConstraintsDirective.php +++ b/src/WhereConstraints/WhereConstraintsDirective.php @@ -61,7 +61,7 @@ function ($builder) use ($notConnectedConstraints): void { } if ($column = $whereConstraints['column'] ?? null) { - if (! $value = $whereConstraints['value']) { + if (! isset($whereConstraints['value'])) { throw new Error( "Did not receive a value to match the WhereConstraints for column {$column}." ); @@ -80,7 +80,7 @@ function ($builder) use ($notConnectedConstraints): void { $builder->{$where}( $column, $whereConstraints['operator'], - $value + $whereConstraints['value'] ); } diff --git a/tests/Integration/WhereConstraints/WhereConstraintsDirectiveTest.php b/tests/Integration/WhereConstraints/WhereConstraintsDirectiveTest.php index 3830501a37..8ff7a08b6a 100644 --- a/tests/Integration/WhereConstraints/WhereConstraintsDirectiveTest.php +++ b/tests/Integration/WhereConstraints/WhereConstraintsDirectiveTest.php @@ -173,7 +173,7 @@ public function itAddsNestedNot(): void */ public function itRejectsInvalidColumnName(): void { - $result = $this->query(' + $this->query(' { users( where: { @@ -192,4 +192,39 @@ public function itRejectsInvalidColumnName(): void 'message' => WhereConstraintsDirective::INVALID_COLUMN_MESSAGE, ]); } + + /** + * @test + */ + public function itQueriesEmptyStrings(): void + { + factory(User::class, 3)->create(); + + $userNamedEmptyString = factory(User::class)->create([ + 'name' => '', + ]); + + $this->query(' + { + users( + where: { + column: "name" + value: "" + } + ) { + id + name + } + } + ')->assertJson([ + 'data' => [ + 'users' => [ + [ + 'id' => $userNamedEmptyString->id, + 'name' => $userNamedEmptyString->name, + ], + ], + ], + ]); + } }