Skip to content
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 @@ -14,7 +14,7 @@ public async Task StartAsync(CancellationToken cancellationToken)
foreach (var schemaName in provider.SchemaNames)
{
var setup = await executorOptionsMonitor.GetAsync(schemaName, cancellationToken);
var options = RequestExecutorManager.CreateSchemaOptions(setup);
var options = CreateSchemaOptions(setup);

if (!options.LazyInitialization)
{
Expand All @@ -32,4 +32,16 @@ private async Task WarmupAsync(string schemaName, CancellationToken cancellation
{
await provider.GetExecutorAsync(schemaName, cancellationToken).ConfigureAwait(false);
}

private static SchemaOptions CreateSchemaOptions(RequestExecutorSetup setup)
{
var options = new SchemaOptions();

foreach (var configure in setup.SchemaOptionModifiers)
{
configure(options);
}

return options;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ public sealed class RequestExecutorSetup
/// </summary>
public Schema? Schema { get; set; }

/// <summary>
/// Gets or sets the schema builder that is used to create the schema.
/// </summary>
public ISchemaBuilder? SchemaBuilder { get; set; }

/// <summary>
/// Gets or sets the request executor options.
/// </summary>
Expand Down Expand Up @@ -110,6 +115,7 @@ public IList<Action<SchemaOptions>> SchemaOptionModifiers
public void CopyTo(RequestExecutorSetup options)
{
options.Schema = Schema;
options.SchemaBuilder = SchemaBuilder;
options.RequestExecutorOptions = RequestExecutorOptions;
options._onConfigureSchemaBuilderHooks.AddRange(_onConfigureSchemaBuilderHooks);
options._onConfigureRequestExecutorOptionsHooks.AddRange(_onConfigureRequestExecutorOptionsHooks);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ public static IRequestExecutorBuilder ModifyOptions(
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(configure);

return builder.Configure(setup => setup.SchemaOptionModifiers.Add(configure));
// We configure the options using the internal SchemaBuilder,
// but we also register the modification through the SchemaOptionModifiers,
// so we're able to build the schema options without having to construct
// the schema.
return builder
.ConfigureSchema(b => b.ModifyOptions(configure))
.Configure(setup => setup.SchemaOptionModifiers.Add(configure));
}

/// <summary>
Expand Down
17 changes: 1 addition & 16 deletions src/HotChocolate/Core/src/Execution/RequestExecutorManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,9 @@ private async Task<RegisteredExecutor> CreateRequestExecutorAsync(
await _optionsMonitor.GetAsync(schemaName, cancellationToken)
.ConfigureAwait(false);

var options = CreateSchemaOptions(setup);
var schemaBuilder = SchemaBuilder.New(options);

var context = new ConfigurationContext(
schemaName,
schemaBuilder,
setup.SchemaBuilder ?? SchemaBuilder.New(),
_applicationServices);

var typeModuleChangeMonitor = new TypeModuleChangeMonitor(this, context.SchemaName);
Expand Down Expand Up @@ -249,18 +246,6 @@ private static async Task RunEvictionEvents(RegisteredExecutor registeredExecuto
}
}

internal static SchemaOptions CreateSchemaOptions(RequestExecutorSetup setup)
{
var options = new SchemaOptions();

foreach (var configure in setup.SchemaOptionModifiers)
{
configure(options);
}

return options;
}

private async Task<ServiceProvider> CreateSchemaServicesAsync(
ConfigurationContext context,
RequestExecutorSetup setup,
Expand Down
10 changes: 3 additions & 7 deletions src/HotChocolate/Core/src/Types/SchemaBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@ public partial class SchemaBuilder : ISchemaBuilder
private readonly List<CreateRef> _types = [];
private readonly Dictionary<OperationType, CreateRef> _operations = [];

private readonly SchemaOptions _options;
private readonly SchemaOptions _options = new();
private IsOfTypeFallback? _isOfType;
private IServiceProvider? _services;
private CreateRef? _schema;

private SchemaBuilder(SchemaOptions options)
private SchemaBuilder()
{
_options = options;

var typeInterceptors = new TypeInterceptorCollection();

typeInterceptors.TryAdd(new IntrospectionTypeInterceptor());
Expand Down Expand Up @@ -240,7 +238,5 @@ public ISchemaBuilder AddServices(IServiceProvider services)
/// <returns>
/// Returns a new instance of <see cref="SchemaBuilder"/>.
/// </returns>
public static SchemaBuilder New() => new(new SchemaOptions());

internal static SchemaBuilder New(SchemaOptions options) => new(options);
public static SchemaBuilder New() => new();
}
Loading