Skip to content
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
10 changes: 6 additions & 4 deletions src/GraphQL.EntityFramework/IncludeAppender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ public IQueryable<TItem> ApplyProjection<TDbContext, TItem>(
projection = MergeFilterFieldsIntoProjection(projection, filters, type);
}

if (!SelectExpressionBuilder.TryBuild<TItem>(projection, keyNames, derivedTypes, out var expression, out var includePaths, out var argumentFields))
// Includes are built from the same projection, so without a collection in it neither the
// select nor the includes fallback loads one
if (!LoadsCollection(projection))
{
return AddIncludesFromProjection(query, projection);
query = QuerySplitting.Remove(query);
}

if (!LoadsCollection(projection))
if (!SelectExpressionBuilder.TryBuild<TItem>(projection, keyNames, derivedTypes, out var expression, out var includePaths, out var argumentFields))
{
query = QuerySplitting.Remove(query);
return AddIncludesFromProjection(query, projection);
}

foreach (var includePath in includePaths)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
target: {
Data: {
splitInterfaceGraphConnection: {
totalCount: 2,
items: [
{
property: Value1
},
{
property: Value2
}
]
}
}
},
sql: [
{
Text:
select COUNT(*)
from BaseEntities as b
},
{
Text:
select b.Id,
b.Discriminator,
b.Property,
b.Status
from BaseEntities as b
order by b.Property
offset @p rows fetch next @p1 rows only,
Parameters: {
@p: 0,
@p1: 10
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@
where: BaseEntityWhere,
orderBy: [BaseEntityOrderBy!],
ids: [ID!]): BaseConnection!
splitInterfaceGraphConnection(
"Only return edges after the specified cursor."
after: String,
"Specifies the maximum number of edges to return, starting after the cursor specified by 'after', or the first number of edges if 'after' is not specified."
first: Int,
"Only return edges prior to the specified cursor."
before: String,
"Specifies the maximum number of edges to return, starting prior to the cursor specified by 'before', or the last number of edges if 'before' is not specified."
last: Int,
where: BaseEntityWhere,
orderBy: [BaseEntityOrderBy!],
ids: [ID!]): BaseConnection!
baseEntities(id: ID, ids: [ID!], where: BaseEntityWhere, orderBy: [BaseEntityOrderBy!], skip: Int, take: Int): [BaseEntity]!
derivedEntities(id: ID, ids: [ID!], where: DerivedEntityWhere, orderBy: [DerivedEntityOrderBy!], skip: Int, take: Int): [Derived!]!
derivedEntity(id: ID, ids: [ID!], where: DerivedEntityWhere): Derived!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,36 @@ public async Task Connection_split_query_without_collection()
await RunQuery(database, query, null, null, false, entities);
}

// The resolver's AsSplitQuery is removed from a connection over a type with derived types,
// since no collection is selected
[Fact]
public async Task Connection_split_query_with_derived_types_without_collection()
{
var query =
"""
{
splitInterfaceGraphConnection(first: 10) {
totalCount
items {
property
}
}
}
""";

var derived1 = new DerivedEntity
{
Property = "Value1"
};
var derived2 = new DerivedWithNavigationEntity
{
Property = "Value2"
};

await using var database = await sqlInstance.Build();
await RunQuery(database, query, null, null, false, [derived1, derived2]);
}

// The resolver's AsSplitQuery is kept, since the children are selected
[Fact]
public async Task Connection_split_query_with_collection()
Expand Down
7 changes: 7 additions & 0 deletions src/Tests/IntegrationTests/Query.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,13 @@ public Query(IEfGraphQLService<IntegrationDbContext> efGraphQlService)
name: "interfaceGraphConnection",
resolve: _ => _.DbContext.BaseEntities.OrderBy(_ => _.Property));

// Split for the children a request might select, over a type with derived types
efGraphQlService.AddQueryConnectionField<BaseEntity>(
this,
itemGraphType: typeof(BaseGraphType),
name: "splitInterfaceGraphConnection",
resolve: _ => _.DbContext.BaseEntities.AsSplitQuery().OrderBy(_ => _.Property));

AddQueryField(
name: "baseEntities",
graphType: typeof(BaseGraphType),
Expand Down
Loading