Skip to content

Commit f686c16

Browse files
committed
.
1 parent 9115ef9 commit f686c16

10 files changed

+156
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
public class CustomOrderChildEntity
2+
{
3+
public Guid Id { get; set; } = Guid.NewGuid();
4+
public Guid? ParentId { get; set; }
5+
public CustomOrderParentEntity? Parent { get; set; }
6+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
public class CustomOrderChildGraphType :
2+
EfObjectGraphType<IntegrationDbContext, CustomOrderChildEntity>
3+
{
4+
public CustomOrderChildGraphType(IEfGraphQLService<IntegrationDbContext> graphQlService) :
5+
base(graphQlService) =>
6+
AutoMap();
7+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
public class CustomOrderParentEntity
2+
{
3+
public Guid Id { get; set; } = Guid.NewGuid();
4+
public IList<CustomOrderChildEntity> Children { get; set; } = [];
5+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
public class CustomOrderParentGraphType :
2+
EfObjectGraphType<IntegrationDbContext, CustomOrderParentEntity>
3+
{
4+
public CustomOrderParentGraphType(IEfGraphQLService<IntegrationDbContext> graphQlService) :
5+
base(graphQlService)
6+
{
7+
AddQueryField(
8+
name: "customOrderChildren",
9+
resolve: context =>
10+
{
11+
var parentId = context.Source.Id;
12+
return context.DbContext.CustomOrderChildEntities
13+
.Where(_ => _.ParentId == parentId);
14+
});
15+
AutoMap();
16+
}
17+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
target:
3+
{
4+
"data": {
5+
"customOrder": [
6+
{
7+
"customOrderChildren": [
8+
{
9+
"id": "Guid_1"
10+
},
11+
{
12+
"id": "Guid_2"
13+
}
14+
]
15+
},
16+
{
17+
"customOrderChildren": [
18+
{
19+
"id": "Guid_3"
20+
}
21+
]
22+
}
23+
]
24+
}
25+
},
26+
sql: [
27+
{
28+
Text:
29+
SELECT [c].[Id]
30+
FROM [CustomOrderParentEntities] AS [c],
31+
HasTransaction: false
32+
},
33+
{
34+
Text:
35+
SELECT [c].[Id], [c].[ParentId]
36+
FROM [CustomOrderChildEntities] AS [c]
37+
WHERE [c].[ParentId] = @__parentId_0,
38+
Parameters: {
39+
@__parentId_0: {
40+
Value: Guid_4,
41+
IsNullable: true
42+
}
43+
},
44+
HasTransaction: false
45+
},
46+
{
47+
Text:
48+
SELECT [c].[Id], [c].[ParentId]
49+
FROM [CustomOrderChildEntities] AS [c]
50+
WHERE [c].[ParentId] = @__parentId_0,
51+
Parameters: {
52+
@__parentId_0: {
53+
Value: Guid_5,
54+
IsNullable: true
55+
}
56+
},
57+
HasTransaction: false
58+
}
59+
]
60+
}

src/Tests/IntegrationTests/IntegrationTests.SchemaPrint.verified.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
withNullableEntities(id: ID, ids: [ID!], where: [WhereExpression!], orderBy: [OrderBy!], skip: Int, take: Int): [WithNullable!]!
88
namedEntities(id: ID, ids: [ID!], where: [WhereExpression!], orderBy: [OrderBy!], skip: Int, take: Int): [NamedId!]!
99
misNamed(id: ID, ids: [ID!], where: [WhereExpression!], orderBy: [OrderBy!], skip: Int, take: Int): [WithMisNamedQueryParent!]!
10+
customOrder(id: ID, ids: [ID!], where: [WhereExpression!], orderBy: [OrderBy!], skip: Int, take: Int): [CustomOrderParent!]!
1011
parentEntities(id: ID, ids: [ID!], where: [WhereExpression!], orderBy: [OrderBy!], skip: Int, take: Int): [Parent!]!
1112
childEntities(id: ID, ids: [ID!], where: [WhereExpression!], orderBy: [OrderBy!], skip: Int, take: Int): [Child!]!
1213
dateEntities(id: ID, ids: [ID!], where: [WhereExpression!], orderBy: [OrderBy!], skip: Int, take: Int): [DateEntity!]!
@@ -219,6 +220,18 @@ type WithMisNamedQueryChild {
219220
parentId: ID
220221
}
221222

223+
type CustomOrderParent {
224+
customOrderChildren(id: ID, ids: [ID!], where: [WhereExpression!], orderBy: [OrderBy!], skip: Int, take: Int): [CustomOrderChild!]!
225+
children(id: ID, ids: [ID!], where: [WhereExpression!], orderBy: [OrderBy!], skip: Int, take: Int): [CustomOrderChild!]!
226+
id: ID!
227+
}
228+
229+
type CustomOrderChild {
230+
parent: CustomOrderParent
231+
id: ID!
232+
parentId: ID
233+
}
234+
222235
type Parent {
223236
childrenConnection(
224237
"Only return edges after the specified cursor."

src/Tests/IntegrationTests/IntegrationTests.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2514,6 +2514,44 @@ public async Task MisNamedQuery()
25142514
await RunQuery(database, query, null, null, false, [entity1, entity2, entity3, entity4, entity5]);
25152515
}
25162516

2517+
[Fact]
2518+
public async Task CustomOrder()
2519+
{
2520+
var query =
2521+
"""
2522+
{
2523+
customOrder
2524+
{
2525+
customOrderChildren
2526+
{
2527+
id
2528+
}
2529+
}
2530+
}
2531+
""";
2532+
2533+
var entity1 = new CustomOrderParentEntity();
2534+
var entity2 = new CustomOrderChildEntity
2535+
{
2536+
Parent = entity1
2537+
};
2538+
var entity3 = new CustomOrderChildEntity
2539+
{
2540+
Parent = entity1
2541+
};
2542+
entity1.Children.Add(entity2);
2543+
entity1.Children.Add(entity3);
2544+
var entity4 = new CustomOrderParentEntity();
2545+
var entity5 = new CustomOrderChildEntity
2546+
{
2547+
Parent = entity4
2548+
};
2549+
entity4.Children.Add(entity5);
2550+
2551+
await using var database = await sqlInstance.Build();
2552+
await RunQuery(database, query, null, null, false, [entity1, entity2, entity3, entity4, entity5]);
2553+
}
2554+
25172555
[Fact(Skip = "fix order")]
25182556
public async Task Parent_child()
25192557
{

src/Tests/IntegrationTests/MyDataContext.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ public class IntegrationDbContext(DbContextOptions options) :
88
public DbSet<FilterParentEntity> FilterParentEntities { get; set; } = null!;
99
public DbSet<FilterChildEntity> FilterChildEntities { get; set; } = null!;
1010
public DbSet<ChildEntity> ChildEntities { get; set; } = null!;
11+
public DbSet<CustomOrderChildEntity> CustomOrderChildEntities { get; set; } = null!;
12+
public DbSet<CustomOrderParentEntity> CustomOrderParentEntities { get; set; } = null!;
1113
public DbSet<WithMisNamedQueryChildEntity> WithMisNamedQueryChildEntities { get; set; } = null!;
1214
public DbSet<WithMisNamedQueryParentEntity> WithMisNamedQueryParentEntities { get; set; } = null!;
1315
public DbSet<Level1Entity> Level1Entities { get; set; } = null!;
@@ -44,6 +46,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
4446
modelBuilder.Entity<ChildEntity>();
4547
modelBuilder.Entity<WithMisNamedQueryParentEntity>();
4648
modelBuilder.Entity<WithMisNamedQueryChildEntity>();
49+
modelBuilder.Entity<CustomOrderParentEntity>();
50+
modelBuilder.Entity<CustomOrderChildEntity>();
4751
modelBuilder.Entity<IncludeNonQueryableB>();
4852
modelBuilder.Entity<IncludeNonQueryableA>()
4953
.HasOne(_ => _.IncludeNonQueryableB)

src/Tests/IntegrationTests/Query.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ public Query(IEfGraphQLService<IntegrationDbContext> efGraphQlService)
4444
name: "misNamed",
4545
resolve: _ => _.DbContext.WithMisNamedQueryParentEntities);
4646

47+
AddQueryField(
48+
name: "customOrder",
49+
resolve: _ => _.DbContext.CustomOrderParentEntities);
50+
4751
AddQueryField(
4852
name: "parentEntities",
4953
resolve: _ => _.DbContext.ParentEntities);

src/Tests/IntegrationTests/Schema.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public Schema(IServiceProvider resolver) :
2525
RegisterTypeMapping(typeof(WithMisNamedQueryChildEntity), typeof(WithMisNamedQueryChildGraphType));
2626
RegisterTypeMapping(typeof(WithNullableEntity), typeof(WithNullableGraphType));
2727
RegisterTypeMapping(typeof(NamedIdEntity), typeof(NamedIdGraphType));
28+
RegisterTypeMapping(typeof(CustomOrderParentEntity), typeof(CustomOrderParentGraphType));
29+
RegisterTypeMapping(typeof(CustomOrderChildEntity), typeof(CustomOrderChildGraphType));
2830
RegisterTypeMapping(typeof(DerivedEntity), typeof(DerivedGraphType));
2931
RegisterTypeMapping(typeof(DerivedWithNavigationEntity), typeof(DerivedWithNavigationGraphType));
3032
RegisterTypeMapping(typeof(DerivedChildEntity), typeof(DerivedChildGraphType));

0 commit comments

Comments
 (0)