使用@queryfield进行AWS放大的分类列表的问题

发布于 2025-02-09 13:23:07 字数 2208 浏览 1 评论 0原文

这是我遇到过的先前问题的后续措施(从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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

粉红×色少女 2025-02-16 13:23:07

表或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”.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文