Repository navigation
Closed
Labels
Description
Product
Hot Chocolate
Version
15.0.0
Link to minimal reproduction
Steps to reproduce
dotnet build in the folder will print the following warning:
warning CS8619: Nullability of reference types in value of type 'Task<Author?>' doesn't match target type 'Task<Author>'.
var builder = WebApplication.CreateBuilder(args);
builder.AddGraphQL().AddTypes();
var app = builder.Build();
app.MapGraphQL();
app.RunWithGraphQLCommands(args);
public record Book(string Title, int AuthorId);
public record Author(string Name);
[ExtendObjectType<Book>]
public static class BookExtensions
{
public static Task<Author> GetAuthorAsync(
[Parent] Book book,
IAuthorByIdDataLoader authorById,
CancellationToken cancellationToken)
// ISSUE
// Nullability of reference types in value of type 'System.Threading.Tasks.Task<Author?>' does not match target type 'System.Threading.Tasks.Task<Author>'
=> authorById.LoadAsync(book.AuthorId, cancellationToken);
}
namespace GettingStarted
{
internal static class AuthorDataLoaders
{
[DataLoader]
public static Task<Dictionary<int, Author>> GetAuthorByIdAsync(
IReadOnlyList<int> authorIds,
CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
}
}
[QueryType]
public static class Query
{
public static Book GetBook()
=> new Book("C# in depth.", 1);
}What is expected?
We are trying to migrate from hotchocolate 13 to 15. We expect [DataLoader]s to continue working as is
What is actually happening?
we are getting a lot of CS8619 because data loaders now return null
Program.cs(19,12): warning CS8619: Nullability of reference types in value of type 'Task<Author?>' doesn't match target type 'Task<Author>'.
Relevant log output
Additional context
This change happened in #7389
and the ability was to control this behaviour was discussed in #2911
Activity
liyanjie2048 commentedon Feb 12, 2026
You might be looking for the method
dataLoader.LoadRequiredAsync.michaelstaib commentedon Feb 13, 2026
Exactly right ... if you require a key to always be resolvable use
LoadRequiredAsync. However, in GraphQL a good practice is to let composite return types be nullable, if they could reasonable be nullable.LoadRequiredAsyncwill throw an exception of the DataLoader returnsnullfor the requested key.cliedeman commentedon Feb 13, 2026
thanks @michaelstaib @liyanjie2048
Ill try to add this to the migration notes