diff --git a/src/HotChocolate/AspNetCore/src/Transport.Abstractions/OperationRequest.cs b/src/HotChocolate/AspNetCore/src/Transport.Abstractions/OperationRequest.cs
index 5d96573aba5..da912174077 100644
--- a/src/HotChocolate/AspNetCore/src/Transport.Abstractions/OperationRequest.cs
+++ b/src/HotChocolate/AspNetCore/src/Transport.Abstractions/OperationRequest.cs
@@ -89,11 +89,6 @@ public OperationRequest(
Extensions = extensions;
}
- ///
- /// Empty Operation Request.
- ///
- public static OperationRequest Empty { get; } = new();
-
///
/// Gets the ID of a previously persisted operation that should be executed.
///
diff --git a/src/HotChocolate/AspNetCore/src/Transport.Abstractions/VariableBatchRequest.cs b/src/HotChocolate/AspNetCore/src/Transport.Abstractions/VariableBatchRequest.cs
index a7e3b7b7484..c33ae6f9736 100644
--- a/src/HotChocolate/AspNetCore/src/Transport.Abstractions/VariableBatchRequest.cs
+++ b/src/HotChocolate/AspNetCore/src/Transport.Abstractions/VariableBatchRequest.cs
@@ -89,11 +89,6 @@ public VariableBatchRequest(
Extensions = extensions;
}
- ///
- /// Empty Operation Request.
- ///
- public static OperationRequest Empty { get; } = new();
-
///
/// Gets the ID of a previously persisted operation that should be executed.
///
diff --git a/src/HotChocolate/AspNetCore/test/Transport.Http.Tests/VariableBatchRequestTests.cs b/src/HotChocolate/AspNetCore/test/Transport.Http.Tests/VariableBatchRequestTests.cs
index f9600a9fb3e..c9f2cf9a10b 100644
--- a/src/HotChocolate/AspNetCore/test/Transport.Http.Tests/VariableBatchRequestTests.cs
+++ b/src/HotChocolate/AspNetCore/test/Transport.Http.Tests/VariableBatchRequestTests.cs
@@ -5,7 +5,7 @@
namespace HotChocolate.Transport.Http;
-public class VariableBatchRequestTestss(TestServerFactory serverFactory) : ServerTestBase(serverFactory)
+public class VariableBatchRequestTests(TestServerFactory serverFactory) : ServerTestBase(serverFactory)
{
[Fact]
public async Task Should_WriteNullValues()
diff --git a/src/HotChocolate/Core/src/Types/Execution/Processing/VariableCoercionHelper.cs b/src/HotChocolate/Core/src/Types/Execution/Processing/VariableCoercionHelper.cs
index a463ceb3686..94a97c4b0d0 100644
--- a/src/HotChocolate/Core/src/Types/Execution/Processing/VariableCoercionHelper.cs
+++ b/src/HotChocolate/Core/src/Types/Execution/Processing/VariableCoercionHelper.cs
@@ -213,7 +213,7 @@ private IValueNode CoerceInputLiteral(
foreach (var field in inputObjectType.Fields)
{
- if (field.DefaultValue is not (null or NullValueNode) && !processedFields.Contains(field.Name))
+ if (field is { IsOptional: false, DefaultValue: not (null or NullValueNode) } && !processedFields.Contains(field.Name))
{
fields.Add(new ObjectFieldNode(field.Name, field.DefaultValue));
}
diff --git a/src/HotChocolate/Core/test/Execution.Tests/Processing/VariableCoercionHelperTests.cs b/src/HotChocolate/Core/test/Execution.Tests/Processing/VariableCoercionHelperTests.cs
index 8ab6a019d5b..0d39bf04578 100644
--- a/src/HotChocolate/Core/test/Execution.Tests/Processing/VariableCoercionHelperTests.cs
+++ b/src/HotChocolate/Core/test/Execution.Tests/Processing/VariableCoercionHelperTests.cs
@@ -298,6 +298,61 @@ public void Coerce_Nullable_ReviewInput_Variable_With_Object()
});
}
+ [Fact]
+ public void Coerce_Empty_Input_Object_With_Optional_And_Default_Value()
+ {
+ // arrange
+ var schema = SchemaBuilder.New().AddQueryType().Create();
+
+ var variableDefinitions = new List
+ {
+ new VariableDefinitionNode(
+ null,
+ new VariableNode("input"),
+ description: null,
+ new NamedTypeNode("SomeInput"),
+ null,
+ [])
+ };
+
+ var variableValues = JsonDocument.Parse("""{"input": { }}""");
+ var coercedValues = new Dictionary();
+ var featureProvider = new MockFeatureProvider();
+ var helper = new VariableCoercionHelper(new());
+
+ // act
+ helper.CoerceVariableValues(
+ schema,
+ variableDefinitions,
+ variableValues.RootElement,
+ coercedValues,
+ featureProvider);
+
+ // assert
+ Assert.Collection(coercedValues,
+ t =>
+ {
+ Assert.Equal("input", t.Key);
+ Assert.IsType>(t.Value.Type);
+ Assert.False(Assert.IsType(t.Value.RuntimeValue).OptionalField.HasValue);
+ t.Value.ValueLiteral.MatchInlineSnapshot(
+ """
+ {
+ field: true
+ }
+ """);
+ });
+ }
+
+ public sealed class SomeQuery
+ {
+ public bool HasOptionalValue(SomeInput input) => input.OptionalField.HasValue;
+ }
+
+ public sealed record SomeInput(
+ [property: DefaultValue(true)] Optional OptionalField,
+ [property: DefaultValue(true)] bool Field);
+
[Fact]
public void Error_When_Value_Is_Null_On_Non_Null_Variable()
{