Skip to content

Commit

Permalink
Fix querying for falsy values through @whereConstraints (#800)
Browse files Browse the repository at this point in the history
  • Loading branch information
abibby authored and spawnia committed May 21, 2019
1 parent 1eafde0 commit db4e1d4
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/WhereConstraints/WhereConstraintsDirective.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}."
);
Expand All @@ -80,7 +80,7 @@ function ($builder) use ($notConnectedConstraints): void {
$builder->{$where}(
$column,
$whereConstraints['operator'],
$value
$whereConstraints['value']
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public function itAddsNestedNot(): void
*/
public function itRejectsInvalidColumnName(): void
{
$result = $this->query('
$this->query('
{
users(
where: {
Expand All @@ -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,
],
],
],
]);
}
}

0 comments on commit db4e1d4

Please sign in to comment.