-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
128 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/Digdir.Domain.Dialogporten.GraphQL/EndUser/DialogById/Subscriptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Digdir.Domain.Dialogporten.GraphQL.Common.Authorization; | ||
using HotChocolate.Authorization; | ||
using Constants = Digdir.Domain.Dialogporten.Infrastructure.GraphQl.GraphQlSubscriptionConstants; | ||
|
||
// ReSharper disable ClassNeverInstantiated.Global | ||
|
||
namespace Digdir.Domain.Dialogporten.GraphQL.EndUser.DialogById; | ||
|
||
[Authorize(Policy = AuthorizationPolicy.EndUser)] | ||
public sealed class Subscriptions | ||
{ | ||
[Subscribe] | ||
[Topic($"{Constants.DialogUpdatedTopic}{{{nameof(dialogId)}}}")] | ||
public Guid DialogUpdated(Guid dialogId, | ||
[EventMessage] Guid eventMessage) | ||
{ | ||
ArgumentNullException.ThrowIfNull(eventMessage); | ||
return dialogId; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/Digdir.Domain.Dialogporten.Infrastructure/GraphQL/ServiceCollectionExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using HotChocolate.Execution.Configuration; | ||
using HotChocolate.Subscriptions; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using StackExchange.Redis; | ||
|
||
namespace Digdir.Domain.Dialogporten.Infrastructure.GraphQl; | ||
|
||
/// <summary> | ||
/// This implementation is a workaround to allow the use of the AddRedisSubscriptions extension method | ||
/// from HotChocolate.Subscriptions.Redis without having to take the entire HotChocolate library as a dependency. | ||
/// </summary> | ||
internal sealed class DummyRequestExecutorBuilder : IRequestExecutorBuilder | ||
{ | ||
public string Name => string.Empty; | ||
public IServiceCollection Services { get; init; } = null!; | ||
} | ||
|
||
public static class GraphQlSubscriptionConstants | ||
{ | ||
public const string SubscriptionTopicPrefix = "graphql_subscriptions_"; | ||
public const string DialogUpdatedTopic = "dialogUpdated/"; | ||
} | ||
|
||
public static class ServiceCollectionExtensions | ||
{ | ||
public static IServiceCollection AddGraphQlRedisSubscriptions(this IServiceCollection services, | ||
string redisConnectionString) | ||
{ | ||
var dummyImplementation = new DummyRequestExecutorBuilder { Services = services }; | ||
dummyImplementation.AddRedisSubscriptions(_ => ConnectionMultiplexer.Connect(redisConnectionString), | ||
new SubscriptionOptions | ||
{ | ||
TopicPrefix = GraphQlSubscriptionConstants.SubscriptionTopicPrefix | ||
}); | ||
|
||
return services; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters