Options Reference

Comprehensive reference for all configuration options in Hot Chocolate v16, including schema, request, parser, cost, server, socket, subscription, paging, global object identification, and cache control options.

Hot Chocolate provides several option groups that control different aspects of the GraphQL server. You configure them through methods on the IRequestExecutorBuilder.

Schema Options (ModifyOptions)

Schema options control the type system and schema behavior. Configure them with ModifyOptions:

C#
builder
.AddGraphQL()
.ModifyOptions(o =>
{
o.StrictValidation = true;
o.SortFieldsByName = true;
});
PropertyTypeDefaultDescription
QueryTypeNamestring?nullThe name of the query type. When null, defaults to Query.
MutationTypeNamestring?nullThe name of the mutation type. When null, defaults to Mutation.
SubscriptionTypeNamestring?nullThe name of the subscription type. When null, defaults to Subscription.
StrictValidationbooltrueWhen true, the schema must pass all validation rules (e.g., every field must have a resolver).
UseXmlDocumentationbooltrueExtracts descriptions from XML documentation comments on .NET types.
ResolveXmlDocumentationFileNameFunc<Assembly, string>?nullCustom resolver for XML documentation file paths.
SortFieldsByNameboolfalseSorts fields alphabetically in the schema.
RemoveUnreachableTypesboolfalseRemoves types that are not reachable from any root type.
RemoveUnusedTypeSystemDirectivesbooltrueRemoves type system directives that are not applied anywhere.
DefaultBindingBehaviorBindingBehaviorImplicitControls whether type members are included by default (Implicit) or must be explicitly bound (Explicit).
DefaultFieldBindingFlagsFieldBindingFlagsInstanceControls which members are bound as fields (e.g., instance members, static members).
FieldMiddlewareFieldMiddlewareApplicationUserDefinedFieldsControls which fields have middleware applied.
EnableDirectiveIntrospectionboolfalseExposes custom directives via introspection.
DefaultDirectiveVisibilityDirectiveVisibilityPublicThe default visibility of directives in the schema.
DefaultResolverStrategyExecutionStrategyParallelThe default execution strategy for resolvers (Parallel or Serial).
ValidatePipelineOrderbooltrueValidates the order of field middleware (e.g., paging before filtering).
StrictRuntimeTypeValidationboolfalseEnforces strict runtime type validation for union and interface types.
DefaultIsOfTypeCheckIsOfTypeFallback?nullFallback for IsOfType checks on abstract types.
EnableFlagEnumsboolfalseTreats [Flags] enums as flag enums in GraphQL.
EnableDeferboolfalseEnables the @defer directive.
EnableStreamboolfalseEnables the @stream directive.
EnableSemanticNonNullboolfalseEnables the semantic non-null feature.
StripLeadingIFromInterfaceboolfalseStrips the leading I from C# interface names when generating GraphQL interface type names.
EnableTagbooltrueEnables the @tag directive for schema metadata.
EnableOptInFeaturesboolfalseEnables the @requiresOptIn directive.
DefaultQueryDependencyInjectionScopeDependencyInjectionScopeResolverThe DI scope for query resolvers.
DefaultMutationDependencyInjectionScopeDependencyInjectionScopeRequestThe DI scope for mutation resolvers.
PublishRootFieldPagesToPromiseCachebooltrueWhether root field pagination results are published to the DataLoader promise cache.
LazyInitializationboolfalseWhen true, defers schema construction until the first request.
PreparedOperationCacheSizeint256Size of the compiled operation cache. Minimum: 16.
OperationDocumentCacheSizeint256Size of the parsed document cache. Minimum: 16.

Request Options (ModifyRequestOptions)

Request options control the execution engine behavior. Configure them with ModifyRequestOptions:

C#
builder
.AddGraphQL()
.ModifyRequestOptions(o =>
{
o.ExecutionTimeout = TimeSpan.FromSeconds(60);
o.IncludeExceptionDetails = false;
});
PropertyTypeDefaultDescription
ExecutionTimeoutTimeSpan30 seconds (30 minutes when debugger is attached)Maximum execution time for a request. Minimum: 100ms.
IncludeExceptionDetailsbooltrue when debugger is attachedWhen true, exception messages and stack traces appear in GraphQL errors.
PersistedOperationsPersistedOperationOptionsDefault instanceConfiguration for the persisted operation pipeline behavior.

