|
| 1 | +using HotChocolate.Configuration; |
1 | 2 | using HotChocolate.Data.Sorting;
|
2 | 3 | using HotChocolate.Data.Sorting.Expressions;
|
3 | 4 | using HotChocolate.Language;
|
4 | 5 | using HotChocolate.Types;
|
| 6 | +using HotChocolate.Types.Descriptors.Configurations; |
5 | 7 |
|
6 | 8 | namespace HotChocolate.Data.Tests;
|
7 | 9 |
|
@@ -237,6 +239,35 @@ public void SortInputType_Should_InfereType_When_ItIsAInterface()
|
237 | 239 | schema.ToString().MatchSnapshot();
|
238 | 240 | }
|
239 | 241 |
|
| 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 | + |
240 | 271 | public class IgnoreTest
|
241 | 272 | {
|
242 | 273 | public int Id { get; set; }
|
|
0 commit comments