diff --git a/src/HotChocolate/Core/test/Execution.Tests/Projections/ProjectableDataLoaderTests.cs b/src/HotChocolate/Core/test/Execution.Tests/Projections/ProjectableDataLoaderTests.cs index 372c0ce21dd..9ebde32afc6 100644 --- a/src/HotChocolate/Core/test/Execution.Tests/Projections/ProjectableDataLoaderTests.cs +++ b/src/HotChocolate/Core/test/Execution.Tests/Projections/ProjectableDataLoaderTests.cs @@ -760,47 +760,26 @@ public async Task Project_Key_To_Collection_Expression_Integration() } [Fact] - public async Task Brand_Without_Country_Should_Allow_Nullable_Country() + public async Task Product_With_Nullable_Reference_Property_Set_To_Null() { // Arrange var queries = new List(); var connectionString = CreateConnectionString(); - - var services = new ServiceCollection() - .AddScoped(_ => queries) - .AddTransient(_ => new CatalogContext(connectionString)) - .AddDataLoader( - sp => new ProductByBrandIdDataLoader2( - sp, - sp.GetRequiredService>(), - sp.GetRequiredService(), - sp.GetRequiredService())) - .BuildServiceProvider(); - - await using var catalogContext = services.GetRequiredService(); - await catalogContext.Database.EnsureCreatedAsync(); - catalogContext.Brands.Add(new Brand - { - Name = "Some brand", - Details = new BrandDetails { Country = null }, - }); - await catalogContext.SaveChangesAsync(); + await CatalogContext.SeedAsync(connectionString); // Act var result = await new ServiceCollection() .AddScoped(_ => queries) .AddTransient(_ => new CatalogContext(connectionString)) .AddGraphQLServer() - .AddQueryType() - .AddTypeExtension(typeof(BrandListExtensions)) + .AddQueryType() .ExecuteRequestAsync( """ { - brandById(id: 1) { - details { - country { - name - } + productById(id: 1) { + name + type { + name } } } @@ -808,7 +787,6 @@ public async Task Brand_Without_Country_Should_Allow_Nullable_Country() // Assert Snapshot.Create() - .AddSql(queries) .Add(result, "Result") .MatchMarkdownSnapshot(); } @@ -890,6 +868,30 @@ public async Task> GetBrandByIdAsync( .ToListAsync(cancellationToken); } + public class ProductsWithNullBrandQuery + { + public async Task GetProductByIdAsync( + int id, + ISelection selection, + CatalogContext context, + CancellationToken cancellationToken) + => await context.Products + .Where(p => p.Id == id) + .Select(p => new ProductProjection + { + Name = p.Name, + }) + .Select(selection.AsSelector()) + .SingleOrDefaultAsync(cancellationToken); + + public class ProductProjection + { + public string Name { get; set; } = default!; + + public ProductType? Type { get; set; } + } + } + [ExtendObjectType] public class BrandExtensions { diff --git a/src/HotChocolate/Core/test/Execution.Tests/Projections/__snapshots__/ProjectableDataLoaderTests.Brand_Without_Country_Should_Allow_Nullable_Country.md b/src/HotChocolate/Core/test/Execution.Tests/Projections/__snapshots__/ProjectableDataLoaderTests.Brand_Without_Country_Should_Allow_Nullable_Country.md deleted file mode 100644 index ad6281da074..00000000000 --- a/src/HotChocolate/Core/test/Execution.Tests/Projections/__snapshots__/ProjectableDataLoaderTests.Brand_Without_Country_Should_Allow_Nullable_Country.md +++ /dev/null @@ -1,24 +0,0 @@ -# Brand_Without_Country_Should_Allow_Nullable_Country - -## SQL - -```text - -``` - -## Result - -```json -{ - "data": { - "brandById": [ - { - "details": { - "country": null - } - } - ] - } -} -``` - diff --git a/src/HotChocolate/Core/test/Execution.Tests/Projections/__snapshots__/ProjectableDataLoaderTests.Product_With_Nullable_Reference_Property_Set_To_Null.md b/src/HotChocolate/Core/test/Execution.Tests/Projections/__snapshots__/ProjectableDataLoaderTests.Product_With_Nullable_Reference_Property_Set_To_Null.md new file mode 100644 index 00000000000..6a547a2e753 --- /dev/null +++ b/src/HotChocolate/Core/test/Execution.Tests/Projections/__snapshots__/ProjectableDataLoaderTests.Product_With_Nullable_Reference_Property_Set_To_Null.md @@ -0,0 +1,12 @@ +# Product_With_Nullable_Reference_Property_Set_To_Null + +```json +{ + "data": { + "productById": { + "name": "Product 0-0", + "type": null + } + } +} +``` diff --git a/src/HotChocolate/Core/test/Execution.Tests/TestContext/Brand.cs b/src/HotChocolate/Core/test/Execution.Tests/TestContext/Brand.cs index be66eaaea6a..9814cc404e9 100644 --- a/src/HotChocolate/Core/test/Execution.Tests/TestContext/Brand.cs +++ b/src/HotChocolate/Core/test/Execution.Tests/TestContext/Brand.cs @@ -21,7 +21,7 @@ public class Brand public class BrandDetails { - public Country? Country { get; set; } + public Country Country { get; set; } = default!; } public class Country