Skip to content

Commit

Permalink
fix: Add missing events to dialog subscription (#1163)
Browse files Browse the repository at this point in the history
<!--- Provide a general summary of your changes in the Title above -->

## Description

<!--- Describe your changes in detail -->
The DialogUpdated GraphQL subscription is not triggered when an activity
is added, or when the dialog is deleted

* Rename subscription to "dialogEvents"
* Add type field, values are "DialogUpdated" and "DialogDeleted"

## Related Issue(s)

- #1162

## Verification

- [ ] **Your** code builds clean without any errors or warnings
- [ ] Manual testing done (required)
- [ ] Relevant automated test added (if you find this hard, leave it and
we'll help out)

## Documentation

- [ ] Documentation is updated (either in `docs`-directory, Altinnpedia
or a separate linked PR in
[altinn-studio-docs.](https://github.com/Altinn/altinn-studio-docs), if
applicable)


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
- Introduced a new `DialogEventPayload` structure to handle dialog
events, including updates and deletions.
	- Updated subscriptions to reflect the new event handling mechanism.

- **Bug Fixes**
- Renamed and expanded dialog event handling to improve clarity and
functionality.

- **Chores**
- Renamed constants for event topics to better represent the scope of
dialog events.

- **Tests**
- Minor adjustments in architecture tests for internal class visibility.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
oskogstad authored Sep 20, 2024
1 parent a91706f commit 162ce9a
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 12 deletions.
12 changes: 9 additions & 3 deletions docs/schema/V1/schema.verified.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,9 @@ type DialogByIdPayload {
errors: [DialogByIdError!]!
}

type DialogUpdatedPayload {
type DialogEventPayload {
id: UUID!
type: DialogEventType!
}

type GuiAction {
Expand Down Expand Up @@ -211,7 +212,7 @@ type SeenLog {
}

type Subscriptions @authorize(policy: "enduser") {
dialogUpdated(dialogId: UUID!): DialogUpdatedPayload!
dialogEvents(dialogId: UUID!): DialogEventPayload!
}

type Transmission {
Expand Down Expand Up @@ -296,6 +297,11 @@ enum AttachmentUrlConsumer {
API
}

enum DialogEventType {
DIALOG_UPDATED
DIALOG_DELETED
}

enum DialogStatus {
"The dialogue is considered new. Typically used for simple messages that do not require any interaction, or as an initial step for dialogues. This is the default."
NEW
Expand Down Expand Up @@ -355,4 +361,4 @@ scalar DateTime @specifiedBy(url: "https:\/\/www.graphql-scalars.com\/date-time"

scalar URL @specifiedBy(url: "https:\/\/tools.ietf.org\/html\/rfc3986")

scalar UUID @specifiedBy(url: "https:\/\/tools.ietf.org\/html\/rfc4122")
scalar UUID @specifiedBy(url: "https:\/\/tools.ietf.org\/html\/rfc4122")
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,14 @@ public enum AttachmentUrlConsumer
Api = 2
}

public sealed class DialogUpdatedPayload
public sealed class DialogEventPayload
{
public Guid Id { get; set; }
public DialogEventType Type { get; set; }
}

public enum DialogEventType
{
DialogUpdated = 1,
DialogDeleted = 2
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ namespace Digdir.Domain.Dialogporten.GraphQL.EndUser.DialogById;
public sealed class Subscriptions
{
[Subscribe]
[Topic($"{Constants.DialogUpdatedTopic}{{{nameof(dialogId)}}}")]
public DialogUpdatedPayload DialogUpdated(Guid dialogId,
[EventMessage] Guid eventMessage)
[Topic($"{Constants.DialogEventsTopic}{{{nameof(dialogId)}}}")]
public DialogEventPayload DialogEvents(Guid dialogId,
[EventMessage] DialogEventPayload eventMessage)
{
ArgumentNullException.ThrowIfNull(dialogId);
ArgumentNullException.ThrowIfNull(eventMessage);
return new DialogUpdatedPayload { Id = dialogId };
return eventMessage;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Digdir.Domain.Dialogporten.Application.Common;
using Digdir.Domain.Dialogporten.Domain.Dialogs.Events;
using Digdir.Domain.Dialogporten.Domain.Dialogs.Events.Activities;
using Digdir.Domain.Dialogporten.Domain.Outboxes;
using Digdir.Domain.Dialogporten.Infrastructure.GraphQl;
using Digdir.Library.Entity.Abstractions.Features.EventPublisher;
using HotChocolate.Subscriptions;
using Microsoft.EntityFrameworkCore.Diagnostics;
Expand Down Expand Up @@ -72,8 +74,28 @@ public override async ValueTask<int> SavedChangesAsync(SaveChangesCompletedEvent
var task = domainEvent switch
{
DialogUpdatedDomainEvent dialogUpdatedDomainEvent => _topicEventSender.SendAsync(
$"{Constants.DialogUpdatedTopic}{dialogUpdatedDomainEvent.DialogId}",
dialogUpdatedDomainEvent.DialogId,
$"{Constants.DialogEventsTopic}{dialogUpdatedDomainEvent.DialogId}",
new DialogEventPayload
{
Id = dialogUpdatedDomainEvent.DialogId,
Type = DialogEventType.DialogUpdated
},
cancellationToken),
DialogDeletedDomainEvent dialogDeletedDomainEvent => _topicEventSender.SendAsync(
$"{Constants.DialogEventsTopic}{dialogDeletedDomainEvent.DialogId}",
new DialogEventPayload
{
Id = dialogDeletedDomainEvent.DialogId,
Type = DialogEventType.DialogDeleted
},
cancellationToken),
DialogActivityCreatedDomainEvent dialogActivityCreatedDomainEvent => _topicEventSender.SendAsync(
$"{Constants.DialogEventsTopic}{dialogActivityCreatedDomainEvent.DialogId}",
new DialogEventPayload
{
Id = dialogActivityCreatedDomainEvent.DialogId,
Type = DialogEventType.DialogUpdated
},
cancellationToken),
_ => ValueTask.CompletedTask
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace Digdir.Domain.Dialogporten.Infrastructure.GraphQl;

internal struct DialogEventPayload
{
public Guid Id { get; set; }
public DialogEventType Type { get; set; }
}

internal enum DialogEventType
{
DialogUpdated = 1,
DialogDeleted = 2
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ namespace Digdir.Domain.Dialogporten.Infrastructure.GraphQl;
public static class GraphQlSubscriptionConstants
{
public const string SubscriptionTopicPrefix = "graphql_subscriptions_";
public const string DialogUpdatedTopic = "dialogUpdated/";
public const string DialogEventsTopic = "dialogEvents/";
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public void All_Classes_In_Infrastructure_Should_Be_Internal()
{
nameof(InfrastructureAssemblyMarker),
nameof(InfrastructureExtensions),

// These classes are currently public, but should be internal, moved to another assembly, or deleted
nameof(OutboxScheduler),
nameof(IUpstreamServiceError)
Expand Down

0 comments on commit 162ce9a

Please sign in to comment.