Skip to content
Open
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
65 changes: 65 additions & 0 deletions src/Core/Services/ExecutionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,74 @@ private static bool TryGetPropertyFromParent(
SupportedHotChocolateTypes.SINGLE_TYPE => value is IntValueNode intValueNode ? intValueNode.ToSingle() : ((FloatValueNode)value).ToSingle(),
SupportedHotChocolateTypes.FLOAT_TYPE => value is IntValueNode intValueNode ? intValueNode.ToDouble() : ((FloatValueNode)value).ToDouble(),
SupportedHotChocolateTypes.DECIMAL_TYPE => value is IntValueNode intValueNode ? intValueNode.ToDecimal() : ((FloatValueNode)value).ToDecimal(),
SupportedHotChocolateTypes.DATETIME_TYPE => ParseDateTimeValue(value.Value),
SupportedHotChocolateTypes.DATETIMEOFFSET_TYPE => ParseDateTimeOffsetValue(value.Value),
SupportedHotChocolateTypes.UUID_TYPE => Guid.TryParse(value.Value!.ToString(), out Guid guidValue) ? guidValue : value.Value,
_ => value.Value
Comment on lines +398 to 401
};

static object? ParseDateTimeValue(object? raw)
{
if (raw is null)
{
return null;
}

if (raw is DateTime dt)
{
return dt;
}

if (raw is DateTimeOffset dto)
{
return dto.UtcDateTime;
}

if (raw is string s)
{
// HotChocolate DateTime inputs are supplied as strings; parse them so DB providers
// (notably PostgreSQL) receive a typed parameter instead of text.
if (DateTimeOffset.TryParse(s, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind, out DateTimeOffset parsedDto))
{
return parsedDto.UtcDateTime;
}

if (DateTime.TryParse(s, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind, out DateTime parsedDt))
{
return parsedDt;
Comment on lines +425 to +432
}
}

return raw;
}

static object? ParseDateTimeOffsetValue(object? raw)
{
if (raw is null)
{
return null;
}

if (raw is DateTimeOffset dto)
{
return dto;
}

if (raw is DateTime dt)
{
return new DateTimeOffset(dt);
}

if (raw is string s)
{
if (DateTimeOffset.TryParse(s, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind, out DateTimeOffset parsedDto))
{
return parsedDto;
}
}

return raw;
}
}

/// <summary>
Expand Down
Loading