Skip to content
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 @@ -89,11 +89,6 @@ public OperationRequest(
Extensions = extensions;
}

/// <summary>
/// Empty Operation Request.
/// </summary>
public static OperationRequest Empty { get; } = new();

/// <summary>
/// Gets the ID of a previously persisted operation that should be executed.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,6 @@ public VariableBatchRequest(
Extensions = extensions;
}

/// <summary>
/// Empty Operation Request.
/// </summary>
public static OperationRequest Empty { get; } = new();

/// <summary>
/// Gets the ID of a previously persisted operation that should be executed.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<SomeQuery>().Create();

var variableDefinitions = new List<VariableDefinitionNode>
{
new VariableDefinitionNode(
null,
new VariableNode("input"),
description: null,
new NamedTypeNode("SomeInput"),
null,
[])
};

var variableValues = JsonDocument.Parse("""{"input": { }}""");
var coercedValues = new Dictionary<string, VariableValue>();
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<InputObjectType<SomeInput>>(t.Value.Type);
Assert.False(Assert.IsType<SomeInput>(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<bool> OptionalField,
[property: DefaultValue(true)] bool Field);

[Fact]
public void Error_When_Value_Is_Null_On_Non_Null_Variable()
{
Expand Down
Loading