Skip to content

Commit

Permalink
fix: Do not override the library user's AddMutationConventions() conf…
Browse files Browse the repository at this point in the history
…iguration (#57)
  • Loading branch information
rbeauchamp authored Sep 7, 2024
1 parent 580b422 commit 34981e3
Show file tree
Hide file tree
Showing 29 changed files with 1,496 additions and 1,004 deletions.
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

0 comments on commit 34981e3

Please sign in to comment.