diff --git a/src/HotChocolate/Data/src/Data/Filters/FilterFieldDescriptor.cs b/src/HotChocolate/Data/src/Data/Filters/FilterFieldDescriptor.cs index 80b449d87fe..fba71b666c6 100644 --- a/src/HotChocolate/Data/src/Data/Filters/FilterFieldDescriptor.cs +++ b/src/HotChocolate/Data/src/Data/Filters/FilterFieldDescriptor.cs @@ -35,6 +35,11 @@ protected FilterFieldDescriptor( Configuration.Description = convention.GetFieldDescription(member); Configuration.Type = convention.GetFieldType(member); Configuration.Scope = scope; + + if (context.Naming.IsDeprecated(member, out var reason)) + { + Deprecated(reason); + } } protected FilterFieldDescriptor( diff --git a/src/HotChocolate/Data/src/Data/Sorting/SortFieldDescriptor.cs b/src/HotChocolate/Data/src/Data/Sorting/SortFieldDescriptor.cs index 6cc6e1054d0..9adbf54dc9f 100644 --- a/src/HotChocolate/Data/src/Data/Sorting/SortFieldDescriptor.cs +++ b/src/HotChocolate/Data/src/Data/Sorting/SortFieldDescriptor.cs @@ -46,6 +46,11 @@ protected SortFieldDescriptor(IDescriptorContext context, string? scope, MemberI Configuration.Type = convention.GetFieldType(member); Configuration.Scope = scope; Configuration.Flags = CoreFieldFlags.SortOperationField; + + if (context.Naming.IsDeprecated(member, out var reason)) + { + Deprecated(reason); + } } protected internal SortFieldDescriptor(IDescriptorContext context, string? scope) diff --git a/src/HotChocolate/Data/test/Data.Filters.Tests/FilterInputTypeTest.cs b/src/HotChocolate/Data/test/Data.Filters.Tests/FilterInputTypeTest.cs index 0926dc03e85..fb3e9c19150 100644 --- a/src/HotChocolate/Data/test/Data.Filters.Tests/FilterInputTypeTest.cs +++ b/src/HotChocolate/Data/test/Data.Filters.Tests/FilterInputTypeTest.cs @@ -407,6 +407,18 @@ public async Task Execute_CoerceWhereArgument_MatchesSnapshot() result.MatchSnapshot(); } + [Fact] + public void FilterInputType_ShouldInferDeprecatedDirective_ForDeprecatedFields() + { + // arrange + // act + var schema = CreateSchema( + s => s.AddType(new FilterInputType())); + + // assert + schema.MatchSnapshot(); + } + public class FooDirectiveType : DirectiveType { @@ -608,4 +620,8 @@ public class FilterWithStruct } public record struct ExampleValueType(string Foo, string Bar); + + public record TypeWithDeprecatedField( + string Foo, + [property: GraphQLDeprecated("old")] string? DeprecatedField = null); } diff --git a/src/HotChocolate/Data/test/Data.Filters.Tests/__snapshots__/FilterInputTypeTest.FilterInputType_ShouldInferDeprecatedDirective_ForDeprecatedFields.graphql b/src/HotChocolate/Data/test/Data.Filters.Tests/__snapshots__/FilterInputTypeTest.FilterInputType_ShouldInferDeprecatedDirective_ForDeprecatedFields.graphql new file mode 100644 index 00000000000..f49bb4eff82 --- /dev/null +++ b/src/HotChocolate/Data/test/Data.Filters.Tests/__snapshots__/FilterInputTypeTest.FilterInputType_ShouldInferDeprecatedDirective_ForDeprecatedFields.graphql @@ -0,0 +1,29 @@ +schema { + query: Query +} + +type Query { + foo: String +} + +input StringOperationFilterInput { + and: [StringOperationFilterInput!] + or: [StringOperationFilterInput!] + eq: String + neq: String + contains: String + ncontains: String + in: [String] + nin: [String] + startsWith: String + nstartsWith: String + endsWith: String + nendsWith: String +} + +input TypeWithDeprecatedFieldFilterInput { + and: [TypeWithDeprecatedFieldFilterInput!] + or: [TypeWithDeprecatedFieldFilterInput!] + foo: StringOperationFilterInput + deprecatedField: StringOperationFilterInput @deprecated(reason: "old") +} diff --git a/src/HotChocolate/Data/test/Data.Sorting.Tests/SortInputTypeTests.cs b/src/HotChocolate/Data/test/Data.Sorting.Tests/SortInputTypeTests.cs index 989786b6d15..4b67486e75c 100644 --- a/src/HotChocolate/Data/test/Data.Sorting.Tests/SortInputTypeTests.cs +++ b/src/HotChocolate/Data/test/Data.Sorting.Tests/SortInputTypeTests.cs @@ -237,6 +237,18 @@ public void SortInputType_Should_InfereType_When_ItIsAInterface() schema.ToString().MatchSnapshot(); } + [Fact] + public void SortInputType_ShouldInferDeprecatedDirective_ForDeprecatedFields() + { + // arrange + // act + var schema = CreateSchema( + s => s.AddType(new SortInputType())); + + // assert + schema.MatchSnapshot(); + } + public class IgnoreTest { public int Id { get; set; } @@ -368,4 +380,8 @@ protected override void Configure(IObjectTypeDescriptor> descripto descriptor.Field(x => x.Root).UseFiltering(); } } + + public record TypeWithDeprecatedField( + string Foo, + [property: GraphQLDeprecated("old")] string? DeprecatedField = null); } diff --git a/src/HotChocolate/Data/test/Data.Sorting.Tests/__snapshots__/SortInputTypeTests.SortInputType_ShouldInferDeprecatedDirective_ForDeprecatedFields.graphql b/src/HotChocolate/Data/test/Data.Sorting.Tests/__snapshots__/SortInputTypeTests.SortInputType_ShouldInferDeprecatedDirective_ForDeprecatedFields.graphql new file mode 100644 index 00000000000..40c49018813 --- /dev/null +++ b/src/HotChocolate/Data/test/Data.Sorting.Tests/__snapshots__/SortInputTypeTests.SortInputType_ShouldInferDeprecatedDirective_ForDeprecatedFields.graphql @@ -0,0 +1,17 @@ +schema { + query: Query +} + +type Query { + foo: String +} + +input TypeWithDeprecatedFieldSortInput { + foo: SortEnumType + deprecatedField: SortEnumType @deprecated(reason: "old") +} + +enum SortEnumType { + ASC + DESC +}