previousResult is undefined when using updateQuery in fetchMore
See original GitHub issueIntended outcome:
The previousResult
variable should contain the previous data.
Actual outcome:
The previousResult
is undefined
How to reproduce the issue:
I followed the tutorial on this page using the Relay-style cursor pagination. After switching everything to the latest stable apollo version the previousResult
variable contains the data.
fetchMore({
variables: {
cursor: comments.pageInfo.endCursor
},
updateQuery: (previousResult, { fetchMoreResult }) => {
const newEdges = fetchMoreResult.comments.edges;
const pageInfo = fetchMoreResult.comments.pageInfo;
// Apollo v3 Beta
// previousResult is undefined
// Apollo latest stable version
// previousResult contains the data
return newEdges.length
? {
// Put the new comments at the end of the list and update `pageInfo`
// so we have the new `endCursor` and `hasNextPage` values
comments: {
__typename: previousResult.comments.__typename,
edges: [...previousResult.comments.edges, ...newEdges],
pageInfo
}
}
: previousResult;
}
})
Versions v3.0.0-beta.20
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:17 (4 by maintainers)
Top Results From Across the Web
When using fetchMore with useQuery previous data is undefined
I use fetchMore function for pagination with useQuery hook. Previous data is always undefined in the updateQuery in here.
Read more >Pagination - Apollo GraphQL Docs
By default, fetchMore will use the original query , so we just pass in new variables. Once the new data is returned from...
Read more >Reactive Query | Vue Apollo
Each key will be mapped with a '$' in the GraphQL document, for example foo ... Transform the previous result with new data...
Read more >GraphQL Pagination with Apollo Client in React - Educative.io
fetchMore ; variables; updateQuery. You may also want to shield away from the conditional renderings in the FetchMore component, which happens because of...
Read more >Vue Apollo "Typename" Is Undefined In Updatequery - ADocLib
The fetchMore method takes a map of variables to be sent with the new query.Here we're setting the offset to feed.length so that...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@Thomazella - Did you add a console logger in the area I recommended above? It sucks to add a logger there, but it helped me track down some issues that weren’t escaping in an obvious way. If using npm to install it, you’ll have to add it to the transpiled code, but it isn’t so bad. Also, feel free to ignore this if not using the InMemoryCache.
I’m experiencing the same issue in @apollo/client@3.2.2 when using useQuery. Any updates on this issue? I’ve noticed also the error is not deterministic and seems to be related to network latency.
@soltysaleksandr workaround works but it would be nice if it would work out of the box