Skip to content

Commit

Permalink
Fixed issue with default values on mutations. (#6776)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib committed Dec 15, 2023
1 parent 3e527b7 commit 60fc2d2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ private void TryApplyInputConvention(
argument.Parameter?.ParameterType ??
typeof(object);

var argumentType = _completionContext.GetType<IInputType>(argument.Type!);

var formatter =
argument.Formatters.Count switch
{
Expand All @@ -238,13 +240,24 @@ private void TryApplyInputConvention(
_ => new AggregateInputValueFormatter(argument.Formatters)
};

var defaultValue = argument.DefaultValue;

if(defaultValue is null && argument.RuntimeDefaultValue is not null)
{
defaultValue =
_context.InputFormatter.FormatValue(
argument.RuntimeDefaultValue,
argumentType,
Path.Root);
}

resolverArguments.Add(
new ResolverArgument(
argument.Name,
new FieldCoordinate(inputTypeName, argument.Name),
_completionContext.GetType<IInputType>(argument.Type!),
runtimeType,
argument.DefaultValue,
defaultValue,
formatter));
}

Expand Down
18 changes: 12 additions & 6 deletions src/HotChocolate/Core/src/Types/Internal/FieldInitHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,20 @@ public static class FieldInitHelper
IInputType argumentType,
FieldCoordinate argumentCoordinate)
{
var defaultValue = argumentDefinition.DefaultValue;

try
{
return argumentDefinition.RuntimeDefaultValue != null
? context.DescriptorContext.InputFormatter.FormatValue(
argumentDefinition.RuntimeDefaultValue,
argumentType,
Path.Root)
: argumentDefinition.DefaultValue;
if(defaultValue is null && argumentDefinition.RuntimeDefaultValue is not null)
{
defaultValue =
context.DescriptorContext.InputFormatter.FormatValue(
argumentDefinition.RuntimeDefaultValue,
argumentType,
Path.Root);
}

return defaultValue;
}
catch (Exception ex)
{
Expand Down

0 comments on commit 60fc2d2

Please sign in to comment.