Ohs*_*sik 8 graphql aws-appsync aws-amplify
我的schema.graphql文件graphql/queries.js通过运行amplify push命令在文件中自动生成以下查询。
这是自动生成查询的架构文件。
模式.graphql
type User @model {
id: String!
uuid: String!
following: [String]
follower: [String]
posts: [Post] @connection(name: "Userposts", sortField: "createdAt")
}
type Post
@model
@auth(
rules: [
{ allow: owner },
{ allow: groups, groups: ["Admin"] }
]
) {
id: ID!
author: User! @connection(name: "Userposts")
status: Status!
draft: Boolean
content: AWSJSON!
loved: [String]
comments: [Comment] @connection(name: "PostComments", sortField: "createdAt")
createdAt: AWSDateTime
updatedAt: AWSDateTime
}
enum Status {
PRIVATE
PUBLIC
}
Run Code Online (Sandbox Code Playgroud)
这是模式 graphql 生成的查询。
查询.js
export const getUser = `query GetUser($id: ID!) {
getUser(id: $id) {
id
uuid
following
follower
posts(limit: 10, sortDirection: DESC) {
items {
id
privacy
draft
content
loved
createdAt
updatedAt
}
nextToken
}
notifications {
items {
id
content
category
link
createdAt
}
nextToken
}
}
}
`;
Run Code Online (Sandbox Code Playgroud)
我添加(limit: 10, sortDirection: DESC)了posts以从用户那里获取 10 个最新帖子,但无法弄清楚如何nextToken在第一次查询后传递值以获取另外 10 个帖子。
如何将nextToken价值传递给帖子,以便获得接下来的 10 个帖子?
假设您正在使用graphqlOperation辅助方法:
const newData = await API.graphql(graphqlOperation(listUser, { nextToken }));
Run Code Online (Sandbox Code Playgroud)
在这里,nextToken来自上一个请求使用对象速记符号作为参数传递。
| 归档时间: |
|
| 查看次数: |
5120 次 |
| 最近记录: |