Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ You can find and compare releases at the [GitHub release page](https://github.co

## Unreleased

### Fixed

- Throw client-safe errors for malformed date literals instead of reporting them as server errors https://github.com/nuwave/lighthouse/pull/2788

## v6.70.0

### Changed
Expand Down
2 changes: 1 addition & 1 deletion src/Schema/Types/Scalars/DateScalar.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function parseLiteral(Node $valueNode, ?array $variables = null): Illumin
try {
return $this->parse($value);
} catch (\Exception $exception) {
throw Error::createLocatedError($exception, $valueNode);
throw new Error($exception->getMessage(), $valueNode);
}
}

Expand Down
19 changes: 19 additions & 0 deletions tests/Unit/Schema/Types/Scalars/DateScalarTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,25 @@ public function testThrowsIfParseLiteralNonString(): void
);
}

public function testThrowsClientSafeErrorIfParseLiteralInvalidDate(): void
{
$error = null;

try {
$this->scalarInstance()->parseLiteral(
new StringValueNode(['value' => 'rolf']),
);
} catch (Error $caught) {
$error = $caught;
}

$this->assertInstanceOf(Error::class, $error);
$this->assertTrue(
$error->isClientSafe(),
'A malformed date literal is client misuse, so it must not be reported as a server error.',
);
}

public function testSerializesCarbonInstance(): void
{
$now = IlluminateCarbon::now();
Expand Down
Loading