Skip to content

Commit

Permalink
Handled optional values in CoerceArgumentValue<T> (#7449)
Browse files Browse the repository at this point in the history
  • Loading branch information
glen-84 authored Sep 14, 2024
1 parent 136ab5a commit e2e4335
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ private T CoerceArgumentValue<T>(ArgumentValue argument)
return default!;
}

if (value is IOptional optional)
{
return (T)optional.Value!;
}

if (value is T castedValue ||
_operationContext.Converter.TryConvert(value, out castedValue))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,7 @@ public async Task Mutation_Aggregate_Error_Not_Mapped()
}

[Fact]
public async Task Mutation_With_Optional_Arg()
public async Task Mutation_With_Optional_Args()
{
var result =
await new ServiceCollection()
Expand All @@ -1170,7 +1170,7 @@ public async Task Mutation_With_Optional_Arg()
.ExecuteRequestAsync(
"""
mutation {
doSomething(input: { }) {
doSomething(input: { optional1: "something", optional2: null }) {
string
}
}
Expand All @@ -1181,7 +1181,7 @@ public async Task Mutation_With_Optional_Arg()
{
"data": {
"doSomething": {
"string": "nothing"
"string": "something, null, unspecified"
}
}
}
Expand Down Expand Up @@ -1702,8 +1702,11 @@ public override void OnConfigure(

public class MutationWithOptionalArg
{
public string DoSomething(Optional<string?> something)
=> something.Value ?? "nothing";
public string DoSomething(
Optional<string?> optional1,
Optional<string?> optional2,
Optional<string?> optional3)
=> string.Join(", ", optional1.ToString(), optional2.ToString(), optional3.ToString());
}

public class MutationWithInterfaces
Expand Down

0 comments on commit e2e4335

Please sign in to comment.