Skip to content
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
fb506ef
Add IDeprecationProvider to IObjectTypeDefinition
glen-84 Jul 29, 2026
09e48f9
Add EnableObjectDeprecation option and `@deprecated` OBJECT location
glen-84 Jul 29, 2026
5ede742
Add object type deprecation configuration and descriptor API
glen-84 Jul 29, 2026
c2ce449
Read `@deprecated` on object types from SDL and extensions
glen-84 Jul 29, 2026
4ed7d06
Infer object type deprecation from `[GraphQLDeprecated]`
glen-84 Jul 30, 2026
81bc7f9
Add object type deprecation to the mutable type system
glen-84 Jul 30, 2026
09178e4
Print `@deprecated` on object types in both formatters
glen-84 Jul 30, 2026
62e3ba0
Expose `@deprecated` on object types through introspection
glen-84 Jul 30, 2026
1ac265f
Reject a non-deprecated field returning a deprecated object type
glen-84 Jul 31, 2026
b472c4f
Merge object type deprecation in Fusion composition
glen-84 Jul 31, 2026
3a2b07d
Carry object type deprecation through Fusion schema completion
glen-84 Jul 31, 2026
73e3b66
Merge remote-tracking branch 'origin/main' into gai/deprecated-on-obj…
glen-84 Jul 31, 2026
824b89b
Expose object type deprecation through Fusion introspection
glen-84 Jul 31, 2026
876ece1
Detect and download object type deprecation in the introspection client
glen-84 Jul 31, 2026
fdf8596
[Website] Document object type deprecation
glen-84 Aug 3, 2026
65ba678
Reject a merged deprecated type returned by a non-deprecated field
glen-84 Aug 3, 2026
b77fbbd
Gate object type deprecation during Fusion schema completion
glen-84 Aug 3, 2026
6a8cd57
Test object type deprecation via the real schema-type descriptor path
glen-84 Aug 3, 2026
a5c329f
Merge remote-tracking branch 'origin/main' into gai/deprecated-on-obj…
glen-84 Aug 3, 2026
bf7878e
Cover options copying with snapshots and simplify FusionOptions.Clone
glen-84 Aug 3, 2026
359956b
Drop the unwritten spec reference from the deprecated-type rule
glen-84 Aug 3, 2026
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
2 changes: 2 additions & 0 deletions dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ autonumber
backplane
backpressure
Badurina
Baiji
bananacakepop
basicsaga
bbox
Expand Down Expand Up @@ -65,6 +66,7 @@ debuggable
decompile
deepagents
depersist
deprecatable
deprioritization
deprioritized
dexto
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ namespace HotChocolate;

