Skip to content

Commit

Permalink
Add GraphQL-Disable-NullBubbling header
Browse files Browse the repository at this point in the history
  • Loading branch information
tobias-tengler committed Feb 10, 2024
1 parent 95739c6 commit ef8d1b3
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ public class DefaultHttpRequestInterceptor : IHttpRequestInterceptor
requestBuilder.TryAddGlobalState(WellKnownContextData.IncludeQueryPlan, true);
}

if (context.IsNullBubblingDisabled())
{
requestBuilder.TryAddGlobalState(WellKnownContextData.DisableNullBubbling, true);
}

return default;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public class DefaultSocketSessionInterceptor : ISocketSessionInterceptor
requestBuilder.TryAddGlobalState(IncludeQueryPlan, true);
}

if (context.IsNullBubblingDisabled())
{
requestBuilder.TryAddGlobalState(WellKnownContextData.DisableNullBubbling, true);
}

return default;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,17 @@ public static bool IncludeQueryPlan(this HttpContext context)

return false;
}

public static bool IsNullBubblingDisabled(this HttpContext context)
{
var headers = context.Request.Headers;

if (headers.TryGetValue(HttpHeaderKeys.DisableNullBubbling, out var values) &&
values.Any(v => v == HttpHeaderValues.DisableNullBubbling))
{
return true;
}

return false;
}
}
2 changes: 2 additions & 0 deletions src/HotChocolate/AspNetCore/src/AspNetCore/HttpHeaderKeys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ internal static class HttpHeaderKeys
public const string CacheControl = "Cache-Control";

public const string Preflight = "GraphQL-Preflight";

public const string DisableNullBubbling = "GraphQL-Disable-NullBubbling";
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ internal static class HttpHeaderValues

public const string IncludeQueryPlan = "1";

public const string DisableNullBubbling = "1";

public const string NoCache = "no-cache";
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,28 @@ public static HttpRequestHeaders AddGraphQLPreflight(this HttpRequestHeaders hea

headers.Add("GraphQL-Preflight", "1");
return headers;
}
}
}

/// <summary>
/// Adds the <c>GraphQL-Disable-NullBubbling</c> header to the request.
/// </summary>
/// <param name="headers">
/// The <see cref="HttpRequestHeaders"/> to add the header to.
/// </param>
/// <returns>
/// Returns the <paramref name="headers"/> for configuration chaining.
/// </returns>
/// <exception cref="ArgumentNullException">
/// <paramref name="headers"/> is <see langword="null"/>.
/// </exception>
public static HttpRequestHeaders AddGraphQLDisableNullBubbling(this HttpRequestHeaders headers)
{
if (headers == null)
{
throw new ArgumentNullException(nameof(headers));
}

headers.Add("GraphQL-Disable-NullBubbling", "1");
return headers;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,6 @@ public static class WellKnownContextData
/// </summary>
public const string NodeResolver = "HotChocolate.Relay.Node.Resolver";

/// <summary>
/// The key to check if relay support is enabled.
/// </summary>
public const string IsRelaySupportEnabled = "HotChocolate.Relay.IsEnabled";

/// <summary>
/// The key to check if the global identification spec is enabled.
/// </summary>
Expand Down Expand Up @@ -281,9 +276,9 @@ public static class WellKnownContextData
public const string EnableTrueNullability = "HotChocolate.Types.EnableTrueNullability";

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

/// <summary>
/// The key to access the tag options object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ public async ValueTask InvokeAsync(IRequestContext context)

private bool IsNullBubblingEnabled(IRequestContext context, OperationDefinitionNode operationDefinition)
{
if (context.Schema.ContextData.ContainsKey(DisableNullBubbling))
if (context.ContextData.TryGetValue(DisableNullBubbling, out var disableNullBubbling)
&& disableNullBubbling is true)
{
return false;
}
Expand Down
5 changes: 0 additions & 5 deletions src/HotChocolate/Core/src/Types/IReadOnlySchemaOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,6 @@ public interface IReadOnlySchemaOptions
/// </summary>
bool EnableTrueNullability { get; }

/// <summary>
/// Specifies whether null-bubbling shall be disabled.
/// </summary>
bool DisableNullBubbling { get; }

/// <summary>
/// Specifies that the @tag directive shall be registered with the type system.
/// </summary>
Expand Down
1 change: 0 additions & 1 deletion src/HotChocolate/Core/src/Types/SchemaBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public partial class SchemaBuilder : ISchemaBuilder
typeof(CostTypeInterceptor),
typeof(MiddlewareValidationTypeInterceptor),
typeof(EnableTrueNullabilityTypeInterceptor),
typeof(DisableNullBubblingTypeInterceptor),
];

private SchemaOptions _options = new();
Expand Down
6 changes: 0 additions & 6 deletions src/HotChocolate/Core/src/Types/SchemaOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,6 @@ public FieldBindingFlags DefaultFieldBindingFlags
/// </summary>
public bool EnableTrueNullability { get; set; }

/// <summary>
/// Specifies whether null-bubbling shall be disabled.
/// </summary>
public bool DisableNullBubbling { get; set; }

/// <summary>
/// Specifies that the @tag directive shall be registered with the type system.
/// </summary>
Expand Down Expand Up @@ -267,7 +262,6 @@ public static SchemaOptions FromOptions(IReadOnlySchemaOptions options)
MaxAllowedNodeBatchSize = options.MaxAllowedNodeBatchSize,
StripLeadingIFromInterface = options.StripLeadingIFromInterface,
EnableTrueNullability = options.EnableTrueNullability,
DisableNullBubbling = options.DisableNullBubbling,
EnableTag = options.EnableTag,
};
}
Expand Down

This file was deleted.

0 comments on commit ef8d1b3

Please sign in to comment.