Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes how arg values will be handled when the input obj is inferred #6632

Merged
merged 1 commit into from
Oct 25, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,32 @@ public async ValueTask InvokeAsync(IMiddlewareContext context)

var arguments = new Dictionary<string, ArgumentValue>(StringComparer.Ordinal);
var preservedArguments = context.ReplaceArguments(arguments);
var inputArgument = preservedArguments[_inputArgumentName];

foreach (var argument in _resolverArguments)
{
input.TryGetValue(argument.Name, out var value);

inputLiteral.TryGetValue(argument.Name, out var valueLiteral);
var omitted = false;
if (!inputLiteral.TryGetValue(argument.Name, out var valueLiteral))
{
omitted = true;
valueLiteral = argument.DefaultValue;
value = null;
}
valueLiteral ??= NullValueNode.Default;

if (!valueLiteral.TryGetValueKind(out var kind))
{
kind = ValueKind.Unknown;
}

arguments.Add(
argument.Name,
new ArgumentValue(
argument,
kind,
true,
inputArgument.IsDefaultValue,
!omitted,
omitted,
value,
valueLiteral));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1137,8 +1137,37 @@ public async Task Mutation_Aggregate_Error_Not_Mapped()

result.MatchSnapshot();
}

[Fact]
public async Task Mutation_With_Optional_Arg()
{
var result =
await new ServiceCollection()
.AddGraphQL()
.AddQueryType(d => d.Field("abc").Resolve("def"))
.AddMutationType<MutationWithOptionalArg>()
.AddMutationConventions()
.ExecuteRequestAsync(
"""
mutation {
doSomething(input: { }) {
string
}
}
""");


result.MatchInlineSnapshot(
"""
{
"data": {
"doSomething": {
"string": "nothing"
}
}
}
""");
}

public class SimpleMutation
{
public string DoSomething(string something)
Expand Down Expand Up @@ -1531,4 +1560,10 @@ public override void OnConfigure(IDescriptorContext context, ObjectFieldDefiniti
}));
}
}

public class MutationWithOptionalArg
{
public string DoSomething(Optional<string?> something)
=> something.Value ?? "nothing";
}
}
Loading