In the docs, I see that the terms offset and limit are used a lot. I am using keystone, which uses the terms first and skip. I am trying to make this work, but somewhere I am missing a key component.
Within my client creation, I have added a reference to offsetLimitPagination():
allComments: offsetLimitPagination(),
Then, I create my query along with variables to pass in:
const ALL_COMMENTS = gql`
query ALL_COMMENTS($id: ID!, $first: Int, $skip: Int) {
allComments(
where: { post: { id: $id }, parentId_is_null: true }
sortBy: id_DESC
first: $first
skip: $skip
) {
id
comment
created
votes
user {
name
}
}
}
`;
let first = 4;
let perPage = 4;
Then my useQuery statement:
variables: {
id: "ckracasxy75851o8vgpk909ibb",
first: 4,
skip: 0,
},
});
Then I have a button that activates ‘plzFetchMore’. For now, I am trying to make this work with a button, but then will upgrade it to be infinite scrolling. I need the basics figured out first. Here is what I have:
function plzFetchMore() {
first = first + first;
queryResult.fetchMore({
variables: {
id: "ckracasxy75851o8vgpk909ibb",
first: 4,
skip: first,
},
});
}
So with this code, everything appears to be working perfectly. I am able to fetch 4 new results of data, but the issue is, the older data is disappearing. How can I force the older data to stay on the page? If I could run a function that takes in cache/payload, I could do it manually. However, I believe the solution is much simpler than that. Can anyone guide me?
Thank you.