仅限 AWS AppSync returns 10 个关于连接查询的项目

AWS AppSync only returns 10 items on query on connection

我是 AppSync 的新手,正在尝试了解它的工作原理以及设置它的正确方法。

我创建了 schema.graphql 如下所示。

type User @model {
  id: String!
  following: [String]
  follower: [String]
  journals: [Journal] @connection(name: "UserJournals", sortField: "createdAt")
  notifications: [Notification] @connection(name: "UserNotifications", sortField: "createdAt")
}

type Journal @model {
  id: ID!
  author: User! @connection(name: "UserJournals")
  privacy: String!
  content: AWSJSON!
  loved: [String]
  createdAt: String
  updatedAt: String
}

这由 AppSync 自动创建 queries.js。

export const getUser = `query GetUser($id: ID!) {
  getUser(id: $id) {
    id
    following
    follower
    journals {
      items {
        id
        privacy
        content
        loved
        createdAt
        updatedAt
      }
      nextToken
    }
    notifications {
      items {
        id
        content
        category
        link
        createdAt
      }
      nextToken
    }
  }
}
`;

我注意到查询 getUser 仅 returns 10 journals 项并且不确定如何将其设置为超过 10 项或以正确的方式查询并将更多期刊添加到这 10 项中getUser.

查询的项目

由于您没有在查询中显式传递 limit 参数,因此 journals 解析器的请求映射模板将其默认为 10 个项目。如果您想更改此默认值,请转至 AppSync 控制台上的架构页面,导航至架构页面解析器部分下的 journals 字段。这将显示该字段的解析器定义,然后您可以将 10 的默认值更新为您喜欢的任何值。或者,您可以将其作为查询参数传递。

仅供参考 - 此默认值在 GitHub 的 amplify-cli 存储库中定义,可以在 here.[=14= 中找到]