Skip to content

Commit 94c7336

Browse files
authored
Fixed array resize condition in SortInputType (#8682)
1 parent beb8bb3 commit 94c7336

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/HotChocolate/Data/src/Data/Sorting/SortInputType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ protected override InputFieldCollection OnCompleteFields(
8686
}
8787
}
8888

89-
if (fields.Length < index)
89+
if (fields.Length > index)
9090
{
9191
Array.Resize(ref fields, index);
9292
}

src/HotChocolate/Data/test/Data.Sorting.Tests/SortInputTypeTests.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
using HotChocolate.Configuration;
12
using HotChocolate.Data.Sorting;
23
using HotChocolate.Data.Sorting.Expressions;
34
using HotChocolate.Language;
45
using HotChocolate.Types;
6+
using HotChocolate.Types.Descriptors.Configurations;
57

68
namespace HotChocolate.Data.Tests;
79

@@ -237,6 +239,35 @@ public void SortInputType_Should_InfereType_When_ItIsAInterface()
237239
schema.ToString().MatchSnapshot();
238240
}
239241

242+
[Fact]
243+
public void SortInput_FieldIgnoredWithTypeInterceptor()
244+
{
245+
// arrange
246+
// act
247+
var schema = CreateSchema(s => s
248+
.TryAddTypeInterceptor(new IgnoreSortInputFieldTypeInterceptor(entityType: typeof(User), fieldName: "id"))
249+
.AddType(new SortInputType<User>()));
250+
251+
// assert
252+
Assert.False(((SortInputType)schema.Types["UserSortInput"]).Fields.ContainsField("id"));
253+
}
254+
255+
private sealed class IgnoreSortInputFieldTypeInterceptor(Type entityType, string fieldName) : TypeInterceptor
256+
{
257+
public override void OnBeforeCompleteType(
258+
ITypeCompletionContext completionContext,
259+
TypeSystemConfiguration configuration)
260+
{
261+
if (configuration is SortInputTypeConfiguration sortInputType
262+
&& sortInputType.EntityType == entityType)
263+
{
264+
sortInputType.Fields.Single(f => f.Name == fieldName).Ignore = true;
265+
}
266+
267+
base.OnBeforeCompleteType(completionContext, configuration);
268+
}
269+
}
270+
240271
public class IgnoreTest
241272
{
242273
public int Id { get; set; }

0 commit comments

Comments
 (0)