22using System.Collections.Generic;
33using System.Linq;
44using System.Threading.Tasks;
5+ using HotChocolate.Execution.Options;
56using HotChocolate.Execution.Processing;
67using HotChocolate.Language;
78using HotChocolate.Types;
@@ -19,13 +20,15 @@ internal sealed class OperationResolverMiddleware
1920{
2021 private readonly RequestDelegate _next;
2122 private readonly ObjectPool<OperationCompiler> _operationCompilerPool;
23+ private readonly IRequestExecutorOptionsAccessor _options;
2224 private readonly VariableCoercionHelper _coercionHelper;
2325 private readonly IReadOnlyList<IOperationCompilerOptimizer>? _optimizers;
2426
2527 private OperationResolverMiddleware(
2628 RequestDelegate next,
2729 ObjectPool<OperationCompiler> operationCompilerPool,
2830 IEnumerable<IOperationCompilerOptimizer> optimizers,
31+ IRequestExecutorOptionsAccessor options,
2932 VariableCoercionHelper coercionHelper)
3033 {
3134 if (optimizers is null)
@@ -37,6 +40,8 @@ private OperationResolverMiddleware(
3740 throw new ArgumentNullException(nameof(next));
3841 _operationCompilerPool = operationCompilerPool ??
3942 throw new ArgumentNullException(nameof(operationCompilerPool));
43+ _options = options ??
44+ throw new ArgumentNullException(nameof(options));
4045 _coercionHelper = coercionHelper ??
4146 throw new ArgumentNullException(nameof(coercionHelper));
4247 _optimizers = optimizers.ToArray();
@@ -109,8 +114,7 @@ private IOperation CompileOperation(
109114
110115 private bool IsNullBubblingEnabled(IRequestContext context, OperationDefinitionNode operationDefinition)
111116 {
112- if (context.ContextData.TryGetValue(DisableNullBubbling, out var disableNullBubbling)
113- && disableNullBubbling is true)
117+ if (_options.AllowDisablingNullBubbling && context.ContextData.ContainsKey(DisableNullBubbling))
114118 {
115119 return false;
116120 }
@@ -175,12 +179,14 @@ public static RequestCoreMiddleware Create()
175179 var operationCompilerPool = core.Services.GetRequiredService<ObjectPool<OperationCompiler>>();
176180 var optimizers1 = core.Services.GetRequiredService<IEnumerable<IOperationCompilerOptimizer>>();
177181 var optimizers2 = core.SchemaServices.GetRequiredService<IEnumerable<IOperationCompilerOptimizer>>();
182+ var options = core.SchemaServices.GetRequiredService<IRequestExecutorOptionsAccessor>();
178183 var coercionHelper = core.Services.GetRequiredService<VariableCoercionHelper>();
179184 var middleware = new OperationResolverMiddleware(
180185 next,
181186 operationCompilerPool,
182187 optimizers1.Concat(optimizers2),
188+ options,
183189 coercionHelper);
184190 return context => middleware.InvokeAsync(context);
185191 };
186- }
192+ }
0 commit comments