-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHelloServerModule.cs
61 lines (53 loc) · 1.71 KB
/
HelloServerModule.cs
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using HotChocolate;
using HotChocolate.Data;
using HotChocolate.Types;
using Microsoft.Extensions.Logging;
using Modulight.Modules;
using Modulight.Modules.Hosting;
using Modulight.Modules.Server.GraphQL;
namespace Delights.Modules.Hello.Server
{
public static class ModuleExtensions
{
public static IModuleHostBuilder AddHelloServerModule(this IModuleHostBuilder builder)
{
builder.AddModule<HelloServerModule>();
return builder;
}
}
[Module(Url = SharedManifest.Url, Author = SharedManifest.Author, Description = SharedManifest.Description)]
[GraphQLModuleType("Hello", typeof(ModuleQuery))]
[ModuleService(typeof(ModuleService))]
public class HelloServerModule : GraphQLServerModule
{
public HelloServerModule(IModuleHost host) : base(host)
{
}
}
public class ModuleQuery
{
[UsePaging]
[UseProjection]
[UseFiltering]
[UseSorting]
public IQueryable<Message> GetMessages([Service] ModuleService service)
{
service.Logger.LogInformation(nameof(GetMessages));
return service.Messages.AsQueryable();
}
}
public record Message
{
public string Id { get; init; } = "";
public string Content { get; init; } = "";
}
public class ModuleService
{
public ModuleService(ILogger<HelloServerModule> logger) => Logger = logger;
public ILogger<HelloServerModule> Logger { get; private set; }
public List<Message> Messages { get; } = new List<Message>() {
new Message { Content = "Message 1", Id = "a" },
new Message { Content = "Message 2", Id = "b" },
};
}
}