我在另一个关系上遇到问题。我希望能够对前端关系中的列标题进行排序。这是我的设置:
extend type Query {
entries(first: Int!,
page: Int,
type: String @eq,
site_id: ID @eq,
orderBy: _ @orderBy(
columns: ["created_at", "published_at"],
relations: [{ relation: "content", columns: ["title"] }]
)
): [Entry!]! @paginate
}
export const ALL_SITE_ENTRIES = gql`
query Entries(
$first: Int!,
$page: Int,
$type: String,
$site_id: ID,
$title: Mixed = null,
$orderBy: [EntriesOrderByOrderByClause!]) {
entries(
first: $first,
page: $page,
type: $type,
site_id: $site_id,
hasContent: {column: TITLE, operator: LIKE, value: $title},
orderBy: $orderBy
) {
data {
...EntryDetails
content{
id
title
status
}
}
paginatorInfo {
currentPage
lastPage
total
}
}
}
${EntryDetailsFragment}
`
现在,根据有关排序的文档,这应该没问题。在上发表并在工作中创作,非常出色。当我尝试按标题排序时,按
我的阿波罗呼叫:
this.$apollo.addSmartQuery('entries', {
query: ALL_SITE_ENTRIES,
fetchPolicy: 'no-cache',
variables() {
return {
type: this.entryType,
site_id: null,
blog_type: this.siteSettings.blog_type,
first: 25,
page: this.selectedPage,
orderBy: [{content: {column: 'TITLE'}, order: 'DESC'}],
}
},
});
我得到错误Expected type EntriesOrderByColumn at value[0].field
。发表于的作品只有:[{field: 'PUBLISHED_AT', order: 'DESC'}]
我从错误和文档中得到了混杂的信号。帮助
嗯。。。我在GraphQL上不是最好的,但有同样的问题,找到了对我有效的答案。
尝试更换:
$orderBy: [EntriesOrderByOrderByClause!]) {
发件人:
$orderBy: [EntriesOrderByRelationOrderByClause!]) {
对不起,我在这里打扰了,买吧,我有一个相关的问题。
我的产品有一个类别,但我不能按类别排序。我该怎么做?
我的查询
query getProducts($orderBy: [QueryGetProductsOrderByRelationOrderByClause!]) {
getProducts(orderBy: $orderBy) {
id
code
article
category{
id
name
}
stock
stockMin
priceBuy
priceSell
}
}
我的参数
{
"orderBy": {
"column": {"category": {
"column": "NAME"
},
"order": "DESC"
}
}
}
结构
getProducts(
orderBy: _
@orderBy(relations: [{ relation: "category", columns: ["name"] }])
): [Product!]!
type Product {
id: ID
code: String
article: String
category: Category
}
type Category {
id: ID
name: String
products: [Product]
}