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

Adds services to fusion registration extensions #6305

Merged
merged 4 commits into from
Jun 30, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
refinements
michaelstaib committed Jun 30, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 72aa272ff94b7b1fd20ddb5d8b3789c2fe612402
Original file line number Diff line number Diff line change
@@ -22,8 +22,8 @@ public static class FusionRequestExecutorBuilderExtensions
/// <param name="services">
/// The service collection.
/// </param>
/// <param name="fusionGraphDocument">
/// The fusion graph document.
/// <param name="gatewayConfigurationDoc">
/// The fusion gateway configuration document.
/// </param>
/// <param name="graphName">
/// The name of the fusion graph.
@@ -33,25 +33,25 @@ public static class FusionRequestExecutorBuilderExtensions
/// </returns>
/// <exception cref="ArgumentNullException">
/// <paramref name="services"/> is <c>null</c> or
/// <paramref name="fusionGraphDocument"/> is <c>null</c>.
/// <paramref name="gatewayConfigurationDoc"/> is <c>null</c>.
/// </exception>
public static FusionGatewayBuilder AddFusionGatewayServer(
this IServiceCollection services,
DocumentNode fusionGraphDocument,
DocumentNode gatewayConfigurationDoc,
string? graphName = default)
{
if (services is null)
{
throw new ArgumentNullException(nameof(services));
}

if (fusionGraphDocument is null)
if (gatewayConfigurationDoc is null)
{
throw new ArgumentNullException(nameof(fusionGraphDocument));
throw new ArgumentNullException(nameof(gatewayConfigurationDoc));
}

return services.AddFusionGatewayServer(
_ => new ValueTask<DocumentNode>(fusionGraphDocument),
(_, _) => new ValueTask<DocumentNode>(gatewayConfigurationDoc),
graphName: graphName);
}

