Attribute Reference

Comprehensive reference of all built-in attributes in Hot Chocolate v16 for configuring your GraphQL schema.

Hot Chocolate provides a wide range of attributes that you can apply to your .NET types, properties, methods, and parameters to configure the GraphQL schema. This page serves as a comprehensive reference.

Root Type Attributes

These attributes mark a class as a root operation type for your schema.

AttributeNamespaceDescription
[QueryType]HotChocolateMarks a static class as the root query type.
[MutationType]HotChocolateMarks a static class as the root mutation type.
[SubscriptionType]HotChocolateMarks a static class as the root subscription type.

Type Configuration Attributes

These attributes control how .NET types map to GraphQL types.

AttributeNamespaceDescription
[ObjectType<T>]HotChocolateMarks a class as a GraphQL object type bound to the specified runtime type T.
[ExtendObjectType<T>]HotChocolateExtends an existing GraphQL object type bound to the runtime type T with additional fields.
[GraphQLName("name")]HotChocolateOverrides the inferred GraphQL name for a type, field, or argument.
[GraphQLType<T>]HotChocolateOverrides the inferred GraphQL type for a field or argument to the specified type T.
[GraphQLDescription("...")]HotChocolateSets the description for a type, field, or argument in the GraphQL schema.
[GraphQLDeprecated("reason")]HotChocolateMarks a field or enum value as deprecated with the specified reason.
[GraphQLIgnore]HotChocolateExcludes a property or method from the GraphQL schema.

Data Fetching Attributes

These attributes configure data loading and resolver behavior.

AttributeNamespaceDescription
[DataLoader]GreenDonutMarks a static method as a DataLoader resolver. The source generator creates the DataLoader type.
[IsSelected]HotChocolateIndicates that a resolver parameter should receive whether a specific field is selected in the query.

Authorization Attributes

AttributeNamespaceDescription
[Authorize]HotChocolate.AuthorizationApplies authorization policies to a type or field. Supports Policy, Roles, and Apply parameters.

Error Handling Attributes

AttributeNamespaceDescription
[Error<T>]HotChocolateRegisters an error type T for a mutation field when using mutation conventions.

Cost Analysis Attributes

AttributeNamespaceDescription
[Cost]HotChocolate.CostAnalysisSets the cost weight for a field, used by the cost analyzer to calculate query complexity.
[ListSize]HotChocolate.CostAnalysisDeclares the expected list size for a field, used by the cost analyzer.

Caching Attributes

AttributeNamespaceDescription
[CacheControl(...)]HotChocolate.CachingDeclares HTTP cache policy hints (@cacheControl) for Cache-Control and Vary headers.

Identity Attributes

AttributeNamespaceDescription
[ID]HotChocolateMarks a field as a global object identifier. The value is encoded as a base64 ID with the type name.
[ID<T>]HotChocolateMarks a field as a global object identifier associated with a specific GraphQL type T.

Resolver Parameter Attributes

These attributes control how parameters are injected into resolvers.

AttributeNamespaceDescription
[Parent]HotChocolateInjects the parent (resolved value of the parent field) into the resolver.
[Service]HotChocolateInjects a service from the dependency injection container.
[ScopedService]HotChocolateInjects a scoped service. Equivalent to [Service] for the current DI scope.
[GlobalState("key")]HotChocolateInjects a value from the global request state by key.
[ScopedState("key")]HotChocolateInjects a value from the scoped state by key.
[LocalState("key")]HotChocolateInjects a value from the local (field-scoped) state by key.

Subscription Attributes

AttributeNamespaceDescription
[Subscribe]HotChocolateMarks a method as a subscription resolver that subscribes to an event stream.
[EventMessage]HotChocolateInjects the event message payload into a subscription resolver.
[Topic("name")]HotChocolateSpecifies the topic name for subscription event routing. Can also be applied to parameters to use a dynamic topic.

