Skip to content

Commit

Permalink
--wip-- [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
oskogstad committed Sep 15, 2024
1 parent 3d7302d commit dd19d27
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,9 @@ public enum AttachmentUrlConsumer
Api = 2
}

public sealed class DialogUpdatedPayload
public sealed class DialogUpdatedPayload : IOutputType
{
public Guid Id { get; set; }
public TypeKind Kind { get; }
public Type RuntimeType => typeof(DialogUpdatedPayload);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
using System.Reflection;
using Digdir.Domain.Dialogporten.GraphQL.Common.Authorization;
using HotChocolate.Authorization;
using HotChocolate.Configuration;
using HotChocolate.Subscriptions;
using HotChocolate.Types.Descriptors;
using Constants = Digdir.Domain.Dialogporten.Infrastructure.GraphQl.GraphQlSubscriptionConstants;

Expand All @@ -7,16 +11,51 @@
namespace Digdir.Domain.Dialogporten.GraphQL.EndUser.DialogById;

/// Auth for this is done by <see cref="SubscriptionAuthHttpRequestInterceptor" />
public sealed class Subscriptions
[Authorize(Policy = AuthorizationPolicy.EndUser)]
public sealed class Subscriptions : ObjectType
{
[Subscribe]
[UseYourCustom]
[Topic($"{Constants.DialogUpdatedTopic}{{{nameof(dialogId)}}}")]
public DialogUpdatedPayload DialogUpdated(Guid dialogId,
[EventMessage] Guid eventMessage)
// [Subscribe]
// [UseYourCustom]
// [Topic($"{Constants.DialogUpdatedTopic}{{{nameof(dialogId)}}}")]
// public DialogUpdatedPayload DialogUpdated(Guid dialogId,
// [EventMessage] Guid eventMessage)
// {
// ArgumentNullException.ThrowIfNull(eventMessage);
// return new DialogUpdatedPayload { Id = dialogId };
// }

protected override void Configure(IObjectTypeDescriptor descriptor)
{
ArgumentNullException.ThrowIfNull(eventMessage);
return new DialogUpdatedPayload { Id = dialogId };
descriptor.Name("Subscriptions");
descriptor.Field("dialogUpdated")
.Authorize("enduser")
.Type<NonNullType<DialogUpdatedPayload>>()
.Argument("dialogId", a => a.Type<NonNullType<UuidType>>())
.Resolve(context =>
{
var eventMessage = context.GetEventMessage<Guid>();
return new DialogUpdatedPayload
{
Id = eventMessage
};
})
.Subscribe(async context =>
{
Console.WriteLine("Before subscription?");

// (╯°□°)╯︵ new Exception();

return await context.Service<ITopicEventReceiver>()
.SubscribeAsync<Guid>("onPing", context.RequestAborted);
});

// .Argument("eventMessage", a => a.Type<NonNullType<UuidType>())
// .Resolver(ctx =>
// {
// var dialogId = ctx.Argument<Guid>("dialogId");
// var eventMessage = ctx.Argument<Guid>("eventMessage");
// return new DialogUpdatedPayload { Id = dialogId };
// });
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public static IServiceCollection AddDialogportenGraphQl(this IServiceCollection
.RegisterDbContext<DialogDbContext>()
.AddDiagnosticEventListener<ApplicationInsightEventListener>()
.AddQueryType<Queries>()
// .AddType<DialogUpdatedPayload>()
.AddType<DialogByIdDeleted>()
.AddType<DialogByIdNotFound>()
.AddType<DialogByIdForbidden>()
Expand Down

0 comments on commit dd19d27

Please sign in to comment.