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

Remove the need to declare scalars when doing schema stitching #4769

Merged
merged 4 commits into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
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
Formatting
  • Loading branch information
michaelstaib committed Feb 17, 2022
commit 0a0148328ae52a02105c3abc59e1529b6b509ae1
6 changes: 6 additions & 0 deletions src/HotChocolate/Stitching/format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

dotnet format src/Stitching
dotnet format src/Stitching.Abstractions
dotnet format src/Stitching.Redis
dotnet format test/Stitching.Tests
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,36 @@
using System.Linq;
using HotChocolate.Language;

namespace HotChocolate.Stitching
namespace HotChocolate.Stitching;

/// <summary>
/// Defines a remote schema and how it shall be stitched into the Hot Chocolate gateway.
/// </summary>
public class RemoteSchemaDefinition
{
/// <summary>
/// Defines a remote schema and how it shall be stitched into the Hot Chocolate gateway.
/// </summary>
public class RemoteSchemaDefinition
public RemoteSchemaDefinition(
NameString name,
DocumentNode document,
IEnumerable<DocumentNode>? extensionDocuments = null)
{
public RemoteSchemaDefinition(
NameString name,
DocumentNode document,
IEnumerable<DocumentNode>? extensionDocuments = null)
{
Name = name;
Document = document;
ExtensionDocuments = extensionDocuments?.ToArray() ?? Array.Empty<DocumentNode>();
}
Name = name;
Document = document;
ExtensionDocuments = extensionDocuments?.ToArray() ?? Array.Empty<DocumentNode>();
}

/// <summary>
/// Gets the name of the schema.
/// </summary>
public NameString Name { get; }
/// <summary>
/// Gets the name of the schema.
/// </summary>
public NameString Name { get; }

/// <summary>
/// Gets the main schema documents.
/// </summary>
public DocumentNode Document { get; }
/// <summary>
/// Gets the main schema documents.
/// </summary>
public DocumentNode Document { get; }

/// <summary>
/// Gets the documents that describes how type are being merged
/// into types from other services.
/// </summary>
public IReadOnlyList<DocumentNode> ExtensionDocuments { get; }
}
/// <summary>
/// Gets the documents that describes how type are being merged
/// into types from other services.
/// </summary>
public IReadOnlyList<DocumentNode> ExtensionDocuments { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,26 @@
using HotChocolate.Stitching.SchemaDefinitions;
using StackExchange.Redis;

namespace Microsoft.Extensions.DependencyInjection
namespace Microsoft.Extensions.DependencyInjection;

public static class HotChocolateStitchingRedisPublishSchemaDefinitionDescriptorExtensions
{
public static class HotChocolateStitchingRedisPublishSchemaDefinitionDescriptorExtensions
public static IPublishSchemaDefinitionDescriptor PublishToRedis(
this IPublishSchemaDefinitionDescriptor descriptor,
NameString configurationName,
Func<IServiceProvider, IConnectionMultiplexer> connectionFactory)
{
public static IPublishSchemaDefinitionDescriptor PublishToRedis(
this IPublishSchemaDefinitionDescriptor descriptor,
NameString configurationName,
Func<IServiceProvider, IConnectionMultiplexer> connectionFactory)
if (connectionFactory is null)
{
if (connectionFactory is null)
{
throw new ArgumentNullException(nameof(connectionFactory));
}
throw new ArgumentNullException(nameof(connectionFactory));
}

configurationName.EnsureNotEmpty(nameof(configurationName));
configurationName.EnsureNotEmpty(nameof(configurationName));

return descriptor.SetSchemaDefinitionPublisher(sp =>
{
IConnectionMultiplexer connection = connectionFactory(sp);
return new RedisSchemaDefinitionPublisher(configurationName, connection);
});
}
return descriptor.SetSchemaDefinitionPublisher(sp =>
{
IConnectionMultiplexer connection = connectionFactory(sp);
return new RedisSchemaDefinitionPublisher(configurationName, connection);
});
}
}
Original file line number Diff line number Diff line change
@@ -1,42 +1,41 @@
using System;
using Microsoft.Extensions.DependencyInjection.Extensions;
using HotChocolate;
using HotChocolate.Execution.Configuration;
using HotChocolate.Stitching.Redis;
using HotChocolate.Stitching.Requests;
using Microsoft.Extensions.DependencyInjection.Extensions;
using StackExchange.Redis;

namespace Microsoft.Extensions.DependencyInjection
namespace Microsoft.Extensions.DependencyInjection;

public static class HotChocolateStitchingRedisRequestExecutorBuilderExtensions
{
public static class HotChocolateStitchingRedisRequestExecutorBuilderExtensions
public static IRequestExecutorBuilder AddRemoteSchemasFromRedis(
this IRequestExecutorBuilder builder,
NameString configurationName,
Func<IServiceProvider, IConnectionMultiplexer> connectionFactory)
{
public static IRequestExecutorBuilder AddRemoteSchemasFromRedis(
this IRequestExecutorBuilder builder,
NameString configurationName,
Func<IServiceProvider, IConnectionMultiplexer> connectionFactory)
if (connectionFactory is null)
{
if (connectionFactory is null)
{
throw new ArgumentNullException(nameof(connectionFactory));
}
throw new ArgumentNullException(nameof(connectionFactory));
}

configurationName.EnsureNotEmpty(nameof(configurationName));
configurationName.EnsureNotEmpty(nameof(configurationName));

builder.Services.AddSingleton<IRequestExecutorOptionsProvider>(sp =>
{
IConnectionMultiplexer connection = connectionFactory(sp);
IDatabase database = connection.GetDatabase();
ISubscriber subscriber = connection.GetSubscriber();
return new RedisExecutorOptionsProvider(
builder.Name, configurationName, database, subscriber);
});
builder.Services.AddSingleton<IRequestExecutorOptionsProvider>(sp =>
{
IConnectionMultiplexer connection = connectionFactory(sp);
IDatabase database = connection.GetDatabase();
ISubscriber subscriber = connection.GetSubscriber();
return new RedisExecutorOptionsProvider(
builder.Name, configurationName, database, subscriber);
});

// Last but not least, we will setup the stitching context which will
// provide access to the remote executors which in turn use the just configured
// request executor proxies to send requests to the downstream services.
builder.Services.TryAddScoped<IStitchingContext, StitchingContext>();
// Last but not least, we will setup the stitching context which will
// provide access to the remote executors which in turn use the just configured
// request executor proxies to send requests to the downstream services.
builder.Services.TryAddScoped<IStitchingContext, StitchingContext>();

return builder;
}
return builder;
}
}
Loading