Skip to content

Commit 0a94e86

Browse files
Add GraphQL-Disable-NullBubbling header
1 parent 54ae298 commit 0a94e86

File tree

12 files changed

+56
-42
lines changed

12 files changed

+56
-42
lines changed

src/HotChocolate/AspNetCore/src/AspNetCore/DefaultHttpRequestInterceptor.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ public virtual ValueTask OnCreateAsync(
3434
requestBuilder.TryAddGlobalState(WellKnownContextData.IncludeQueryPlan, true);
3535
}
3636

37+
if (context.IsNullBubblingDisabled())
38+
{
39+
requestBuilder.TryAddGlobalState(WellKnownContextData.DisableNullBubbling, true);
40+
}
41+
3742
return default;
3843
}
3944
}

src/HotChocolate/AspNetCore/src/AspNetCore/DefaultSocketSessionInterceptor.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ public virtual ValueTask OnRequestAsync(
4444
requestBuilder.TryAddGlobalState(IncludeQueryPlan, true);
4545
}
4646

47+
if (context.IsNullBubblingDisabled())
48+
{
49+
requestBuilder.TryAddGlobalState(WellKnownContextData.DisableNullBubbling, true);
50+
}
51+
4752
return default;
4853
}
4954

src/HotChocolate/AspNetCore/src/AspNetCore/Extensions/HttpContextExtensions.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,17 @@ public static bool IncludeQueryPlan(this HttpContext context)
3535

3636
return false;
3737
}
38+
39+
public static bool IsNullBubblingDisabled(this HttpContext context)
40+
{
41+
var headers = context.Request.Headers;
42+
43+
if (headers.TryGetValue(HttpHeaderKeys.DisableNullBubbling, out var values) &&
44+
values.Any(v => v == HttpHeaderValues.DisableNullBubbling))
45+
{
46+
return true;
47+
}
48+
49+
return false;
50+
}
3851
}

src/HotChocolate/AspNetCore/src/AspNetCore/HttpHeaderKeys.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ internal static class HttpHeaderKeys
1111
public const string CacheControl = "Cache-Control";
1212

1313
public const string Preflight = "GraphQL-Preflight";
14+
15+
public const string DisableNullBubbling = "GraphQL-Disable-NullBubbling";
1416
}

src/HotChocolate/AspNetCore/src/AspNetCore/HttpHeaderValues.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@ internal static class HttpHeaderValues
66

77
public const string IncludeQueryPlan = "1";
88

9+
public const string DisableNullBubbling = "1";
10+
911
public const string NoCache = "no-cache";
1012
}

src/HotChocolate/AspNetCore/src/Transport.Http/HttpRequestHeadersExtensions.cs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,28 @@ public static HttpRequestHeaders AddGraphQLPreflight(this HttpRequestHeaders hea
2929

3030
headers.Add("GraphQL-Preflight", "1");
3131
return headers;
32-
}
33-
}
32+
}
33+
34+
/// <summary>
35+
/// Adds the <c>GraphQL-Disable-NullBubbling</c> header to the request.
36+
/// </summary>
37+
/// <param name="headers">
38+
/// The <see cref="HttpRequestHeaders"/> to add the header to.
39+
/// </param>
40+
/// <returns>
41+
/// Returns the <paramref name="headers"/> for configuration chaining.
42+
/// </returns>
43+
/// <exception cref="ArgumentNullException">
44+
/// <paramref name="headers"/> is <see langword="null"/>.
45+
/// </exception>
46+
public static HttpRequestHeaders AddGraphQLDisableNullBubbling(this HttpRequestHeaders headers)
47+
{
48+
if (headers == null)
49+
{
50+
throw new ArgumentNullException(nameof(headers));
51+
}
52+
53+
headers.Add("GraphQL-Disable-NullBubbling", "1");
54+
return headers;
55+
}
56+
}

src/HotChocolate/Core/src/Abstractions/WellKnownContextData.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,6 @@ public static class WellKnownContextData
169169
/// </summary>
170170
public const string NodeResolver = "HotChocolate.Relay.Node.Resolver";
171171

172-
/// <summary>
173-
/// The key to check if relay support is enabled.
174-
/// </summary>
175-
public const string IsRelaySupportEnabled = "HotChocolate.Relay.IsEnabled";
176-
177172
/// <summary>
178173
/// The key to check if the global identification spec is enabled.
179174
/// </summary>
@@ -281,9 +276,9 @@ public static class WellKnownContextData
281276
public const string EnableTrueNullability = "HotChocolate.Types.EnableTrueNullability";
282277

283278
/// <summary>
284-
/// The key to access the disable null-bubbling flag on the execution context.
279+
/// Disables null-bubbling for the current request.
285280
/// </summary>
286-
public const string DisableNullBubbling = "HotChocolate.Types.DisableNullBubbling";
281+
public const string DisableNullBubbling = "HotChocolate.Execution.DisableNullBubbling";
287282

288283
/// <summary>
289284
/// The key to access the tag options object.

src/HotChocolate/Core/src/Execution/Pipeline/OperationResolverMiddleware.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ private IOperation CompileOperation(
109109

110110
private bool IsNullBubblingEnabled(IRequestContext context, OperationDefinitionNode operationDefinition)
111111
{
112-
if (context.Schema.ContextData.ContainsKey(DisableNullBubbling))
112+
if (context.ContextData.TryGetValue(DisableNullBubbling, out var disableNullBubbling)
113+
&& disableNullBubbling is true)
113114
{
114115
return false;
115116
}

src/HotChocolate/Core/src/Types/IReadOnlySchemaOptions.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,6 @@ public interface IReadOnlySchemaOptions
181181
/// </summary>
182182
bool EnableTrueNullability { get; }
183183

184-
/// <summary>
185-
/// Specifies whether null-bubbling shall be disabled.
186-
/// </summary>
187-
bool DisableNullBubbling { get; }
188-
189184
/// <summary>
190185
/// Specifies that the @tag directive shall be registered with the type system.
191186
/// </summary>

src/HotChocolate/Core/src/Types/SchemaBuilder.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ public partial class SchemaBuilder : ISchemaBuilder
3939
typeof(CostTypeInterceptor),
4040
typeof(MiddlewareValidationTypeInterceptor),
4141
typeof(EnableTrueNullabilityTypeInterceptor),
42-
typeof(DisableNullBubblingTypeInterceptor),
4342
];
4443

4544
private SchemaOptions _options = new();

0 commit comments

Comments
 (0)