Data Middleware Attributes

These attributes apply middleware to fields for pagination, filtering, sorting, and projection.

Middleware ordering matters. The correct attribute order from top to bottom is: [UsePaging], [UseProjection], [UseFiltering], [UseSorting].

AttributeNamespaceDescription
[UsePaging]HotChocolate.TypesApplies cursor-based pagination to the field.
[UseFiltering]HotChocolate.DataApplies filtering capabilities to the field.
[UseSorting]HotChocolate.DataApplies sorting capabilities to the field.
[UseProjection]HotChocolate.DataApplies field projection to push selection down to the data source.

Mutation Convention Attributes

AttributeNamespaceDescription
[UseMutationConvention]HotChocolate.TypesApplies mutation conventions (input wrapping, payload type generation) to a mutation field.

Relay / Global Object Identification Attributes

AttributeNamespaceDescription
[NodeResolver]HotChocolate.Types.RelayMarks a method as the resolver for the node field, used in Global Object Identification.

Schema Design Attributes

AttributeNamespaceDescription
[RequiresOptIn("feature")]HotChocolateMarks a field as requiring opt-in, used with the @requiresOptIn directive.

Fusion / Federation Attributes

These attributes are used when building Fusion subgraphs or Apollo Federation subgraphs.

AttributeNamespaceDescription
[Lookup]HotChocolate.FusionMarks a resolver as a lookup resolver for entity resolution in Fusion.
[EntityKey]HotChocolate.FusionMarks a property as part of the entity key in Fusion.
[Shareable]HotChocolate.ApolloFederationIndicates that a field can be resolved by multiple subgraphs.
[Inaccessible]HotChocolate.ApolloFederationHides a field from the composed supergraph schema.
[Internal]HotChocolate.FusionMarks a field as internal, visible only within the subgraph.
[Is]HotChocolate.FusionProvides a mapping expression for entity resolution in Fusion.
[Require]HotChocolate.FusionSpecifies that a lookup resolver requires certain fields to be provided.

Custom Descriptor Attributes

You can create custom attributes to package descriptor configurations for reuse. Hot Chocolate provides base classes for each descriptor type:

  • ObjectTypeDescriptorAttribute
  • ObjectFieldDescriptorAttribute
  • InputObjectTypeDescriptorAttribute
  • InputFieldDescriptorAttribute
  • InterfaceTypeDescriptorAttribute
  • InterfaceFieldDescriptorAttribute
  • EnumTypeDescriptorAttribute
  • EnumValueDescriptorAttribute
  • UnionTypeDescriptorAttribute
  • ArgumentDescriptorAttribute

Each base class pre-configures the allowed attribute targets. For example, ObjectFieldDescriptorAttribute is valid only on methods and properties.

C#
public class UseMyMiddlewareAttribute : ObjectFieldDescriptorAttribute
{
public UseMyMiddlewareAttribute([CallerLineNumber] int order = 0)
{
Order = order;
}
protected override void OnConfigure(
IDescriptorContext context,
IObjectFieldDescriptor descriptor,
MemberInfo member)
{
descriptor.Use(next => async ctx =>
{
// Custom logic
await next(ctx);
});
}
}

For attributes that target multiple descriptor types, use the DescriptorAttribute base class:

C#
[AttributeUsage(
AttributeTargets.Property | AttributeTargets.Method,
Inherited = true,
AllowMultiple = true)]
public sealed class MyCustomAttribute : DescriptorAttribute
{
protected override void TryConfigure(
IDescriptorContext context,
IDescriptor descriptor,
ICustomAttributeProvider element)
{
if (element is MemberInfo member)
{
switch (descriptor)
{
case IInterfaceFieldDescriptor interfaceField:
// Configure interface field
break;
case IObjectFieldDescriptor objectField:
// Configure object field
break;
}
}
}
}

Next Steps

Last updated on April 13, 2026 by Michael Staib