Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Oct 29, 2024
1 parent 9115ef9 commit f686c16
Show file tree
Hide file tree
Showing 10 changed files with 156 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public class CustomOrderChildEntity
{
public Guid Id { get; set; } = Guid.NewGuid();
public Guid? ParentId { get; set; }
public CustomOrderParentEntity? Parent { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
public class CustomOrderChildGraphType :
EfObjectGraphType<IntegrationDbContext, CustomOrderChildEntity>
{
public CustomOrderChildGraphType(IEfGraphQLService<IntegrationDbContext> graphQlService) :
base(graphQlService) =>
AutoMap();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class CustomOrderParentEntity
{
public Guid Id { get; set; } = Guid.NewGuid();
public IList<CustomOrderChildEntity> Children { get; set; } = [];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
public class CustomOrderParentGraphType :
EfObjectGraphType<IntegrationDbContext, CustomOrderParentEntity>
{
public CustomOrderParentGraphType(IEfGraphQLService<IntegrationDbContext> graphQlService) :
base(graphQlService)
{
AddQueryField(
name: "customOrderChildren",
resolve: context =>
{
var parentId = context.Source.Id;
return context.DbContext.CustomOrderChildEntities
.Where(_ => _.ParentId == parentId);
});
AutoMap();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
target:
{
"data": {
"customOrder": [
{
"customOrderChildren": [
{
"id": "Guid_1"
},
{
"id": "Guid_2"
}
]
},
{
"customOrderChildren": [
{
"id": "Guid_3"
}
]
}
]
}
},
sql: [
{
Text:
SELECT [c].[Id]
FROM [CustomOrderParentEntities] AS [c],
HasTransaction: false
},
{
Text:
SELECT [c].[Id], [c].[ParentId]
FROM [CustomOrderChildEntities] AS [c]
WHERE [c].[ParentId] = @__parentId_0,
Parameters: {
@__parentId_0: {
Value: Guid_4,
IsNullable: true
}
},
HasTransaction: false
},
{
Text:
SELECT [c].[Id], [c].[ParentId]
FROM [CustomOrderChildEntities] AS [c]
WHERE [c].[ParentId] = @__parentId_0,
Parameters: {
@__parentId_0: {
Value: Guid_5,
IsNullable: true
}
},
HasTransaction: false
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
withNullableEntities(id: ID, ids: [ID!], where: [WhereExpression!], orderBy: [OrderBy!], skip: Int, take: Int): [WithNullable!]!
namedEntities(id: ID, ids: [ID!], where: [WhereExpression!], orderBy: [OrderBy!], skip: Int, take: Int): [NamedId!]!
misNamed(id: ID, ids: [ID!], where: [WhereExpression!], orderBy: [OrderBy!], skip: Int, take: Int): [WithMisNamedQueryParent!]!
customOrder(id: ID, ids: [ID!], where: [WhereExpression!], orderBy: [OrderBy!], skip: Int, take: Int): [CustomOrderParent!]!
parentEntities(id: ID, ids: [ID!], where: [WhereExpression!], orderBy: [OrderBy!], skip: Int, take: Int): [Parent!]!
childEntities(id: ID, ids: [ID!], where: [WhereExpression!], orderBy: [OrderBy!], skip: Int, take: Int): [Child!]!
dateEntities(id: ID, ids: [ID!], where: [WhereExpression!], orderBy: [OrderBy!], skip: Int, take: Int): [DateEntity!]!
Expand Down Expand Up @@ -219,6 +220,18 @@ type WithMisNamedQueryChild {
parentId: ID
}

type CustomOrderParent {
customOrderChildren(id: ID, ids: [ID!], where: [WhereExpression!], orderBy: [OrderBy!], skip: Int, take: Int): [CustomOrderChild!]!
children(id: ID, ids: [ID!], where: [WhereExpression!], orderBy: [OrderBy!], skip: Int, take: Int): [CustomOrderChild!]!
id: ID!
}

type CustomOrderChild {
parent: CustomOrderParent
id: ID!
parentId: ID
}

type Parent {
childrenConnection(
"Only return edges after the specified cursor."
Expand Down
38 changes: 38 additions & 0 deletions src/Tests/IntegrationTests/IntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2514,6 +2514,44 @@ public async Task MisNamedQuery()
await RunQuery(database, query, null, null, false, [entity1, entity2, entity3, entity4, entity5]);
}

[Fact]
public async Task CustomOrder()
{
var query =
"""
{
customOrder
{
customOrderChildren
{
id
}
}
}
""";

var entity1 = new CustomOrderParentEntity();
var entity2 = new CustomOrderChildEntity
{
Parent = entity1
};
var entity3 = new CustomOrderChildEntity
{
Parent = entity1
};
entity1.Children.Add(entity2);
entity1.Children.Add(entity3);
var entity4 = new CustomOrderParentEntity();
var entity5 = new CustomOrderChildEntity
{
Parent = entity4
};
entity4.Children.Add(entity5);

await using var database = await sqlInstance.Build();
await RunQuery(database, query, null, null, false, [entity1, entity2, entity3, entity4, entity5]);
}

[Fact(Skip = "fix order")]
public async Task Parent_child()
{
Expand Down
4 changes: 4 additions & 0 deletions src/Tests/IntegrationTests/MyDataContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public class IntegrationDbContext(DbContextOptions options) :
public DbSet<FilterParentEntity> FilterParentEntities { get; set; } = null!;
public DbSet<FilterChildEntity> FilterChildEntities { get; set; } = null!;
public DbSet<ChildEntity> ChildEntities { get; set; } = null!;
public DbSet<CustomOrderChildEntity> CustomOrderChildEntities { get; set; } = null!;
public DbSet<CustomOrderParentEntity> CustomOrderParentEntities { get; set; } = null!;
public DbSet<WithMisNamedQueryChildEntity> WithMisNamedQueryChildEntities { get; set; } = null!;
public DbSet<WithMisNamedQueryParentEntity> WithMisNamedQueryParentEntities { get; set; } = null!;
public DbSet<Level1Entity> Level1Entities { get; set; } = null!;
Expand Down Expand Up @@ -44,6 +46,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
modelBuilder.Entity<ChildEntity>();
modelBuilder.Entity<WithMisNamedQueryParentEntity>();
modelBuilder.Entity<WithMisNamedQueryChildEntity>();
modelBuilder.Entity<CustomOrderParentEntity>();
modelBuilder.Entity<CustomOrderChildEntity>();
modelBuilder.Entity<IncludeNonQueryableB>();
modelBuilder.Entity<IncludeNonQueryableA>()
.HasOne(_ => _.IncludeNonQueryableB)
Expand Down
4 changes: 4 additions & 0 deletions src/Tests/IntegrationTests/Query.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public Query(IEfGraphQLService<IntegrationDbContext> efGraphQlService)
name: "misNamed",
resolve: _ => _.DbContext.WithMisNamedQueryParentEntities);

AddQueryField(
name: "customOrder",
resolve: _ => _.DbContext.CustomOrderParentEntities);

AddQueryField(
name: "parentEntities",
resolve: _ => _.DbContext.ParentEntities);
Expand Down
2 changes: 2 additions & 0 deletions src/Tests/IntegrationTests/Schema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public Schema(IServiceProvider resolver) :
RegisterTypeMapping(typeof(WithMisNamedQueryChildEntity), typeof(WithMisNamedQueryChildGraphType));
RegisterTypeMapping(typeof(WithNullableEntity), typeof(WithNullableGraphType));
RegisterTypeMapping(typeof(NamedIdEntity), typeof(NamedIdGraphType));
RegisterTypeMapping(typeof(CustomOrderParentEntity), typeof(CustomOrderParentGraphType));
RegisterTypeMapping(typeof(CustomOrderChildEntity), typeof(CustomOrderChildGraphType));
RegisterTypeMapping(typeof(DerivedEntity), typeof(DerivedGraphType));
RegisterTypeMapping(typeof(DerivedWithNavigationEntity), typeof(DerivedWithNavigationGraphType));
RegisterTypeMapping(typeof(DerivedChildEntity), typeof(DerivedChildGraphType));
Expand Down

0 comments on commit f686c16

Please sign in to comment.