hotchoc - supporting multiple object for resolving your object in graphql
Let's say you need to organize your code and instead of placing all the query method into a single object like you can do with AddQueryType<> in hotchoc graphql, you can place this into multiple object for easy maintenance.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
builder.Services.AddGraphQLServer().AddQueryType(q => q.Name("Query")) | |
.AddType<Query>().AddType<QueryBook>(); |
For the rest of your classes you can have the followings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ExtendObjectType("Query")] | |
public class Query | |
{ | |
public async Task<ICollection<TodoReader.WeatherForecast>> GetTodosAsync( | |
[Service] TodoService service, | |
CancellationToken cancellationToken) | |
{ | |
return await service.GetWeatherForecastAsync(cancellationToken); | |
} | |
} | |
[ExtendObjectType("Query")] | |
public class QueryBook | |
{ | |
public async Task<Book> GetBookAsync() | |
{ | |
await Task.Delay(100); | |
return new Book | |
{ | |
Title = "C# in depth.", | |
Author = new Author | |
{ | |
Name = "Jon Skeet" | |
} | |
}; | |
} | |
} | |
public class Book | |
{ | |
public string Title { get; set; } | |
public Author Author { get; set; } | |
} | |
public class Author | |
{ | |
public string Name { get; set; } | |
} |
That's it!
Comments