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. 


builder.Services.AddGraphQLServer().AddQueryType(q => q.Name("Query"))
.AddType<Query>().AddType<QueryBook>();


For the rest of your classes you can have the followings

[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

Popular posts from this blog

The specified initialization vector (IV) does not match the block size for this algorithm

NodeJS: Error: spawn EINVAL in window for node version 20.20 and 18.20