使用@queryfield进行AWS放大的分类列表的问题
这是我遇到过的先前问题的后续措施(从AWS无法正确排序)。
在遵循了给出的建议之后,我为查询列表stortedalBumCategory生成了代码:
export const listSortedAlbumCategories = /* GraphQL */ `
query ListSortedAlbumCategories(
$id: ID
$sortOrder: ModelIntKeyConditionInput
$sortDirection: ModelSortDirection
$filter: ModelAlbumCategoryFilterInput
$limit: Int
$nextToken: String
) {
listSortedAlbumCategories(
id: $id
sortOrder: $sortOrder
sortDirection: $sortDirection
filter: $filter
limit: $limit
nextToken: $nextToken
) {
items {
id
title
sortOrder
albums {
nextToken
}
createdAt
updatedAt
}
nextToken
}
}
然后,我更新了代码以使用该查询:
useEffect( () => {
const fetchAlbumCategories = async() => {
try {
const data = await API.graphql(graphqlOperation(listSortedAlbumCategories));
setCategories(data.data.listSortedAlbumCategories.items);
} catch (e) {
console.log(e);
}
}
console.log("Fetching album categories...")
fetchAlbumCategories();
},[]);
但是,我收到以下错误消息:
Object {
"data": null,
"errors": Array [
Object {
"locations": Array [
Object {
"column": 15,
"line": 1,
"sourceName": null,
},
],
"message": "Variable 'id' has coerced Null value for NonNull type 'ID!'",
"path": null,
},
],
}
Object {
"data": Object {
"listSortedAlbumCategories": null,
},
"errors": Array [
Object {
"data": null,
"errorInfo": null,
"errorType": "MappingTemplate",
"locations": Array [
Object {
"column": 3,
"line": 2,
"sourceName": null,
},
],
"message": "Expression block '$[query]' requires an expression",
"path": Array [
"listSortedAlbumCategories",
],
},
],
}
我似乎无法找到查询的问题,看起来与原始的ListalBumCategory非常相似,但添加了排序订单。请帮忙!
This is a follow-up to a previous question I had (Elements Pulled From AWS Not Being Sorted Properly).
After following the advice given, I generated code for a query listSortedAlbumCategories seen here:
export const listSortedAlbumCategories = /* GraphQL */ `
query ListSortedAlbumCategories(
$id: ID
$sortOrder: ModelIntKeyConditionInput
$sortDirection: ModelSortDirection
$filter: ModelAlbumCategoryFilterInput
$limit: Int
$nextToken: String
) {
listSortedAlbumCategories(
id: $id
sortOrder: $sortOrder
sortDirection: $sortDirection
filter: $filter
limit: $limit
nextToken: $nextToken
) {
items {
id
title
sortOrder
albums {
nextToken
}
createdAt
updatedAt
}
nextToken
}
}
Then, I updated my code to use that query:
useEffect( () => {
const fetchAlbumCategories = async() => {
try {
const data = await API.graphql(graphqlOperation(listSortedAlbumCategories));
setCategories(data.data.listSortedAlbumCategories.items);
} catch (e) {
console.log(e);
}
}
console.log("Fetching album categories...")
fetchAlbumCategories();
},[]);
However, I get the following error message:
Object {
"data": null,
"errors": Array [
Object {
"locations": Array [
Object {
"column": 15,
"line": 1,
"sourceName": null,
},
],
"message": "Variable 'id' has coerced Null value for NonNull type 'ID!'",
"path": null,
},
],
}
Object {
"data": Object {
"listSortedAlbumCategories": null,
},
"errors": Array [
Object {
"data": null,
"errorInfo": null,
"errorType": "MappingTemplate",
"locations": Array [
Object {
"column": 3,
"line": 2,
"sourceName": null,
},
],
"message": "Expression block '$[query]' requires an expression",
"path": Array [
"listSortedAlbumCategories",
],
},
],
}
I can't seem to find the issue with my query, it looks very similar to the original listAlbumCategorys but with the sortOrder added. Please help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
表或GSI上的查询要求您指定分区密钥。如果不指定分区密钥,您将无法从DynamoDB获得分类的响应。
您配置的GSI需要您指定“ ID”。
在情况下,您可以通过将分区键设置为所有项目(例如“类别”)来解决此问题。
Queries on a table or GSI require that you specify the partition key. You cannot get a sorted response from DynamoDB without specifying a partition key.
The GSI you have configured requires you to specify “id”.
You can get around this in your case by setting the partition key to a constant value for all items, like “category”.