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

Rework the request executor configuration hooks to allow hot reload for Fusion. #6014

Merged
merged 5 commits into from
Apr 3, 2023
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
@@ -0,0 +1,10 @@
using System;

namespace HotChocolate;

/// <summary>
/// Represents the application level service provider.
/// </summary>
public interface IApplicationServiceProvider : IServiceProvider
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;

namespace HotChocolate.Execution.Configuration;

/// <summary>
/// The configuration context is used during the setup of the schema and request executor.
/// </summary>
public sealed class ConfigurationContext : IHasContextData
{
/// <summary>
/// Initializes a new instance of <see cref="ConfigurationContext"/>.
/// </summary>
/// <param name="schemaName">
/// The schema name.
/// </param>
/// <param name="schemaBuilder">
/// The schema builder that is used to create the schema.
/// </param>
/// <param name="applicationServices">
/// The application services.
/// </param>
/// <exception cref="ArgumentNullException">
/// <paramref name="schemaBuilder"/> is <c>null</c>.
/// </exception>
public ConfigurationContext(
string schemaName,
ISchemaBuilder schemaBuilder,
IServiceProvider applicationServices)
{
SchemaName = schemaName ??
throw new ArgumentNullException(nameof(schemaName));
SchemaBuilder = schemaBuilder ??
throw new ArgumentNullException(nameof(schemaBuilder));
ApplicationServices = applicationServices ??
throw new ArgumentNullException(nameof(applicationServices));
}

/// <summary>
/// Gets the schema name.
/// </summary>
public string SchemaName { get; }

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

/// <summary>
/// Gets the application services.
/// </summary>
public IServiceProvider ApplicationServices { get; }

/// <summary>
/// Gets the configuration context data which can be used by hooks to store arbitrary state.
/// </summary>
public IDictionary<string, object?> ContextData { get; } = new Dictionary<string, object?>();
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using HotChocolate.Execution.Options;

namespace HotChocolate.Execution.Configuration;

/// <summary>
/// This struct is used as a oneOf to allow for both a sync and ab async hook
/// into the request executor option finalization.
/// </summary>
public readonly struct OnConfigureRequestExecutorOptionsAction
{
/// <summary>
/// Initializes a new instance of <see cref="OnConfigureRequestExecutorOptionsAction"/>.
/// </summary>
/// <param name="action">
/// The synchronous action.
/// </param>
/// <exception cref="ArgumentNullException">
/// <paramref name="action"/> is <c>null</c>.
/// </exception>
public OnConfigureRequestExecutorOptionsAction(OnConfigureRequestExecutorOptions action)
{
Configure = action ?? throw new ArgumentNullException(nameof(action));
ConfigureAsync = default;
}

/// <summary>
/// Initializes a new instance of <see cref="OnConfigureRequestExecutorOptionsAction"/>.
/// </summary>
/// <param name="async">
/// The asynchronous action.
/// </param>
/// <exception cref="ArgumentNullException">
/// <paramref name="async"/> is <c>null</c>.
/// </exception>
public OnConfigureRequestExecutorOptionsAction(OnConfigureRequestExecutorOptionsAsync async)
{
Configure = default;
ConfigureAsync = async ?? throw new ArgumentNullException(nameof(async));
}

/// <summary>
/// Gets the synchronous action.
/// </summary>
public OnConfigureRequestExecutorOptions? Configure { get; }

/// <summary>
/// Gets the asynchronous action.
/// </summary>
public OnConfigureRequestExecutorOptionsAsync? ConfigureAsync { get; }
}

/// <summary>
/// This delegate is used to configure the request executor options.
/// </summary>
public delegate void OnConfigureRequestExecutorOptions(
ConfigurationContext context,
RequestExecutorOptions options);

/// <summary>
/// This delegate is used to configure the request executor options.
/// </summary>
public delegate ValueTask OnConfigureRequestExecutorOptionsAsync(
ConfigurationContext context,
RequestExecutorOptions options,
CancellationToken cancellationToken);
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System;
using System.Threading;
using System.Threading.Tasks;

namespace HotChocolate.Execution.Configuration;

/// <summary>
/// This struct is used as a oneOf to allow for both a sync and an async hook
/// into the schema builder configuration.
/// </summary>
public readonly struct OnConfigureSchemaBuilderAction
{
/// <summary>
/// Initializes a new instance of <see cref="OnConfigureSchemaBuilderAction"/>.
/// </summary>
/// <param name="action">
/// The synchronous action.
/// </param>
/// <exception cref="ArgumentNullException">
/// <paramref name="action"/> is <c>null</c>.
/// </exception>
public OnConfigureSchemaBuilderAction(OnConfigureSchemaBuilder action)
{
Configure = action ?? throw new ArgumentNullException(nameof(action));
ConfigureAsync = default;
}

/// <summary>
/// Initializes a new instance of <see cref="OnConfigureSchemaBuilderAction"/>.
/// </summary>
/// <param name="asyncAction">
/// The asynchronous action.
/// </param>
/// <exception cref="ArgumentNullException">
/// <paramref name="asyncAction"/> is <c>null</c>.
/// </exception>
public OnConfigureSchemaBuilderAction(OnConfigureSchemaBuilderAsync asyncAction)
{
Configure = default;
ConfigureAsync = asyncAction ?? throw new ArgumentNullException(nameof(asyncAction));
}

/// <summary>
/// Gets the synchronous action.
/// </summary>
public OnConfigureSchemaBuilder? Configure { get; }

/// <summary>
/// Gets the asynchronous action.
/// </summary>
public OnConfigureSchemaBuilderAsync? ConfigureAsync { get; }
}

/// <summary>
/// This delegate is used to configure the schema builder.
/// </summary>
public delegate void OnConfigureSchemaBuilder(
ConfigurationContext context,
IServiceProvider schemaServices);

/// <summary>
/// This delegate is used to configure the schema builder.
/// </summary>
public delegate ValueTask OnConfigureSchemaBuilderAsync(
ConfigurationContext context,
IServiceProvider schemaServices,
CancellationToken cancellationToken);
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,66 @@

namespace HotChocolate.Execution.Configuration;

/// <summary>
/// This struct is used as a oneOf to allow for both a sync and an async hook
/// into the request executor created event.
///
/// The event can be used to capture the request executor after it was created.
/// </summary>
public readonly struct OnRequestExecutorCreatedAction
{
public OnRequestExecutorCreatedAction(
Action<IRequestExecutor> action)
/// <summary>
/// Initializes a new instance of <see cref="OnRequestExecutorCreatedAction"/>.
/// </summary>
/// <param name="created">
/// The synchronous action.
/// </param>
/// <exception cref="ArgumentNullException">
/// <paramref name="created"/> is <c>null</c>.
/// </exception>
public OnRequestExecutorCreatedAction(OnRequestExecutorCreated created)
{
Action = action ?? throw new ArgumentNullException(nameof(action));
AsyncAction = default;
Created = created ?? throw new ArgumentNullException(nameof(created));
CreatedAsync = default;
}

public OnRequestExecutorCreatedAction(
Func<IRequestExecutor, CancellationToken, ValueTask> asyncAction)
/// <summary>
/// Initializes a new instance of <see cref="OnRequestExecutorCreatedAction"/>.
/// </summary>
/// <param name="createdAsync">
/// The asynchronous action.
/// </param>
/// <exception cref="ArgumentNullException">
/// <paramref name="createdAsync"/> is <c>null</c>.
/// </exception>
public OnRequestExecutorCreatedAction(OnRequestExecutorCreatedAsync createdAsync)
{
Action = default;
AsyncAction = asyncAction ?? throw new ArgumentNullException(nameof(asyncAction));
Created = default;
CreatedAsync = createdAsync ?? throw new ArgumentNullException(nameof(createdAsync));
}

public Action<IRequestExecutor>? Action { get; }
/// <summary>
/// Gets the synchronous action.
/// </summary>
public OnRequestExecutorCreated? Created { get; }

public Func<IRequestExecutor, CancellationToken, ValueTask>? AsyncAction { get; }
/// <summary>
/// Gets the asynchronous action.
/// </summary>
public OnRequestExecutorCreatedAsync? CreatedAsync { get; }
}

/// <summary>
/// This delegate is used to configure the request executor options.
/// </summary>
public delegate void OnRequestExecutorCreated(
ConfigurationContext context,
IRequestExecutor executor);

/// <summary>
/// This delegate is used to configure the request executor options.
/// </summary>
public delegate ValueTask OnRequestExecutorCreatedAsync(
ConfigurationContext context,
IRequestExecutor executor,
CancellationToken cancellationToken);
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,26 @@ namespace HotChocolate.Execution.Configuration;

public readonly struct OnRequestExecutorEvictedAction
{
public OnRequestExecutorEvictedAction(
Action<IRequestExecutor> action)
public OnRequestExecutorEvictedAction(OnRequestExecutorEvicted evicted)
{
Action = action ?? throw new ArgumentNullException(nameof(action));
AsyncAction = default;
Evicted = evicted ?? throw new ArgumentNullException(nameof(evicted));
EvictedAsync = default;
}

public OnRequestExecutorEvictedAction(
Func<IRequestExecutor, CancellationToken, ValueTask> asyncAction)
public OnRequestExecutorEvictedAction(OnRequestExecutorEvictedAsync evictedAsync)
{
Action = default;
AsyncAction = asyncAction ?? throw new ArgumentNullException(nameof(asyncAction));
Evicted = default;
EvictedAsync = evictedAsync ?? throw new ArgumentNullException(nameof(evictedAsync));
}

public Action<IRequestExecutor>? Action { get; }
public OnRequestExecutorEvicted? Evicted { get; }

public Func<IRequestExecutor, CancellationToken, ValueTask>? AsyncAction { get; }
public OnRequestExecutorEvictedAsync? EvictedAsync { get; }
}

public delegate void OnRequestExecutorEvicted(
IRequestExecutor executor);

public delegate ValueTask OnRequestExecutorEvictedAsync(
IRequestExecutor executor,
CancellationToken cancellationToken);

This file was deleted.

Loading