-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDemoSubscription.cs
More file actions
38 lines (34 loc) · 1.19 KB
/
Copy pathDemoSubscription.cs
File metadata and controls
38 lines (34 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using Demo.Server.Core.BusinessEntity;
using Demo.Server.Core.GraphQl.Types;
using Demo.Server.Core.Service.Interface;
using GraphQL.Resolvers;
using GraphQL.Subscription;
using GraphQL.Types;
using System;
namespace Demo.Server.Core.GraphQl.Schema
{
public class DemoSubscription: ObjectGraphType<object>
{
private readonly IFeedbackEventService _feedbackEventService;
public DemoSubscription(IFeedbackEventService feedbackEventService)
{
_feedbackEventService = feedbackEventService;
Name = "Subscription";
AddField(new EventStreamFieldType
{
Name = "feedbackEvent",
Type = typeof(FeedbackEventType),
Resolver = new FuncFieldResolver<FeedbackEvent>(ResolveEvent),
Subscriber = new EventStreamResolver<FeedbackEvent>(Subscribe)
});
}
private FeedbackEvent ResolveEvent(ResolveFieldContext context)
{
return context.Source as FeedbackEvent;
}
private IObservable<FeedbackEvent> Subscribe(ResolveEventStreamContext context)
{
return _feedbackEventService.EventStream();
}
}
}