My schema.graphql
file auto generated below query in graphql/queries.js
file by running amplify push
command.
Here is the schema file that generates query automatically.
schema.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
}
Here's the queries generated by schema graphql.
queries.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
}
}
}
`;
I added (limit: 10, sortDirection: DESC)
to posts
to get the 10 latest posts from the user but can't figure out how to pass nextToken
value to get another 10 posts after the first query.
How do I pass nextToken
value to the posts so I can get next 10 posts?
Assuming you are using the graphqlOperation
helper method:
const newData = await API.graphql(graphqlOperation(listUser, { nextToken }));
Here, nextToken
from previous request is passed as an argument using object shorthand notation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With