Skip to content

Commit ef8d1b3

Browse files
Add GraphQL-Disable-NullBubbling header
1 parent 95739c6 commit ef8d1b3

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
@@ -42,6 +42,11 @@ public virtual ValueTask OnRequestAsync(
4242
requestBuilder.TryAddGlobalState(IncludeQueryPlan, true);
4343
}
4444

45+
if (context.IsNullBubblingDisabled())
46+
{
47+
requestBuilder.TryAddGlobalState(WellKnownContextData.DisableNullBubbling, true);
48+
}
49+
4550
return default;
4651
}
4752

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
@@ -108,7 +108,8 @@ private IOperation CompileOperation(
108108

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

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

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

189-
/// <summary>
190-
/// Specifies whether null-bubbling shall be disabled.
191-
/// </summary>
192-
bool DisableNullBubbling { get; }
193-
194189
/// <summary>
195190
/// Specifies that the @tag directive shall be registered with the type system.
196191
/// </summary>

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ public partial class SchemaBuilder : ISchemaBuilder
3737
typeof(CostTypeInterceptor),
3838
typeof(MiddlewareValidationTypeInterceptor),
3939
typeof(EnableTrueNullabilityTypeInterceptor),
40-
typeof(DisableNullBubblingTypeInterceptor),
4140
];
4241

4342
private SchemaOptions _options = new();

0 commit comments

Comments
 (0)