hotchocaly graphql查询页面/滤镜/嵌套数组字段上的排序
hotchocaly版本= 12.3.2.0
我希望能够在嵌套字段上分页/过滤/排序。例如,在用户ID = 1234的情况下,获取用户的第一个文档集,然后获取文档集中的第一个DocFile,该文档集由Docfile CreateDate订购。
public class User
{
public int Id {get;set}
[UsePaging]
[UseFiltering]
[UseSorting]
public List<Document> Documents { get; set; }
}
public class Document
{
[UsePaging]
[UseFiltering]
[UseSorting]
public List<DocFile> DocFiles { get; set; }
public User User {get;set;}
}
public class DocFile
{
public string Name {get;set}
public DateTime CreatedDate {get;set;}
public Document Document {get;set;}
}
[UseAppDbContext]
[UsePaging]
[UseProjection]
[UseFiltering]
[UseSorting]
public async Task<Connection<User>> GetUsersAsync(
IResolverContext context,
[ScopedService] DbContext dbContext,
CancellationToken cancellationToken
)
{
var dbResult = dbContext.Users.Filter(context).Sort(context).Project(context).ToArray();
var result = await dbResult.ApplyCursorPaginationAsync(context, cancellationToken);
return result;
}
GraphQl查询,
users(
where: {id: {eq: 1234}}
) {
nodes {
documents(first:1){
id
files(first:1 order:{createdDate: DESC}) {
nodes {
name
createdDate
}
}
}
}
}
但是当我执行GraphQl查询时,我当前会收到以下错误:
“ exceptionType”:“ invalidoperationException”, “消息”:“没有通用方法'OrderbyDescending'type'system.linq.sthumerable'与所提供的类型参数和参数兼容。如果该方法是非生成的,则不得提供类型的参数
。这样吗?
HotChocolate Version=12.3.2.0
I want to be able to page/filter/sort on nested fields. For example, where user id = 1234, get the user's 1st document set, then the 1st docFile in the document set, ordered by docFile createdDate.
public class User
{
public int Id {get;set}
[UsePaging]
[UseFiltering]
[UseSorting]
public List<Document> Documents { get; set; }
}
public class Document
{
[UsePaging]
[UseFiltering]
[UseSorting]
public List<DocFile> DocFiles { get; set; }
public User User {get;set;}
}
public class DocFile
{
public string Name {get;set}
public DateTime CreatedDate {get;set;}
public Document Document {get;set;}
}
[UseAppDbContext]
[UsePaging]
[UseProjection]
[UseFiltering]
[UseSorting]
public async Task<Connection<User>> GetUsersAsync(
IResolverContext context,
[ScopedService] DbContext dbContext,
CancellationToken cancellationToken
)
{
var dbResult = dbContext.Users.Filter(context).Sort(context).Project(context).ToArray();
var result = await dbResult.ApplyCursorPaginationAsync(context, cancellationToken);
return result;
}
GraphQL Query
users(
where: {id: {eq: 1234}}
) {
nodes {
documents(first:1){
id
files(first:1 order:{createdDate: DESC}) {
nodes {
name
createdDate
}
}
}
}
}
But when I execute the GraphQL query I currently get the following error:
"exceptionType": "InvalidOperationException",
"message": "No generic method 'OrderByDescending' on type 'System.Linq.Enumerable' is compatible with the supplied type arguments and arguments. No type arguments should be provided if the method is non-generic. "
Any idea on how to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

如果
[useorting]
注释来自hotchocaly.types
,这是过滤的旧方法(使用其他语法)。然后,在查询中应该是order_by
。尝试
[hotchocaly.data.useorting]
匹配查询。If the
[UseSorting]
annotation comes fromHotChocolate.Types
it's the old way of filtering (uses a different syntax). Then it should beorder_by
in your query.Try
[HotChocolate.Data.UseSorting]
to match your query.