Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump HotChocolate from 11.3.8 to 12.0.1 #1295

Merged
merged 6 commits into from
Oct 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,8 @@ public static IServiceCollection AddCustomGraphQL(
.AddGraphQLServer()
.AddFiltering()
.AddSorting()
.EnableRelaySupport()
.AddGlobalObjectIdentification()
.AddQueryFieldToMutationPayloads()
.AddApolloTracing()
#if Authorization
.AddAuthorization()
Expand All @@ -360,8 +361,7 @@ public static IServiceCollection AddCustomGraphQL(
.AddIfElse(
webHostEnvironment.IsEnvironment(Constants.EnvironmentName.Test),
x => x.AddInMemoryQueryStorage(),
// Hot Chocolate contains a bug which requires us to add .GetApplicationServices() below.
x => x.AddRedisQueryStorage(x => x.GetApplicationServices().GetRequiredService<IConnectionMultiplexer>().GetDatabase()))
x => x.AddRedisQueryStorage())
#endif
#if Subscriptions
.AddIfElse(
Expand All @@ -375,7 +375,6 @@ public static IServiceCollection AddCustomGraphQL(
.AddProjectTypes()
.TrimTypes()
.ModifyOptions(options => options.UseXmlDocumentation = false)
.AddMaxComplexityRule(graphQLOptions.MaxAllowedComplexity)
.AddMaxExecutionDepthRule(graphQLOptions.MaxAllowedExecutionDepth)
.SetPagingOptions(graphQLOptions.Paging)
.SetRequestOptions(() => graphQLOptions.Request)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ namespace GraphQLTemplate.DataLoaders
using GraphQLTemplate.Repositories;
using GreenDonut;

public class DroidDataLoader : DataLoaderBase<Guid, Droid>, IDroidDataLoader
public class DroidDataLoader : BatchDataLoader<Guid, Droid>, IDroidDataLoader
{
private readonly IDroidRepository repository;

public DroidDataLoader(IBatchScheduler batchScheduler, IDroidRepository repository)
: base(batchScheduler, new DataLoaderOptions<Guid>()) =>
public DroidDataLoader(IDroidRepository repository, IBatchScheduler batchScheduler, DataLoaderOptions options)
: base(batchScheduler, options) =>
this.repository = repository;

protected override async ValueTask<IReadOnlyList<Result<Droid>>> FetchAsync(
protected override async Task<IReadOnlyDictionary<Guid, Droid>> LoadBatchAsync(
IReadOnlyList<Guid> keys,
CancellationToken cancellationToken)
{
var droids = await this.repository.GetDroidsAsync(keys, cancellationToken).ConfigureAwait(false);
return droids.Select(x => Result<Droid>.Resolve(x)).ToList();
return droids.ToDictionary(x => x.Id);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ namespace GraphQLTemplate.DataLoaders
using GraphQLTemplate.Repositories;
using GreenDonut;

public class HumanDataLoader : DataLoaderBase<Guid, Human>, IHumanDataLoader
public class HumanDataLoader : BatchDataLoader<Guid, Human>, IHumanDataLoader
{
private readonly IHumanRepository repository;

public HumanDataLoader(IBatchScheduler batchScheduler, IHumanRepository repository)
: base(batchScheduler, new DataLoaderOptions<Guid>()) =>
public HumanDataLoader(IHumanRepository repository, IBatchScheduler batchScheduler, DataLoaderOptions? options)
: base(batchScheduler, options) =>
this.repository = repository;

protected override async ValueTask<IReadOnlyList<Result<Human>>> FetchAsync(
protected override async Task<IReadOnlyDictionary<Guid, Human>> LoadBatchAsync(
IReadOnlyList<Guid> keys,
CancellationToken cancellationToken)
{
var droids = await this.repository.GetHumansAsync(keys, cancellationToken).ConfigureAwait(false);
return droids.Select(x => Result<Human>.Resolve(x)).ToList();
return droids.ToDictionary(x => x.Id);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@
<PackageReference Include="Boxed.Mapping" Version="5.3.0" />
<PackageReference Include="GraphQL.Server.Ui.Playground" Version="5.0.2" />
<PackageReference Include="GraphQL.Server.Ui.Voyager" Version="5.0.2" />
<PackageReference Include="HotChocolate.AspNetCore" Version="11.3.8" />
<PackageReference Include="HotChocolate.AspNetCore.Authorization" Version="11.3.8" Condition="'$(Authorization)' == 'true'" />
<PackageReference Include="HotChocolate.Data" Version="11.3.8" />
<PackageReference Include="HotChocolate.PersistedQueries.InMemory" Version="11.3.8" Condition="'$(PersistedQueries)' == 'true'" />
<PackageReference Include="HotChocolate.PersistedQueries.Redis" Version="11.3.8" Condition="'$(PersistedQueries)' == 'true'" />
<PackageReference Include="HotChocolate.Subscriptions.Redis" Version="11.3.8" Condition="'$(Subscriptions)' == 'true'" />
<PackageReference Include="HotChocolate.Types.Scalars" Version="11.3.8" />
<PackageReference Include="HotChocolate.AspNetCore" Version="12.0.1" />
<PackageReference Include="HotChocolate.AspNetCore.Authorization" Version="12.0.1" Condition="'$(Authorization)' == 'true'" />
<PackageReference Include="HotChocolate.Data" Version="12.0.1" />
<PackageReference Include="HotChocolate.PersistedQueries.InMemory" Version="12.0.1" Condition="'$(PersistedQueries)' == 'true'" />
<PackageReference Include="HotChocolate.PersistedQueries.Redis" Version="12.0.1" Condition="'$(PersistedQueries)' == 'true'" />
<PackageReference Include="HotChocolate.Subscriptions.Redis" Version="12.0.1" Condition="'$(Subscriptions)' == 'true'" />
<PackageReference Include="HotChocolate.Types.Scalars" Version="12.0.1" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.18.0" Condition="'$(ApplicationInsights)' == 'true'" />
<PackageReference Include="Microsoft.AspNetCore.ApplicationInsights.HostingStartup" Version="2.2.0" Condition="'$(ApplicationInsights)' == 'true'" />
<PackageReference Include="Microsoft.AspNetCore.AzureAppServicesIntegration" Version="5.0.10" Condition="'$(Azure)' == 'true'" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ namespace GraphQLTemplate.Options

public class GraphQLOptions
{
[Required]
public int MaxAllowedComplexity { get; set; }

[Required]
public int MaxAllowedExecutionDepth { get; set; }

Expand Down
31 changes: 18 additions & 13 deletions Source/GraphQLTemplate/Source/GraphQLTemplate/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ namespace GraphQLTemplate
using Boxed.AspNetCore;
#if CORS
using GraphQLTemplate.Constants;
using HotChocolate.AspNetCore;
#endif
using HotChocolate.AspNetCore;
using Microsoft.AspNetCore.Builder;
#if HealthCheck
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
Expand Down Expand Up @@ -125,10 +125,22 @@ public virtual void Configure(IApplicationBuilder application) =>
.UseEndpoints(
builder =>
{
var graphQLServerOptions = new GraphQLServerOptions();
// Add Banana Cake Pop GraphQL client at /graphql.
graphQLServerOptions.Tool.Enable = this.webHostEnvironment.IsDevelopment();
builder.MapGraphQL().WithOptions(graphQLServerOptions);
var options = new GraphQLServerOptions();
options.Tool.Enable = false;
// Map the GraphQL HTTP and web socket endpoint at /graphql.
builder.MapGraphQL().WithOptions(options);

if (this.webHostEnvironment.IsDevelopment())
{
// Map the GraphQL Playground UI to try out the GraphQL API at /.
builder.MapGraphQLPlayground("/");
// Map the GraphQL Voyager UI to let you navigate your GraphQL API as a spider graph at /voyager.
builder.MapGraphQLVoyager("/voyager");
// Map the GraphQL Banana Cake Pop UI to let you navigate your GraphQL API at /banana.
builder.MapBananaCakePop("/banana");
}

// Map health check endpoints.
#if HealthCheck
#if CORS
builder
Expand All @@ -142,13 +154,6 @@ public virtual void Configure(IApplicationBuilder application) =>
builder.MapHealthChecks("/status/self", new HealthCheckOptions() { Predicate = _ => false });
#endif
#endif
})
.UseIf(
this.webHostEnvironment.IsDevelopment(),
x => x
// Add the GraphQL Playground UI to try out the GraphQL API at /.
.UseGraphQLPlayground("/")
// Add the GraphQL Voyager UI to let you navigate your GraphQL API as a spider graph at /voyager.
.UseGraphQLVoyager("/voyager"));
});
}
}
25 changes: 20 additions & 5 deletions Source/GraphQLTemplate/Source/GraphQLTemplate/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,19 @@
},
//#endif
"GraphQL": {
// The maximum complexity allowed per query. Each field requested has a cost of one, unless a cost has been explicitly set.
"MaxAllowedComplexity": 100,
// The maximum depth of objects that can be requested.
"MaxAllowedExecutionDepth": 100,
"Paging": {
// Enable pagination backwards from the end to the beginning.
"AllowBackwardPagination": true,
// The default page size.
"DefaultPageSize": 10,
// Include the total number of items in the page.
"IncludeTotalCount": true,
"MaxPageSize": 100
// The maximum number of pages that can be requested.
"MaxPageSize": 100,
// Clients need to specify either first, last or take parameters.
"RequirePagingBoundaries": true
},
"Request": {
// The maximum time to allow a query to run.
Expand All @@ -58,8 +63,18 @@
"QueryCacheSize": 100,
// Configures Apollo tracing in the query output. OnDemand enables it when client sends the GraphQL-Tracing=1 HTTP header.
"TracingPreference": "OnDemand",
// Each GraphQL field has a cost (defaults to 1 but can be changed). This can be multiplied e.g. if you return 10 items.
"UseComplexityMultipliers": true
"Complexity": {
// Enable limits to the complexity of queries.
"Enable": true,
// Apply the default multipliers below.
"ApplyDefaults": true,
// Default complexity multiplier for all fields.
"DefaultComplexity": 1,
// Default complexity multiplier for all async resolvers.
"DefaultResolverComplexity": 5,
// The maximum complexity allowed per query. Each field requested has a cost of one, unless a cost has been explicitly set.
"MaximumAllowed": 100
}
}
},
//#if (Redis)
Expand Down