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

fix: Do not override the library user's AddMutationConventions() configuration #57

Merged
merged 3 commits into from
Sep 7, 2024
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
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ RxDBDotNet is a powerful .NET library that implements the RxDB replication proto
## Key Features

- 🔄 Full RxDB Protocol Support
- 🔥 Hot Chocolate GraphQL Integration
- 🌶️ Hot Chocolate GraphQL Integration
- 🌐 Real-Time & Offline-First Capabilities
- ⚡ Quick Setup with Minimal Configuration
- 🧩 Extensible Design for Custom Types
Expand Down Expand Up @@ -73,8 +73,10 @@ Here are the minimial steps to get you up and running with RxDBDotNet in your ex
// Configure the Hot Chocolate GraphQL server
builder.Services
.AddGraphQLServer()
// Mutation conventions must be enabled for replication to work
.AddMutationConventions()
// Enable RxDBDotNet replication services
.AddReplicationServer()
.AddReplication()
// Register the document to be replicated
.AddReplicatedDocument<Workspace>()
.AddInMemorySubscriptions();
Expand Down Expand Up @@ -221,8 +223,10 @@ builder.Services
// Configure the Hot Chocolate GraphQL server
builder.Services
.AddGraphQLServer()
// Mutation conventions must be enabled for replication to work
.AddMutationConventions()
// Enable RxDBDotNet replication services
.AddReplicationServer()
.AddReplication()
// Register a type of document to be replicated
.AddReplicatedDocument<Workspace>()
.AddInMemorySubscriptions();
Expand Down Expand Up @@ -596,7 +600,9 @@ builder.Services
.AddQueryType()
.AddMutationType()
.AddSubscriptionType()
.AddReplicationServer()
// Mutation conventions must be enabled for replication to work
.AddMutationConventions()
.AddReplication()
.AddReplicatedDocument<User>(options =>
{
options.Errors = new List<Type>
Expand Down
4 changes: 3 additions & 1 deletion example/LiveDocs.GraphQLApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ static void ConfigureGraphQL(WebApplicationBuilder builder)
{
builder.Services.AddGraphQLServer()
.ModifyRequestOptions(o => o.IncludeExceptionDetails = true)
.AddReplicationServer()
// Mutation conventions must be enabled for replication to work
.AddMutationConventions()
.AddReplication()
.AddSubscriptionDiagnostics()
.AddReplicatedDocument<Hero>()
.AddReplicatedDocument<ReplicatedUser>()
Expand Down
21 changes: 11 additions & 10 deletions src/RxDBDotNet/Extensions/GraphQLBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,22 @@ namespace RxDBDotNet.Extensions;
public static class GraphQLBuilderExtensions
{
/// <summary>
/// Adds replication support for RxDBDotNet to the GraphQL schema.
/// This method configures all necessary services and types for the RxDB replication protocol.
/// Adds replication support for RxDBDotNet to the GraphQL schema.
/// This method configures all necessary services and types for the RxDB replication protocol.
/// </summary>
/// <param name="builder">The IRequestExecutorBuilder to configure.</param>
/// <returns>The configured IRequestExecutorBuilder for method chaining.</returns>
/// <param name="builder">The <see cref="IRequestExecutorBuilder"/> to configure.</param>
/// <returns>The configured <see cref="IRequestExecutorBuilder"/> for method chaining.</returns>
/// <remarks>
/// This method should be called once before adding support for specific document types.
/// It registers core services like IEventPublisher that are shared across all document types.
/// This method should be called once before adding support for specific document types.
/// It registers core services like <see cref="IEventPublisher"/> that are shared across all document types.
/// </remarks>
public static IRequestExecutorBuilder AddReplicationServer(this IRequestExecutorBuilder builder)
public static IRequestExecutorBuilder AddReplication(this IRequestExecutorBuilder builder)
{
ArgumentNullException.ThrowIfNull(builder);

builder.Services.AddSingleton<IEventPublisher, DefaultEventPublisher>();

builder.AddFiltering()
.AddMutationConventions(false);
builder.AddFiltering();

// Ensure Query, Mutation, and Subscription types exist
EnsureRootTypesExist(builder);
Expand Down Expand Up @@ -65,7 +64,9 @@ public static IRequestExecutorBuilder AddReplicationServer(this IRequestExecutor
/// Usage example:
/// <code>
/// services.AddGraphQLServer()
/// .AddReplicationServer()
/// // Mutation conventions must be enabled for replication to work
/// .AddMutationConventions()
/// .AddReplication()
/// .AddReplicatedDocument&lt;MyDocument&gt;()
/// .AddReplicatedDocument&lt;AnotherDocument&gt;();
/// </code>
Expand Down
4 changes: 0 additions & 4 deletions tests/RxDBDotNet.TestModelGenerator/GraphQlClientFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ public static async Task GenerateLiveDocsGraphQLClientAsync(this HttpClient http
// Join the lines back into a single string
var modifiedCsharpCode = string.Join(Environment.NewLine, lines);

var currentDirectory = Directory.GetCurrentDirectory();

Console.WriteLine($"The current directory is '{currentDirectory}'");

await File.WriteAllTextAsync("./Model/GraphQLTestModel.cs", modifiedCsharpCode);
}
catch (Exception e)
Expand Down
8 changes: 3 additions & 5 deletions tests/RxDBDotNet.TestModelGenerator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ public static async Task Main()
{
Console.WriteLine("Generating GraphQLTestModel...");

var factory = WebApplicationFactorySetupUtil.Setup();

using var client = factory.CreateHttpClient();
var testContext = new TestScenarioBuilder().Build();

try
{
await client.GenerateLiveDocsGraphQLClientAsync();
await testContext.HttpClient.GenerateLiveDocsGraphQLClientAsync();

Console.WriteLine("GraphQLTestModel generated successfully.");
}
Expand All @@ -26,7 +24,7 @@ public static async Task Main()
}
finally
{
await factory.DisposeAsync();
await testContext.DisposeAsync();
}
}
}
2 changes: 2 additions & 0 deletions tests/RxDBDotNet.Tests.Setup/TestContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public async ValueTask DisposeAsync()
{
disposable.Dispose();
}

HttpClient.Dispose();
}
catch
{
Expand Down
Loading
Loading