/// <summary>
/// Denotes a deprecated field on a GraphQL type, a deprecated value on a
/// GraphQL enum, or a deprecated GraphQL directive definition.
/// GraphQL enum, a deprecated GraphQL directive definition, or a deprecated
/// GraphQL object type.
/// </summary>
[AttributeUsage(AttributeTargets.Class // Required for directive definitions
| AttributeTargets.Field // Required for enum values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,30 @@ namespace HotChocolate.Serialization;
public static class SchemaDebugFormatter
{
public static ObjectTypeDefinitionNode Format(IObjectTypeDefinition type)
=> new ObjectTypeDefinitionNode(
{
var directives = type.Directives.Select(Format).ToList();

if (type.IsDeprecated)
{
var deprecatedDirective = new DirectiveNode(
DirectiveNames.Deprecated.Name,
new ArgumentNode(
DirectiveNames.Deprecated.Arguments.Reason,
type.DeprecationReason ?? DirectiveNames.Deprecated.Arguments.DefaultReason));

directives.Insert(0, deprecatedDirective);
}

return new ObjectTypeDefinitionNode(
null,
new NameNode(type.Name),
type.Description is null
? null
: new StringValueNode(type.Description),
type.Directives.Select(Format).ToArray(),
directives,
type.Implements.Select(FormatTypeRef).Cast<NamedTypeNode>().ToArray(),
type.Fields.Where(t => !t.IsIntrospectionField).Select(Format).ToArray());
}

public static InterfaceTypeDefinitionNode Format(IInterfaceTypeDefinition type)
=> new InterfaceTypeDefinitionNode(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ public override void VisitObjectType(IObjectTypeDefinition type, VisitorContext
VisitDirectives(type.Directives, context);
var directives = (List<DirectiveNode>)context.Result!;

directives = ApplyDeprecatedDirective(type, directives);

VisitOutputFields(type.Fields, context);
var fields = (List<FieldDefinitionNode>)context.Result!;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,10 @@ namespace HotChocolate.Types;
/// </summary>
public interface IObjectTypeDefinition
: IComplexTypeDefinition
, ISyntaxNodeProvider<ObjectTypeDefinitionNode>;
, IDeprecationProvider
, ISyntaxNodeProvider<ObjectTypeDefinitionNode>
{
bool IDeprecationProvider.IsDeprecated => false;

string? IDeprecationProvider.DeprecationReason => null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ internal static class LogEntryCodes
public const string DirectiveDefinitionSelfApplication = "HCV0027";
public const string IncompatibleArgumentDefaultValue = "HCV0028";
public const string IncompatibleInputFieldDefaultValue = "HCV0029";
public const string InvalidObjectDeprecation = "HCV0030";
}
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,21 @@ public static LogEntry InvalidMemberName(ITypeSystemMember member)
.Build();
}

public static LogEntry InvalidObjectDeprecation(
IOutputFieldDefinition field,
IObjectTypeDefinition objectType)
{
return LogEntryBuilder.New()
.SetMessage(
LogEntryHelper_InvalidObjectDeprecation,
field.Coordinate.ToString(),
objectType.Name)
.SetCode(LogEntryCodes.InvalidObjectDeprecation)
.SetSeverity(LogSeverity.Error)
.SetTypeSystemMember(field)
.Build();
}

public static LogEntry InvalidOneOfField(IInputValueDefinition inputField)
{
return LogEntryBuilder.New()
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@
<data name="LogEntryHelper_InvalidMemberName" xml:space="preserve">
<value>The name of the type system member '{0}' must not start with two underscores '__'.</value>
</data>
<data name="LogEntryHelper_InvalidObjectDeprecation" xml:space="preserve">
<value>The type of '{0}' is the deprecated type '{1}'. Either deprecate the field or change its return type.</value>
</data>
<data name="LogEntryHelper_InvalidOneOfField" xml:space="preserve">
<value>The OneOf Input Object field '{0}' must be nullable and must not have a default value.</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using HotChocolate.Events;
using HotChocolate.Events.Contracts;
using HotChocolate.Types;
using static HotChocolate.Logging.LogEntryHelper;

namespace HotChocolate.Rules;

/// <summary>
/// A field that is not deprecated must not return a deprecated object type.
/// </summary>
public sealed class ValidObjectDeprecationRule : IValidationEventHandler<OutputFieldEvent>
{
/// <summary>
/// Checks that a field which is not deprecated does not return a deprecated object type.
/// </summary>
public void Handle(OutputFieldEvent @event, ValidationContext context)
{
var field = @event.OutputField;

if (field.IsDeprecated)
{
return;
}

if (field.Type.NamedType() is IObjectTypeDefinition { IsDeprecated: true } objectType)
{
context.Log.Write(InvalidObjectDeprecation(field, objectType));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public void AddDefaultRules()
_rules.Add(new ValidDeprecationRule());
_rules.Add(new ValidImplementationsRule());
_rules.Add(new ValidNameRule());
_rules.Add(new ValidObjectDeprecationRule());
_rules.Add(new ValidOneOfFieldRule());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public void Validate(
EnsureFieldNamesAreValid(interfaceType, errors);
EnsureInterfacesAreCorrectlyImplemented(interfaceType, errors);
EnsureArgumentDeprecationIsValid(interfaceType, errors);
EnsureObjectDeprecationIsValid(interfaceType, errors);
EnsureDefaultValuesAreValid(interfaceType, errors);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public void Validate(
EnsureFieldNamesAreValid(objectType, errors);
EnsureInterfacesAreCorrectlyImplemented(objectType, errors);
EnsureArgumentDeprecationIsValid(objectType, errors);
EnsureObjectDeprecationIsValid(objectType, errors);
EnsureDefaultValuesAreValid(objectType, errors);

if (nodeType?.IsAssignableFrom(objectType) == true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,24 @@ public static void EnsureArgumentDeprecationIsValid(
}
}

public static void EnsureObjectDeprecationIsValid(
IComplexTypeDefinition type,
ICollection<ISchemaError> errors)
{
foreach (var field in type.Fields)
{
if (field.IsDeprecated)
{
continue;
}

if (field.Type.NamedType() is IObjectTypeDefinition { IsDeprecated: true } objectType)
{
errors.Add(InvalidObjectDeprecation(field, objectType));
}
}
}

public static void EnsureDefaultValuesAreValid(
IComplexTypeDefinition type,
ICollection<ISchemaError> errors)
Expand Down
5 changes: 5 additions & 0 deletions src/HotChocolate/Core/src/Types/IReadOnlySchemaOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ public interface IReadOnlySchemaOptions
/// </summary>
bool EnableDirectiveIntrospection { get; }

/// <summary>
/// Defines if the experimental object type deprecation feature shall be enabled.
/// </summary>
bool EnableObjectDeprecation { get; }

/// <summary>
/// The default directive visibility when directive introspection is enabled.
/// </summary>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/HotChocolate/Core/src/Types/Properties/TypeResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ In some cases, you need to provide options to alter GraphQL's execution behavior
<data name="ObjectFieldDescriptorBase_FieldType" xml:space="preserve">
<value>The field-type must be an output-type.</value>
</data>
<data name="ObjectTypeDescriptor_Deprecated_NotEnabled" xml:space="preserve">
<value>The object type `{0}` cannot be deprecated because `SchemaOptions.EnableObjectDeprecation` is not enabled.</value>
</data>
<data name="ObjectTypeDescriptor_InterfaceBaseClass" xml:space="preserve">
<value>The interface base class cannot be used as interface implementation declaration.</value>
</data>
Expand Down Expand Up @@ -900,6 +903,9 @@ Type: `{0}`</value>
<data name="ErrorHelper_RequiredFieldCannotBeDeprecated" xml:space="preserve">
<value>Required input field {0} cannot be deprecated.</value>
</data>
<data name="ErrorHelper_InvalidObjectDeprecation" xml:space="preserve">
<value>The type of `{0}` is the deprecated type `{1}`. Either deprecate the field or change its return type.</value>
</data>
<data name="ErrorHelper_InterfaceHasNoImplementation" xml:space="preserve">
<value>There is no object type implementing interface `{0}`.</value>
</data>
Expand Down
1 change: 1 addition & 0 deletions src/HotChocolate/Core/src/Types/SchemaBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ private SchemaBuilder()
typeInterceptors.TryAdd(new IntrospectionTypeInterceptor());
typeInterceptors.TryAdd(new InterfaceCompletionTypeInterceptor());
typeInterceptors.TryAdd(new MiddlewareValidationTypeInterceptor());
typeInterceptors.TryAdd(new ObjectDeprecationTypeInterceptor());
typeInterceptors.TryAdd(new StoreGlobalPagingOptionsTypeInterceptor());
typeInterceptors.TryAdd(new StoreGlobalSchemaOptionsTypeInterceptor());
typeInterceptors.TryAdd(new OptInFeaturesTypeInterceptor());
Expand Down
4 changes: 4 additions & 0 deletions src/HotChocolate/Core/src/Types/SchemaOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ public FieldBindingFlags DefaultFieldBindingFlags
/// <inheritdoc cref="IReadOnlySchemaOptions.EnableDirectiveIntrospection"/>
public bool EnableDirectiveIntrospection { get; set; }

/// <inheritdoc cref="IReadOnlySchemaOptions.EnableObjectDeprecation"/>
public bool EnableObjectDeprecation { get; set; }

/// <inheritdoc cref="IReadOnlySchemaOptions.DefaultDirectiveVisibility"/>
public DirectiveVisibility DefaultDirectiveVisibility { get; set; } =
DirectiveVisibility.Public;
Expand Down Expand Up @@ -215,6 +218,7 @@ public static SchemaOptions FromOptions(IReadOnlySchemaOptions options)
FieldMiddleware = options.FieldMiddleware,
DefaultBindingBehavior = options.DefaultBindingBehavior,
EnableDirectiveIntrospection = options.EnableDirectiveIntrospection,
EnableObjectDeprecation = options.EnableObjectDeprecation,
DefaultDirectiveVisibility = options.DefaultDirectiveVisibility,
DisableInternalDirectives = options.DisableInternalDirectives,
DefaultResolverStrategy = options.DefaultResolverStrategy,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ public ObjectTypeConfiguration(
FieldBindingType = runtimeType;
}

/// <summary>
/// Gets or sets the deprecation reason of this object type.
/// </summary>
public string? DeprecationReason { get; set; }

/// <summary>
/// Gets or sets the .net type representation of this type.
/// </summary>
Expand Down Expand Up @@ -279,6 +284,7 @@ protected internal void MergeInto(ObjectTypeConfiguration target)
}
}

target.DeprecationReason ??= DeprecationReason;
target.IsOfType ??= IsOfType;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ public interface IObjectTypeDescriptor
/// <param name="value">The object type description.</param>
IObjectTypeDescriptor Description(string? value);

/// <summary>
/// Deprecates the object type.
/// </summary>
/// <param name="reason">The reason why this object type is deprecated.</param>
IObjectTypeDescriptor Deprecated(string? reason);

/// <summary>
/// Deprecates the object type.
/// </summary>
IObjectTypeDescriptor Deprecated();

/// <summary>
/// Specifies an interface that is implemented by the
/// <see cref="ObjectType"/>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ public interface IObjectTypeDescriptor<TRuntimeType>
/// <param name="value">The object type description.</param>
IObjectTypeDescriptor<TRuntimeType> Description(string? value);

/// <summary>
/// Deprecates the object type.
/// </summary>
/// <param name="reason">The reason why this object type is deprecated.</param>
IObjectTypeDescriptor<TRuntimeType> Deprecated(string? reason);

/// <summary>
/// Deprecates the object type.
/// </summary>
IObjectTypeDescriptor<TRuntimeType> Deprecated();

/// <summary>
/// Defines the field binding behavior.
///
Expand Down
Loading
Loading