Skip to content

Add AOT compatibility annotations to HotChocolate.Types#9511

Open
michaelstaib wants to merge 5 commits intomainfrom
mst/types-aot
Open

Add AOT compatibility annotations to HotChocolate.Types#9511
michaelstaib wants to merge 5 commits intomainfrom
mst/types-aot

Conversation

@michaelstaib
Copy link
Copy Markdown
Member

No description provided.

Copilot AI review requested due to automatic review settings April 8, 2026 06:25
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds Native AOT / trimming compatibility annotations across HotChocolate.Types by introducing DynamicallyAccessedMembers, RequiresDynamicCode / RequiresUnreferencedCode, and targeted suppressions for ILLink/NativeAOT diagnostics, and marks the project as AOT compatible.

Changes:

  • Adds AOT/trimming annotations to public and internal APIs that use reflection, expression compilation, or runtime generic construction.
  • Introduces targeted warning suppressions (UnconditionalSuppressMessage / #pragma) for known-safe or framework-driven reflection patterns.
  • Enables <IsAotCompatible>true</IsAotCompatible> for the HotChocolate.Types project.

Reviewed changes

Copilot reviewed 85 out of 85 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/HotChocolate/Core/src/Types/Utilities/Serialization/InputObjectConstructorResolver.cs Adds trimming suppression for constructor reflection.
src/HotChocolate/Core/src/Types/Utilities/Serialization/InputObjectCompiler.cs Adds trimming/AOT suppressions around runtime type usage and Optional<> construction.
src/HotChocolate/Core/src/Types/Utilities/ReflectionUtils.cs Adds suppressions for property/method traversal in reflection utilities.
src/HotChocolate/Core/src/Types/Utilities/NullableTypeConverter.cs Adds suppression for NullableConverter usage under trimming analysis.
src/HotChocolate/Core/src/Types/Utilities/NullableHelper.cs Adds suppression for compiler-generated nullable metadata reflection.
src/HotChocolate/Core/src/Types/Utilities/ListTypeConverter.cs Marks converter as requiring dynamic/unreferenced code; adds suppressions for reflection-based conversions.
src/HotChocolate/Core/src/Types/Utilities/DictionaryToObjectConverter.cs Adds suppressions for runtime object creation and generic list construction.
src/HotChocolate/Core/src/Types/Utilities/DefaultTypeConverter.cs Adds suppressions around dynamic conversion paths and Activator usage.
src/HotChocolate/Core/src/Types/Types/Relay/Serialization/GlobalIdInputValueFormatter.cs Suppresses IL3050 around Array.CreateInstance usage.
src/HotChocolate/Core/src/Types/Types/Relay/Extensions/RelayIdFieldHelpers.cs Suppresses IL3050 around MakeGenericType for schema type rewriting.
src/HotChocolate/Core/src/Types/Types/Relay/Descriptors/NodeDescriptor~2.cs Adds ILLink warning suppressions around node resolver discovery.
src/HotChocolate/Core/src/Types/Types/Relay/Descriptors/NodeDescriptor~1.cs Adds ILLink warning suppressions around node resolver discovery/configuration.
src/HotChocolate/Core/src/Types/Types/Relay/Descriptors/NodeDescriptor.cs Adds ILLink warning suppressions around node resolver discovery/configuration.
src/HotChocolate/Core/src/Types/Types/Relay/Attributes/NodeAttribute.cs Suppresses reflection analysis warnings around member/method lookup.
src/HotChocolate/Core/src/Types/Types/Pagination/PagingHelper.cs Adds RequiresDynamicCode annotations + suppression at call site.
src/HotChocolate/Core/src/Types/Types/ObjectField.cs Suppresses IL2060/IL3050 around MakeGenericMethod + Invoke caching.
src/HotChocolate/Core/src/Types/Types/NamedTypeBase.cs Suppresses IL2055/IL3050 around MakeGenericType for type identity.
src/HotChocolate/Core/src/Types/Types/KeyValuePairObjectType.cs Suppresses reflection analysis around property lookup.
src/HotChocolate/Core/src/Types/Types/Interceptors/InterfaceCompletionTypeInterceptor.cs Suppresses reflection analysis for interface traversal.
src/HotChocolate/Core/src/Types/Types/Interceptors/FlagEnumTypeInterceptor.cs Suppresses IL3050/IL207x around Enum.GetValues and formatter generic construction.
src/HotChocolate/Core/src/Types/Types/InputParser.cs Suppresses trimming warnings for Activator.CreateInstance usage.
src/HotChocolate/Core/src/Types/Types/Extensions/TypeExtensions.cs Suppresses IL3050 around runtime generic type construction.
src/HotChocolate/Core/src/Types/Types/Extensions/MiddlewareObjectFieldDescriptorExtensions.cs Adds DynamicallyAccessedMembers on middleware type parameters.
src/HotChocolate/Core/src/Types/Types/DirectiveType.Initialization.cs Suppresses IL3050 around DirectiveType<> type identity.
src/HotChocolate/Core/src/Types/Types/Descriptors/ObjectFieldDescriptor.cs Suppresses trimming warning for GetMember call from runtime configuration.
src/HotChocolate/Core/src/Types/Types/Descriptors/InputObjectTypeDescriptor.cs Adds DAM annotation to constructor scanning helper + callsite suppression.
src/HotChocolate/Core/src/Types/Types/Descriptors/DirectiveTypeDescriptor~1.cs Adds DynamicallyAccessedMembers on middleware type parameters.
src/HotChocolate/Core/src/Types/Types/Descriptors/DirectiveTypeDescriptor.cs Adds DynamicallyAccessedMembers on middleware type parameters.
src/HotChocolate/Core/src/Types/Types/Descriptors/Conventions/XmlDocumentationProvider.cs Suppresses trimming warnings for reflected base/interface member lookup.
src/HotChocolate/Core/src/Types/Types/Descriptors/Conventions/XmlDocumentationFileResolver.cs Suppresses single-file/AOT warnings around Assembly.Location/CodeBase.
src/HotChocolate/Core/src/Types/Types/Descriptors/Conventions/ITypeInspector.cs Adds DAM annotations to node resolver method signature.
src/HotChocolate/Core/src/Types/Types/Descriptors/Conventions/DefaultTypeInspector.cs Implements DAM signature + adds targeted suppressions for reflection patterns.
src/HotChocolate/Core/src/Types/Types/Descriptors/Conventions/DefaultNamingConventions.cs Suppresses trimming warnings for enum member reflection.
src/HotChocolate/Core/src/Types/Types/Descriptors/Contracts/IDirectiveTypeDescriptor~1.cs Adds DynamicallyAccessedMembers on middleware type parameters.
src/HotChocolate/Core/src/Types/Types/Descriptors/Contracts/IDirectiveTypeDescriptor.cs Adds DynamicallyAccessedMembers on middleware type parameters.
src/HotChocolate/Core/src/Types/Types/Attributes/UseResolverResultPostProcessorAttribute.cs Adds DAM annotation for generic post-processor type.
src/HotChocolate/Core/src/Types/Types/Attributes/SubscribeAttribute.cs Adds suppressions around MakeGenericMethod and reflection lookup.
src/HotChocolate/Core/src/Types/SchemaBuilder.Setup.cs Adds suppression for interceptor type reflection during schema creation.
src/HotChocolate/Core/src/Types/Resolvers/SubscribeResultHelper.cs Adds suppressions for expression-tree and generic specialization helpers.
src/HotChocolate/Core/src/Types/Resolvers/ResolveResultHelper.cs Adds suppressions for expression-tree and generic specialization helpers.
src/HotChocolate/Core/src/Types/Resolvers/FieldClassMiddlewareFactory.cs Adds DAM annotations + suppressions for reflective middleware creation path.
src/HotChocolate/Core/src/Types/Resolvers/Expressions/TypeInfoExtensions.cs Adds DAM on TypeInfo extension to satisfy trimming analysis.
src/HotChocolate/Core/src/Types/Resolvers/Expressions/Parameters/ServiceExpressionHelper.cs Adds suppressions for expression-tree building helpers.
src/HotChocolate/Core/src/Types/Resolvers/Expressions/Parameters/ScopedStateParameterExpressionBuilder.cs Adds suppressions for expression-tree building helpers.
src/HotChocolate/Core/src/Types/Resolvers/Expressions/Parameters/ParentParameterExpressionBuilder.cs Adds suppressions for expression-tree building helpers.
src/HotChocolate/Core/src/Types/Resolvers/Expressions/Parameters/ParameterExpressionBuilderHelpers.cs Adds DAM annotation for cached context type.
src/HotChocolate/Core/src/Types/Resolvers/Expressions/Parameters/GlobalStateParameterExpressionBuilder.cs Adds suppressions for expression-tree building helpers.
src/HotChocolate/Core/src/Types/Resolvers/Expressions/Parameters/ArgumentParameterExpressionBuilder.cs Adds suppressions for expression-tree building helpers.
src/HotChocolate/Core/src/Types/Resolvers/DirectiveClassMiddlewareFactory.cs Adds DAM annotations + suppressions for reflective middleware creation path.
src/HotChocolate/Core/src/Types/Resolvers/DefaultResolverCompiler.cs Adds suppressions for expression-tree building in resolver owner creation.
src/HotChocolate/Core/src/Types/Resolvers/BatchResolverCompiler.cs Adds suppressions for expression-tree building and generic specialization.
src/HotChocolate/Core/src/Types/Internal/ExtendedType.Helper.cs Adds suppression around interface-based list type discovery.
src/HotChocolate/Core/src/Types/HotChocolate.Types.csproj Enables IsAotCompatible for the project.
src/HotChocolate/Core/src/Types/Fetching/Extensions/ObjectFieldDataLoaderExtensions.cs Adds RequiresDynamicCode + DAM annotations for DataLoader middleware wiring.
src/HotChocolate/Core/src/Types/Fetching/DataLoaderRootFieldTypeInterceptor.cs Adds suppression for reflection-based type discovery in DataLoader interceptor.
src/HotChocolate/Core/src/Types/Fetching/DataLoaderParameterExpressionBuilder.cs Adds suppressions for MakeGenericMethod usage in expression building.
src/HotChocolate/Core/src/Types/Fetching/Attributes/UseDataLoaderAttribute.cs Adds suppressions for DataLoader type usage under AOT/trimming.
src/HotChocolate/Core/src/Types/Extensions/SchemaBuilderExtensions.Resolvers.cs Adds suppression around resolver type reflection in schema builder extensions.
src/HotChocolate/Core/src/Types/Extensions/SchemaBuilderExtensions.Middleware.cs Adds DAM annotations for middleware type parameters.
src/HotChocolate/Core/src/Types/Extensions/SchemaBuilderExtensions.Conventions.cs Adds suppressions around convention type reflection.
src/HotChocolate/Core/src/Types/Execution/Requirements/RequirementsTypeInterceptor.cs Adds suppression for runtime type inspection in requirements processing.
src/HotChocolate/Core/src/Types/Execution/Requirements/PropertyTreeBuilder.cs Adds DAM annotations and suppressions for recursive property inspection.
src/HotChocolate/Core/src/Types/Execution/Requirements/PropertyNode.cs Adds suppression and DAM annotations for collection/interface inspection.
src/HotChocolate/Core/src/Types/Execution/Processing/Tasks/StreamHelper.cs Adds RequiresDynamicCode/RequiresUnreferencedCode + DAM annotations for stream factory creation.
src/HotChocolate/Core/src/Types/Execution/Processing/RootValueResolver.cs Adds suppression for runtime root value type resolution.
src/HotChocolate/Core/src/Types/Execution/Processing/MiddlewareContext.Global.cs Adds suppressions around dynamic JSON serialization paths.
src/HotChocolate/Core/src/Types/Execution/Processing/DefaultActivator.cs Adds suppression for resolver provider activator patterns.
src/HotChocolate/Core/src/Types/Execution/Pipeline/RequestClassMiddlewareFactory.cs Adds DAM annotations for request middleware type construction.
src/HotChocolate/Core/src/Types/Execution/NeedsFormatting.cs Adds RequiresDynamicCode/RequiresUnreferencedCode for JSON serialization helper.
src/HotChocolate/Core/src/Types/Execution/DependencyInjection/SchemaRequestExecutorBuilderExtensions.Middleware.cs Adds DAM annotations for field middleware registration APIs.
src/HotChocolate/Core/src/Types/Execution/DependencyInjection/SchemaRequestExecutorBuilderExtensions.Convention.cs Adds DAM annotations for convention registration APIs.
src/HotChocolate/Core/src/Types/Execution/DependencyInjection/RequestExecutorServiceCollectionExtensions.cs Adds DAM annotations for DI registration APIs.
src/HotChocolate/Core/src/Types/Execution/DependencyInjection/RequestExecutorBuilderExtensions.Validation.cs Adds DAM annotations for validation registration APIs.
src/HotChocolate/Core/src/Types/Execution/DependencyInjection/RequestExecutorBuilderExtensions.UseRequest.cs Adds DAM annotations for request middleware registration API.
src/HotChocolate/Core/src/Types/Execution/DependencyInjection/RequestExecutorBuilderExtensions.TypeConversion.cs Adds DAM annotations for type converter registration APIs.
src/HotChocolate/Core/src/Types/Execution/DependencyInjection/RequestExecutorBuilderExtensions.Optimizer.cs Adds DAM annotations for optimizer registration API.
src/HotChocolate/Core/src/Types/Execution/DependencyInjection/RequestExecutorBuilderExtensions.Instrumentation.cs Adds DAM annotations for diagnostic listener registration APIs.
src/HotChocolate/Core/src/Types/Execution/DependencyInjection/RequestExecutorBuilderExtensions.IdSerializer.cs Adds DAM annotations for ID serializer registration API.
src/HotChocolate/Core/src/Types/Execution/DependencyInjection/RequestExecutorBuilderExtensions.ErrorFilter.cs Adds DAM annotations for error filter registration APIs.
src/HotChocolate/Core/src/Types/Execution/DependencyInjection/InternalServiceCollectionExtensions.cs Adds DAM annotations for internal DI helper.
src/HotChocolate/Core/src/Types/Configuration/TypeRegistrar.CreateInstance.cs Adds suppression for schema type instance creation via reflection.
src/HotChocolate/Core/src/Types/Configuration/RuntimeTypeBindingHelper.cs Adds suppression for interface inspection on schema-related types.
src/HotChocolate/Core/src/Types/Configuration/Handlers/TypeRefHelper.cs Adds RequiresDynamicCode + suppression around MakeGenericType for schema types.
src/HotChocolate/Core/src/Types/Configuration/Handlers/DefaultTypeDiscoveryHandler.cs Adds suppression for runtime schema type inference paths.
src/HotChocolate/Core/src/Types/Configuration/Features/TypeInterceptorCollection.cs Formatting-only change to constructor signature layout.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 102 to 104
[UnconditionalSuppressMessage("AOT", "IL2075",
Justification = "DataLoader service types are statically referenced in DI registrations.")]
private HashSet<Type> GetDataLoaderValueTypes()
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The suppression on GetDataLoaderValueTypes targets IL2075, but the reflection usage inside this method is primarily registration.ServiceType.GetInterfaces(), which elsewhere in this codebase is suppressed as IL2070 (e.g. InterfaceCompletionTypeInterceptor and ExtendedType.Helper). If the intent is to silence the GetInterfaces() trim-analysis warning, this attribute likely won’t match the emitted diagnostic. Consider switching the suppression to IL2070 (or moving to a local #pragma around GetInterfaces() / annotating the ServiceType flow with the required DynamicallyAccessedMembers).

Copilot uses AI. Check for mistakes.
michaelstaib and others added 3 commits April 8, 2026 10:00
Reformat all [UnconditionalSuppressMessage], [RequiresDynamicCode], and
[RequiresUnreferencedCode] attributes across 38 files to use multi-line
format with no line exceeding 120 characters.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants