1

Gonna love ChatGPT from time to time.

Best version of this method I wrote by hand was 7 lines. Now it's 3.

And it's perfectly readable.

private static DateOnly ParseDateArgument(GraphQLValue? argumentValue, IResolveFieldContext context)
{
return argumentValue switch
{
GraphQLStringValue strVal when DateOnly.TryParse(strVal.Value.ToString(), out var date) => date,
GraphQLVariable varVal when DateOnly.TryParse(context.Variables?.ValueFor(varVal.Name.StringValue)?.ToString(), out var date) => date,
_ => default
};
}

Comments
Add Comment