Skip to content

Commit

Permalink
Fix Date scalar trying to parse Illuminate\Support\Carbon as `str…
Browse files Browse the repository at this point in the history
…ing`
  • Loading branch information
danbka33 authored Mar 1, 2024
1 parent 305baea commit 80adc58
Show file tree
Hide file tree
Showing 26 changed files with 142 additions and 111 deletions.
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

- Fix `Date` scalar trying to parse `Illuminate\Support\Carbon` as `string` https://github.com/nuwave/lighthouse/pull/2470

## v6.34.0

### Added
Expand Down
3 changes: 1 addition & 2 deletions src/Schema/AST/ASTBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,7 @@ protected function missingBaseDefinition(string $typeName, ObjectTypeExtensionNo
protected function assertExtensionMatchesDefinition(
ObjectTypeExtensionNode|InputObjectTypeExtensionNode|InterfaceTypeExtensionNode|ScalarTypeExtensionNode|EnumTypeExtensionNode|UnionTypeExtensionNode $extension,
ObjectTypeDefinitionNode|InputObjectTypeDefinitionNode|InterfaceTypeDefinitionNode|ScalarTypeDefinitionNode|EnumTypeDefinitionNode|UnionTypeDefinitionNode $definition,
): void
{
): void {
if (static::EXTENSION_TO_DEFINITION_CLASS[$extension::class] !== $definition::class) {
throw new DefinitionException("The type extension {$extension->name->value} of kind {$extension->kind} can not extend a definition of kind {$definition->kind}.");
}
Expand Down
36 changes: 19 additions & 17 deletions src/Schema/Types/Scalars/DateScalar.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,26 +56,28 @@ public function parseLiteral(Node $valueNode, ?array $variables = null): Illumin
protected function tryParsingDate(mixed $value, string $exceptionClass): IlluminateCarbon
{
try {
if (
is_object($value)
if (is_object($value)) {
if ($value::class === IlluminateCarbon::class) {
return $value;
}

// We want to know if we have exactly a Carbon\Carbon, not a subclass thereof
&& (
$value::class === CarbonCarbon::class
if ($value::class === CarbonCarbon::class
|| $value::class === CarbonImmutable::class
)
) {
$carbon = IlluminateCarbon::create(
$value->year,
$value->month,
$value->day,
$value->hour,
$value->minute,
$value->second,
$value->timezone,
);
assert($carbon instanceof IlluminateCarbon, 'Given we had a valid Carbon instance before, this can not fail.');
) {
$carbon = IlluminateCarbon::create(
$value->year,
$value->month,
$value->day,
$value->hour,
$value->minute,
$value->second,
$value->timezone,
);
assert($carbon instanceof IlluminateCarbon, 'Given we had a valid Carbon instance before, this can not fail.');

return $carbon;
return $carbon;
}
}

return $this->parse($value);
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 8 additions & 7 deletions src/Tracing/FederatedTracing/Proto/ContextualizedStats.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/Tracing/FederatedTracing/Proto/FieldStat.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/Tracing/FederatedTracing/Proto/PathErrorStats.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 8 additions & 7 deletions src/Tracing/FederatedTracing/Proto/QueryLatencyStats.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions src/Tracing/FederatedTracing/Proto/Report.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 80adc58

Please sign in to comment.