Skip to content

Commit

Permalink
Merge branch 'main' into personal/dr/non-resolvable-key
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib authored Jun 27, 2024
2 parents bd63086 + 9be8c15 commit 08a2d2d
Show file tree
Hide file tree
Showing 187 changed files with 7,295 additions and 677 deletions.
4 changes: 4 additions & 0 deletions .build/Build.Tests.2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ partial class Build
.Produces(TestResultDirectory / "*.trx")
.Executes(() => RunTests(SourceDirectory / "HotChocolate" / "Core" / "HotChocolate.Core.sln"));

Target TestHotChocolateCostAnalysis => _ => _
.Produces(TestResultDirectory / "*.trx")
.Executes(() => RunTests(SourceDirectory / "HotChocolate" / "CostAnalysis" / "HotChocolate.CostAnalysis.sln"));

Target TestHotChocolateData => _ => _
.Produces(TestResultDirectory / "*.trx")
.Executes(() => RunTests(SourceDirectory / "HotChocolate" / "Data" / "HotChocolate.Data.sln"));
Expand Down
1 change: 1 addition & 0 deletions .build/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ static class Helpers
Path.Combine("HotChocolate", "AspNetCore"),
Path.Combine("HotChocolate", "AzureFunctions"),
Path.Combine("HotChocolate", "Core"),
Path.Combine("HotChocolate", "CostAnalysis"),
Path.Combine("HotChocolate", "Caching"),
Path.Combine("HotChocolate", "Diagnostics"),
Path.Combine("HotChocolate", "Language"),
Expand Down
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ insert_final_newline = true
trim_trailing_whitespace = true
rulers = 120

# ReSharper properties
resharper_align_multiline_statement_conditions = false
resharper_braces_for_ifelse = not_required

[*.md]
trim_trailing_whitespace = false

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "@provides", "FieldSet", "@external" ]) {
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "@external", "@provides", "FieldSet" ]) {
query: Query
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "@provides", "FieldSet", "@external" ]) {
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "@external", "@provides", "FieldSet" ]) {
query: Query
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
schema @composeDirective(name: "custom") @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@composeDirective", "@key", "FieldSet" ]) @link(url: "https:\/\/specs.custom.dev\/custom\/v1.0", import: [ "@custom" ]) {
schema @composeDirective(name: "custom") @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "FieldSet", "@composeDirective" ]) @link(url: "https:\/\/specs.custom.dev\/custom\/v1.0", import: [ "@custom" ]) {
query: Query
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@external", "@key", "FieldSet" ]) {
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "@external", "FieldSet" ]) {
query: Query
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "@external", "FieldSet" ]) {
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@external", "@key", "FieldSet" ]) {
query: Query
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.0", import: [ "@override", "@key", "FieldSet" ]) {
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.0", import: [ "@key", "@override", "FieldSet" ]) {
query: Query
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.7", import: [ "@override", "@key", "FieldSet" ]) {
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.7", import: [ "@key", "@override", "FieldSet" ]) {
query: Query
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ public virtual ValueTask OnCreateAsync(
requestBuilder.TryAddGlobalState(WellKnownContextData.IncludeQueryPlan, true);
}

var costSwitch = context.TryGetCostSwitch();
if (costSwitch is not null)
{
requestBuilder.TryAddGlobalState(costSwitch, true);
}

return default;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,32 @@

namespace Microsoft.Extensions.Hosting;

/// <summary>
/// Provides <see cref="IHostApplicationBuilder"/> extension methods to configure a GraphQL server.
/// </summary>
public static class HotChocolateAspNetCoreHostingBuilderExtensions
{
/// <summary>
/// Adds the GraphQL server to the application.
/// </summary>
/// <param name="builder">
/// The <see cref="IHostApplicationBuilder"/>.
/// </param>
/// <param name="schemaName">
/// The name of the GraphQL schema.
/// </param>
/// <param name="maxAllowedRequestSize">
/// The max allowed GraphQL request size.
/// </param>
/// <param name="disableCostAnalyzer">
/// Defines if the cost analyzer should be disabled.
/// </param>
/// <returns></returns>
public static IRequestExecutorBuilder AddGraphQL(
this IHostApplicationBuilder builder,
this IHostApplicationBuilder builder,
string? schemaName = default,
int maxAllowedRequestSize = MaxAllowedRequestSize)
=> builder.Services.AddGraphQLServer(schemaName, maxAllowedRequestSize);
int maxAllowedRequestSize = MaxAllowedRequestSize,
bool disableCostAnalyzer = false)
=> builder.Services.AddGraphQLServer(schemaName, maxAllowedRequestSize, disableCostAnalyzer);
}
#endif
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,67 @@ public static IServiceCollection AddGraphQLServerCore(

return services;
}
#if NET7_0_OR_GREATER
/// <summary>
/// Adds a GraphQL server configuration to the DI.
/// </summary>
/// <param name="services">
/// The <see cref="IServiceCollection"/>.
/// </param>
/// <param name="schemaName">
/// The name of the schema. Use explicit schema names if you host multiple schemas.
/// </param>
/// <param name="maxAllowedRequestSize">
/// The max allowed GraphQL request size.
/// </param>
/// <param name="disableCostAnalyzer">
/// Defines if the cost analyzer should be disabled.
/// </param>
/// <returns>
/// Returns the <see cref="IRequestExecutorBuilder"/> so that configuration can be chained.
/// </returns>
public static IRequestExecutorBuilder AddGraphQLServer(
this IServiceCollection services,
string? schemaName = default,
int maxAllowedRequestSize = MaxAllowedRequestSize,
bool disableCostAnalyzer = false)
{
var builder = services
.AddGraphQLServerCore(maxAllowedRequestSize)
.AddGraphQL(schemaName)
.AddDefaultHttpRequestInterceptor()
.AddSubscriptionServices();

if (!disableCostAnalyzer)
{
builder.AddCostAnalyzer();
}

return builder;
}