Cost Options (ModifyCostOptions)

Cost options configure the cost analysis feature. Install the HotChocolate.CostAnalysis package and configure with ModifyCostOptions:

C#
builder
.AddGraphQL()
.ModifyCostOptions(o =>
{
o.MaxFieldCost = 1000;
o.MaxTypeCost = 2000;
o.EnforceCostLimits = true;
});

Refer to the cost analysis documentation for the full list of configurable properties.

Server Options (ModifyServerOptions)

Server options control HTTP-level behavior such as GET requests, batching, multipart requests, and schema retrieval. This is new in v16. Configure with ModifyServerOptions:

C#
builder
.AddGraphQL()
.ModifyServerOptions(o =>
{
o.EnableGetRequests = true;
o.EnableMultipartRequests = true;
o.Batching = AllowedBatching.All;
o.MaxBatchSize = 50;
o.EnableSchemaRequests = true;
});
PropertyTypeDefaultDescription
AllowedGetOperationsAllowedGetOperationsQueryControls which operation types are allowed via HTTP GET. Values: None, Query, Mutation, Subscription, QueryAndMutation, All.
EnableGetRequestsbooltrueAllows GraphQL queries over HTTP GET.
EnableMultipartRequestsbooltrueAllows multipart HTTP requests (file uploads).
EnableSchemaRequestsbooltrueAllows schema SDL downloads.
EnableSchemaFileSupportbooltrueAllows the schema SDL to be served as a file download.
EnforceGetRequestsPreflightHeaderboolfalseRequires a preflight header on GET requests for CSRF protection.
EnforceMultipartRequestsPreflightHeaderbooltrueRequires a preflight header on multipart requests for CSRF protection.
BatchingAllowedBatchingNoneControls which batching modes are allowed. Use AllowedBatching.All to enable.
MaxBatchSizeint1024Maximum number of operations in a single batch. Set to 0 for unlimited.
SocketsGraphQLSocketOptionsSee belowWebSocket transport options. See WebSocket options for details.
ToolNitroAppOptionsDefaultNitro IDE tool options.

Per-endpoint overrides are still supported through WithOptions on the endpoint builder:

C#
app.MapGraphQL().WithOptions(o => o.EnableGetRequests = false);

WebSocket Options (GraphQLSocketOptions)

The Sockets property on GraphQLServerOptions holds WebSocket-specific settings. You configure them through ModifyServerOptions:

C#
builder
.AddGraphQL()
.ModifyServerOptions(o =>
{
o.Sockets.ConnectionInitializationTimeout = TimeSpan.FromSeconds(30);
o.Sockets.KeepAliveInterval = TimeSpan.FromSeconds(10);
});
PropertyTypeDefaultDescription
ConnectionInitializationTimeoutTimeSpan10 secondsThe time a client has to send a connection_init message before the server closes the connection.
KeepAliveIntervalTimeSpan?5 secondsThe interval at which the server sends keep-alive ping messages. Set to null to disable keep-alive messages.

Paging Options (ModifyPagingOptions)

Paging options control the default behavior for cursor-based pagination. Configure with ModifyPagingOptions:

C#
builder
.AddGraphQL()
.ModifyPagingOptions(o =>
{
o.DefaultPageSize = 25;
o.MaxPageSize = 100;
o.IncludeTotalCount = true;
});
PropertyTypeDefaultDescription
DefaultPageSizeint?10The default number of items per page when first or last is not specified.
MaxPageSizeint?50The maximum number of items a client can request per page.
IncludeTotalCountbool?falseWhen true, includes a totalCount field on connection types.
AllowBackwardPaginationbool?trueAllows clients to paginate backward using last and before.
RequirePagingBoundariesbool?falseRequires clients to provide either first or last.
InferConnectionNameFromFieldbool?trueInfers the connection type name from the field name.
IncludeNodesFieldbool?nullWhen true, exposes a nodes field on the Connection type that returns a flattened list without edges.
EnableRelativeCursorsbool?nullWhen true, enables relative cursor support for pagination.
NullOrderingNullOrderingUnspecifiedDefines how your database orders null values. Values: Unspecified, NativeNullsFirst, NativeNullsLast.
ProviderNamestring?nullThe name of the paging provider to use. When null, the default provider is used.

