728x90
반응형
- Program.cs
using GraphQLTestServer;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddSingleton<TestService>()
.AddHostedService(p => p.GetRequiredService<TestService>());
builder.Services
.AddGraphQLServer()
.AddQueryType<Query>()
.AddMutationType<Mutation>()
.AddSubscriptionType<Subscription>()
.AddInMemorySubscriptions();
var app = builder.Build();
app.UseRouting();
app.UseEndpoints(endpoints => {
endpoints.MapGraphQL("/");
});
app.Run();
TestService, Query, Mutation, Subscription 은 구현 예정이고,
AddGraphQLServer와 MapGraphQL은 hotchocolate library를 추가하면 해결된다.
- hotchocolate.AspNetCore library 설치
- 아래 파일들 생성
- TestService.cs
namespace GraphQLTestServer;
public class TestService : BackgroundService {
public TestService() {
Console.WriteLine("TestService starts,,,,");
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken) {
Console.WriteLine("Run First");
await Task.Delay(100, stoppingToken);
}
}
실행하면 아래와 같은 창이 뜨고,
create document 클릭하면 아래 처럼 나타남. apply 후 query나 mutation 등을 입력할 수 있다.
실행 창에는 다음과 같이 나타난다.
728x90
반응형