/// <summary>
/// Adds a GraphQL server configuration to the DI.
/// </summary>
/// <param name="builder">
/// The <see cref="IServiceCollection"/>.
/// </param>
/// <param name="schemaName">
/// The name of the schema. Use explicit schema names if you host multiple schemas.
/// </param>
/// <param name="disableCostAnalyzer">
/// Defines if the cost analyzer should be disabled.
/// </param>
/// <returns>
/// Returns the <see cref="IRequestExecutorBuilder"/> so that configuration can be chained.
/// </returns>
public static IRequestExecutorBuilder AddGraphQLServer(
this IRequestExecutorBuilder builder,
string? schemaName = default,
bool disableCostAnalyzer = false)
=> builder.Services.AddGraphQLServer(schemaName, disableCostAnalyzer: disableCostAnalyzer);
#else
/// <summary>
/// Adds a GraphQL server configuration to the DI.
/// </summary>
/// <param name="services">
Expand Down Expand Up @@ -122,9 +181,9 @@ public static IRequestExecutorBuilder AddGraphQLServer(
/// </returns>
public static IRequestExecutorBuilder AddGraphQLServer(
this IRequestExecutorBuilder builder,
string? schemaName = default) =>
builder.Services.AddGraphQLServer(schemaName);

string? schemaName = default)
=> builder.Services.AddGraphQLServer(schemaName);
#endif
/// <summary>
/// Registers the GraphQL Upload Scalar.
/// </summary>
Expand All @@ -145,4 +204,4 @@ public static IRequestExecutorBuilder AddUploadType(
builder.AddType<UploadType>();
return builder;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,30 @@ public static bool IncludeQueryPlan(this HttpContext context)

return false;
}

public static string? TryGetCostSwitch(this HttpContext context)
{
var headers = context.Request.Headers;
if (headers.TryGetValue(HttpHeaderKeys.Cost, out var values))
{
var value = values.FirstOrDefault();

if (value is null)
{
return null;
}

if(value.Equals(HttpHeaderValues.ReportCost, StringComparison.OrdinalIgnoreCase))
{
return WellKnownContextData.ReportCost;
}

if(value.Equals(HttpHeaderValues.ValidateCost, StringComparison.OrdinalIgnoreCase))
{
return WellKnownContextData.ValidateCost;
}
}

return null;
}
}
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 Cost = "GraphQL-Cost";
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ internal static class HttpHeaderValues
public const string IncludeQueryPlan = "1";

public const string NoCache = "no-cache";

public const string ReportCost = "report";

public const string ValidateCost = "validate";
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,22 @@ protected virtual TestServer CreateStarWarsServer(
.AddTypeExtension<SubscriptionsExtensions>()
.AddStarWarsRepositories()
.AddInMemorySubscriptions()
.UseAutomaticPersistedQueryPipeline()
.UseInstrumentation()
.UseExceptions()
.UseTimeout()
.UseDocumentCache()
.UseReadPersistedQuery()
.UseAutomaticPersistedQueryNotFound()
.UseWritePersistedQuery()
.UseDocumentParser()
.UseDocumentValidation()
#if NET7_0_OR_GREATER
.UseCostAnalyzer()
#endif
.UseOperationCache()
.UseOperationResolver()
.UseOperationVariableCoercion()
.UseOperationExecution()
.ConfigureSchemaServices(
s => s.AddSingleton<IOperationDocumentStorage, TestOperationDocumentStorage>())
.ModifyOptions(
Expand Down Expand Up @@ -102,7 +117,8 @@ protected virtual TestServer CreateStarWarsServer(
.WithOptions(new GraphQLServerOptions
{
EnableBatching = true,
AllowedGetOperations = AllowedGetOperations.Query | AllowedGetOperations.Subscription,
AllowedGetOperations =
AllowedGetOperations.Query | AllowedGetOperations.Subscription,
});
configureConventions?.Invoke(builder);
Expand All @@ -112,12 +128,11 @@ protected virtual TestServer CreateStarWarsServer(
endpoints.MapGraphQL("/upload", "upload");
endpoints.MapGraphQL("/starwars", "StarWars");
endpoints.MapGraphQL("/test", "test");
endpoints.MapGraphQL("/batching").
WithOptions(new GraphQLServerOptions
{
// with defaults
// EnableBatching = false
});
endpoints.MapGraphQL("/batching").WithOptions(new GraphQLServerOptions
{
// with defaults
// EnableBatching = false
});
}));
}

Expand Down
Loading

0 comments on commit 08a2d2d

Please sign in to comment.