public static void ConfigureServices( IServiceCollection services, IWebHostEnvironment environment ) { services.AddGraphQLServer() // Types .AddType <GraphQl.Common.OpenEndedDateTimeRangeType>() // Extensions .AddProjections() .AddFiltering <CustomFilterConvention>() .AddSorting() .AddAuthorization() .AddApolloTracing( HotChocolate.Execution.Options.TracingPreference.OnDemand ) // TODO Do we want or need this? .AddGlobalObjectIdentification() .AddQueryFieldToMutationPayloads() .ModifyOptions(options => { // https://github.com/ChilliCream/hotchocolate/blob/main/src/HotChocolate/Core/src/Types/Configuration/Contracts/ISchemaOptions.cs options.StrictValidation = true; options.UseXmlDocumentation = false; options.SortFieldsByName = true; options.RemoveUnreachableTypes = false; options.DefaultBindingBehavior = HotChocolate.Types.BindingBehavior.Implicit; /* options.FieldMiddleware = ... */ } ) .ModifyRequestOptions(options => { // https://github.com/ChilliCream/hotchocolate/blob/main/src/HotChocolate/Core/src/Execution/Options/RequestExecutorOptions.cs /* options.ExecutionTimeout = ...; */ options.IncludeExceptionDetails = environment.IsDevelopment(); // Default is `Debugger.IsAttached`. /* options.QueryCacheSize = ...; */ /* options.UseComplexityMultipliers = ...; */ } ) // TODO Configure `https://github.com/ChilliCream/hotchocolate/blob/main/src/HotChocolate/Core/src/Validation/Options/ValidationOptions.cs`. But how? // Subscriptions /* .AddInMemorySubscriptions() */ // TODO Persisted queries /* .AddFileSystemQueryStorage("./persisted_queries") */ /* .UsePersistedQueryPipeline(); */ .AddHttpRequestInterceptor(async(httpContext, requestExecutor, requestBuilder, cancellationToken) => { // HotChocolate uses the default cookie authentication // scheme `IdentityConstants.ApplicationScheme` by // default. var authenticateResult = await httpContext.AuthenticateAsync(CookieAuthenticationDefaults.AuthenticationScheme).ConfigureAwait(false); if (authenticateResult.Succeeded && authenticateResult.Principal is not null) { httpContext.User = authenticateResult.Principal; } }) .AddDiagnosticEventListener(_ => new GraphQl.LoggingDiagnosticEventListener( _.GetApplicationService <ILogger <GraphQl.LoggingDiagnosticEventListener> >() ) ) .AddQueryType(d => d.Name(nameof(GraphQl.Query))) .AddType <GraphQl.CalorimetricDataX.CalorimetricDataQueries>() .AddType <GraphQl.DataX.DataQueries>() .AddType <GraphQl.GetHttpsResources.GetHttpsResourceQueries>() .AddType <GraphQl.HygrothermalDataX.HygrothermalDataQueries>() .AddType <GraphQl.OpticalDataX.OpticalDataQueries>() .AddType <GraphQl.PhotovoltaicDataX.PhotovoltaicDataQueries>() .AddMutationType(d => d.Name(nameof(GraphQl.Mutation))) .AddType <GraphQl.CalorimetricDataX.CalorimetricDataMutations>() .AddType <GraphQl.GetHttpsResources.GetHttpsResourceMutations>() .AddType <GraphQl.HygrothermalDataX.HygrothermalDataMutations>() .AddType <GraphQl.OpticalDataX.OpticalDataMutations>() .AddType <GraphQl.PhotovoltaicDataX.PhotovoltaicDataMutations>() /* .AddSubscriptionType(d => d.Name(nameof(GraphQl.Subscription))) */ /* .AddType<ComponentSubscriptions>() */ // Scalar Types .AddType(new UuidType("Uuid", defaultFormat: 'D')) // https://chillicream.com/docs/hotchocolate/defining-a-schema/scalars#uuid-type .AddType(new UrlType("Url")) .AddType(new GraphQl.LocaleType()) // Object Types .AddType <GraphQl.CalorimetricDataX.CalorimetricDataType>() .AddType <GraphQl.DataX.DataType>() .AddType <GraphQl.GetHttpsResources.GetHttpsResourceType>() .AddType <GraphQl.HygrothermalDataX.HygrothermalDataType>() .AddType <GraphQl.NamedMethodArgumentType>() .AddType <GraphQl.OpticalDataX.OpticalDataType>() .AddType <GraphQl.PhotovoltaicDataX.PhotovoltaicDataType>() // Data Loaders /* .AddDataLoader<GraphQl.Components.ComponentByIdDataLoader>() */ // Paging .SetPagingOptions( new PagingOptions { MaxPageSize = int.MaxValue, DefaultPageSize = int.MaxValue, IncludeTotalCount = true, // TODO I actually want to infer connection names from fields (which is the default in HotChocolate). However, the current `database.graphql` schema that I hand-wrote still infers connection names from types. InferConnectionNameFromField = false } ); }