Skip to content

Commit

Permalink
Reworked fusion configuration to use observer. (#6310)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib authored Jul 3, 2023
1 parent 383814e commit 41979c5
Show file tree
Hide file tree
Showing 25 changed files with 631 additions and 280 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ public abstract class TypeModule : ITypeModule
/// </summary>
public event EventHandler<EventArgs>? TypesChanged;

internal virtual ValueTask ConfigureAsync(
ConfigurationContext context,
CancellationToken cancellationToken)
=> default;

/// <summary>
/// Will be called by the schema building process to add the dynamically created
/// types and type extensions to the schema building process.
Expand Down
18 changes: 18 additions & 0 deletions src/HotChocolate/Core/src/Execution/RequestExecutorResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ await OnConfigureRequestExecutorOptionsAsync(context, setup, cancellationToken)
typeModuleChangeMonitor.Register(typeModule);
}

// we allow newer type modules to apply configurations.
await typeModuleChangeMonitor.ConfigureAsync(context, cancellationToken)
.ConfigureAwait(false);

serviceCollection.AddSingleton<IApplicationServiceProvider>(
_ => new DefaultApplicationServiceProvider(_applicationServices));

Expand Down Expand Up @@ -519,6 +523,20 @@ public void Register(ITypeModule typeModule)
_typeModules.Add(typeModule);
}

internal async ValueTask ConfigureAsync(
ConfigurationContext context,
CancellationToken cancellationToken)
{
foreach (var item in _typeModules)
{
if (item is TypeModule typeModule)
{
await typeModule.ConfigureAsync(context, cancellationToken)
.ConfigureAwait(false);
}
}
}

public IAsyncEnumerable<ITypeSystemMember> CreateTypesAsync(IDescriptorContext context)
=> new TypeModuleEnumerable(_typeModules, context);

Expand Down
15 changes: 0 additions & 15 deletions src/HotChocolate/Fusion/src/Core/Clients/IGraphQLClient.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using HotChocolate.Fusion.Metadata;

namespace HotChocolate.Fusion.Clients;

/// <summary>
Expand Down Expand Up @@ -28,16 +26,3 @@ Task<GraphQLResponse> ExecuteAsync(
GraphQLRequest request,
CancellationToken cancellationToken);
}

/// <summary>
/// Represents a factory for creating <see cref="IGraphQLClient"/> instances.
/// </summary>
public interface IGraphQLClientFactory
{
/// <summary>
/// Creates a new <see cref="IGraphQLClient"/> instance.
/// </summary>
/// <param name="configuration"></param>
/// <returns></returns>
IGraphQLClient CreateClient(HttpClientConfiguration configuration);
}
16 changes: 16 additions & 0 deletions src/HotChocolate/Fusion/src/Core/Clients/IGraphQLClientFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using HotChocolate.Fusion.Metadata;

namespace HotChocolate.Fusion.Clients;

/// <summary>
/// Represents a factory for creating <see cref="IGraphQLClient"/> instances.
/// </summary>
public interface IGraphQLClientFactory
{
/// <summary>
/// Creates a new <see cref="IGraphQLClient"/> instance.
/// </summary>
/// <param name="configuration"></param>
/// <returns></returns>
IGraphQLClient CreateClient(HttpClientConfiguration configuration);
}

This file was deleted.

Loading

0 comments on commit 41979c5

Please sign in to comment.