Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Issue with abstract types when not all selected #4444

Merged
merged 5 commits into from
Nov 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Linq.Expressions;
using HotChocolate.Data.Projections.Expressions.Handlers;
using HotChocolate.Language;
using HotChocolate.Resolvers;
using HotChocolate.Types;

namespace HotChocolate.Data.Projections.Expressions
Expand All @@ -18,6 +19,14 @@ protected override ISelectionVisitorAction VisitObjectType(
var isAbstractType = field.Type.NamedType().IsAbstractType();
if (isAbstractType && context.TryGetQueryableScope(out QueryableProjectionScope? scope))
{
IReadOnlyList<IFieldSelection> selections =
context.Context.GetSelections(objectType, selectionSet, true);

if (selections.Count == 0)
{
return Continue;
}

context.PushInstance(
Expression.Convert(context.GetInstance(), objectType.RuntimeType));
scope.Level.Push(new Queue<MemberAssignment>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,31 @@ ... on Bar {
res1.MatchSqlSnapshot();
}

[Fact]
public async Task Create_Interface_Without_Missing()
{
// arrange
IRequestExecutor tester =
_cache.CreateSchema(_barEntities, OnModelCreating, configure: ConfigureSchema);

// act
// assert
IExecutionResult res1 = await tester.ExecuteAsync(
QueryRequestBuilder.New()
.SetQuery(
@"
{
root {
... on Foo {
fooProp
}
}
}")
.Create());

res1.MatchSqlSnapshot();
}

public static void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<AbstractType>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,32 @@ ... on Bar {
res1.MatchSqlSnapshot();
}

[Fact]
public async Task Create_Union_Without_Missing()
{
// arrange
IRequestExecutor tester =
_cache.CreateSchema(_barEntities, OnModelCreating, configure: ConfigureSchema);

// act
// assert
IExecutionResult res1 = await tester.ExecuteAsync(
QueryRequestBuilder.New()
.SetQuery(
@"
{
root {
... on Foo {
fooProp
}
}
}")
.Create());

res1.MatchSqlSnapshot();
}


public static void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<AbstractType>()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"data": {
"root": [
null,
{
"fooProp": "FooProp"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SELECT "d"."d" = 'foo', "d"."FooProp"
FROM "Data" AS "d"
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"data": {
"root": [
null,
{
"fooProp": "FooProp"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SELECT "d"."d" = 'foo', "d"."FooProp"
FROM "Data" AS "d"