Parser Options (ModifyParserOptions)

Parser options control limits on the GraphQL document parser. These are important security and performance settings that protect against excessively large or complex queries. Configure them with ModifyParserOptions:

C#
builder
.AddGraphQL()
.ModifyParserOptions(o =>
{
o.MaxAllowedFields = 500;
o.MaxAllowedNodes = 5000;
});
PropertyTypeDefaultDescription
MaxAllowedNodesintint.MaxValueMaximum number of syntax nodes allowed in a document. Prevents excessive memory and CPU usage during parsing.
MaxAllowedTokensintint.MaxValueMaximum number of tokens allowed in a document. Prevents excessive memory and CPU usage during lexing.
MaxAllowedFieldsint2048Maximum number of fields allowed in a document. Provides a convenient way to limit query size since fields are an intuitive measure of scope.
IncludeLocationsbooltruePreserves location information in syntax nodes so that errors can reference positions in the original source. Disabling reduces memory usage.

Parsing happens before validation, so even invalid queries consume resources. Setting MaxAllowedNodes, MaxAllowedTokens, and MaxAllowedFields to reasonable values for your schema protects against denial-of-service attacks.

Subscription Options

Subscription options control topic buffer behavior for subscription providers. You pass them when registering a subscription provider:

C#
builder
.AddGraphQL()
.AddInMemorySubscriptions(new SubscriptionOptions
{
TopicBufferCapacity = 128,
TopicBufferFullMode = TopicBufferFullMode.DropOldest,
});
PropertyTypeDefaultDescription
TopicPrefixstring?nullA prefix prepended to all topic names. Useful when multiple services share the same message broker.
TopicBufferCapacityint64The in-memory buffer size for messages per topic. When the buffer fills, the TopicBufferFullMode policy applies.
TopicBufferFullModeTopicBufferFullModeDropOldestThe behavior when writing to a full topic buffer. Values: DropOldest (remove oldest message), DropNewest (remove newest message), DropWrite (discard the incoming message).

All subscription providers (in-memory, Redis, NATS, RabbitMQ, Postgres) accept these options.

Global Object Identification Options

Global object identification options configure the Relay-style node and nodes fields. You configure them through AddGlobalObjectIdentification:

C#
builder
.AddGraphQL()
.AddGlobalObjectIdentification(o =>
{
o.MaxAllowedNodeBatchSize = 25;
});
PropertyTypeDefaultDescription
RegisterNodeInterfacebooltrueRegisters the Node interface and adds the node(id: ID!): Node field to the Query type.
AddNodesFieldbooltrueAdds a nodes(ids: [ID!]!): [Node]! field to the Query type for batch node fetching.
EnsureAllNodesCanBeResolvedbooltrueValidates during schema building that every type implementing Node has a corresponding node resolver configured.
MaxAllowedNodeBatchSizeint50The maximum number of IDs a client can pass to the nodes field in a single request. Prevents excessive batch fetching.

Cache Control Options (ModifyCacheControlOptions)

Cache control options configure HTTP response caching hints based on the @cacheControl directive. Install the HotChocolate.Caching package and configure with ModifyCacheControlOptions:

C#
builder
.AddGraphQL()
.UseQueryCache()
.AddCacheControl()
.ModifyCacheControlOptions(o =>
{
o.DefaultMaxAge = 60;
o.ApplyDefaults = true;
});
PropertyTypeDefaultDescription
EnablebooltrueEnables or disables query result caching.
DefaultMaxAgeint0The default max-age value (in seconds) applied to fields when ApplyDefaults is true.
DefaultScopeCacheControlScopePublicThe default cache scope applied to fields when ApplyDefaults is true. Values: Public, Private.
ApplyDefaultsbooltrueWhen true, applies DefaultMaxAge and DefaultScope to all fields that do not already have a @cacheControl directive, are on the Query root type, or are responsible for fetching data.

Next Steps

Last updated on April 13, 2026 by Michael Staib