@@ -61,8 +61,8 @@ public static FusionGatewayBuilder AddFusionGatewayServer(
/// <param name="services">
/// The service collection.
/// </param>
/// <param name="fusionGraphFile">
/// The path to the fusion graph package file or fusion graph file.
/// <param name="gatewayConfigurationFile">
/// The path to the fusion gateway configuration file.
/// </param>
/// <param name="graphName">
/// The name of the fusion graph.
@@ -76,12 +76,12 @@ public static FusionGatewayBuilder AddFusionGatewayServer(
/// </returns>
/// <exception cref="ArgumentNullException">
/// <paramref name="services"/> is <c>null</c> or
/// <paramref name="fusionGraphFile"/> is <c>null</c> or
/// <paramref name="fusionGraphFile"/> is equals to <see cref="string.Empty"/>.
/// <paramref name="gatewayConfigurationFile"/> is <c>null</c> or
/// <paramref name="gatewayConfigurationFile"/> is equals to <see cref="string.Empty"/>.
/// </exception>
public static FusionGatewayBuilder AddFusionGatewayServer(
this IServiceCollection services,
string fusionGraphFile,
string gatewayConfigurationFile,
string? graphName = default,
bool watchFileForUpdates = false)
{
@@ -90,18 +90,18 @@ public static FusionGatewayBuilder AddFusionGatewayServer(
throw new ArgumentNullException(nameof(services));
}

if (string.IsNullOrEmpty(fusionGraphFile))
if (string.IsNullOrEmpty(gatewayConfigurationFile))
{
throw new ArgumentNullException(nameof(fusionGraphFile));
throw new ArgumentNullException(nameof(gatewayConfigurationFile));
}

var builder = services.AddFusionGatewayServer(
ct => LoadDocumentAsync(fusionGraphFile, ct),
(_, ct) => LoadDocumentAsync(gatewayConfigurationFile, ct),
graphName: graphName);

if (watchFileForUpdates)
{
builder.CoreBuilder.AddTypeModule(_ => new FileWatcherTypeModule(fusionGraphFile));
builder.CoreBuilder.AddTypeModule(_ => new FileWatcherTypeModule(gatewayConfigurationFile));
}

return builder;
@@ -113,8 +113,8 @@ public static FusionGatewayBuilder AddFusionGatewayServer(
/// <param name="services">
/// The service collection.
/// </param>
/// <param name="fusionGraphResolver">
/// A delegate that is used to resolve a fusion graph document.
/// <param name="resolveConfig">
/// A delegate that is used to resolve the fusion gateway configuration.
/// </param>
/// <param name="graphName">
/// The name of the fusion graph.
@@ -124,46 +124,21 @@ public static FusionGatewayBuilder AddFusionGatewayServer(
/// </returns>
/// <exception cref="ArgumentNullException">
/// <paramref name="services"/> is <c>null</c> or
/// <paramref name="fusionGraphResolver"/> is <c>null</c>.
/// <paramref name="resolveConfig"/> is <c>null</c>.
/// </exception>
public static FusionGatewayBuilder AddFusionGatewayServer(
this IServiceCollection services,
ResolveFusionGraphDocAsync fusionGraphResolver,
string? graphName = default)
=> services.AddFusionGatewayServer((_, ct) => fusionGraphResolver(ct), graphName);

/// <summary>
/// Adds a Fusion GraphQL Gateway to the service collection.
/// </summary>
/// <param name="services">
/// The service collection.
/// </param>
/// <param name="fusionGraphResolver">
/// A delegate that is used to resolve a fusion graph document.
/// </param>
/// <param name="graphName">
/// The name of the fusion graph.
/// </param>
/// <returns>
/// Returns the <see cref="IRequestExecutorBuilder"/> that can be used to configure the Gateway.
/// </returns>
/// <exception cref="ArgumentNullException">
/// <paramref name="services"/> is <c>null</c> or
/// <paramref name="fusionGraphResolver"/> is <c>null</c>.
/// </exception>
public static FusionGatewayBuilder AddFusionGatewayServer(
this IServiceCollection services,
ResolveFusionGraphDocServiceProviderAsync fusionGraphResolver,
GatewayConfigurationResolver resolveConfig,
string? graphName = default)
{
if (services is null)
{
throw new ArgumentNullException(nameof(services));
}

if (fusionGraphResolver is null)
if (resolveConfig is null)
{
throw new ArgumentNullException(nameof(fusionGraphResolver));
throw new ArgumentNullException(nameof(resolveConfig));
}

services.AddTransient<IWebSocketConnectionFactory>(
@@ -190,10 +165,9 @@ public static FusionGatewayBuilder AddFusionGatewayServer(
async: async (ctx, _, ct) =>
{
var rewriter = new FusionGraphConfigurationToSchemaRewriter();
var fusionGraphDoc =
await fusionGraphResolver(ctx.ApplicationServices, ct);
var fusionGraphConfig = Load(fusionGraphDoc);
var schemaDoc = rewriter.Rewrite(fusionGraphDoc);
var config = await resolveConfig(new(ctx.ApplicationServices), ct);
var fusionGraphConfig = Load(config);
var schemaDoc = rewriter.Rewrite(config);

ctx.SchemaBuilder
.AddDocument(schemaDoc)
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace Microsoft.Extensions.DependencyInjection;

/// <summary>
/// Represents the context data available to resolve the fusion gateway configuration.
/// </summary>
public readonly struct GatewayConfigurationContext
{
/// <summary>
/// Initializes a new instance of <see cref="GatewayConfigurationContext"/>.
/// </summary>
/// <param name="services">
/// The service provider.
/// </param>
public GatewayConfigurationContext(IServiceProvider services)
{
Services = services ?? throw new ArgumentNullException(nameof(services));
}

/// <summary>
/// Gets the service provider.
/// </summary>
public IServiceProvider Services { get; }
}
Original file line number Diff line number Diff line change
@@ -8,5 +8,6 @@ namespace Microsoft.Extensions.DependencyInjection;
/// <param name="cancellationToken">
/// The cancellation token.
/// </param>
public delegate ValueTask<DocumentNode> ResolveFusionGraphDocAsync(
public delegate ValueTask<DocumentNode> GatewayConfigurationResolver(
GatewayConfigurationContext context,
CancellationToken cancellationToken = default);

This file was deleted.