kamilkisiela / apollo-angular

A fully-featured, production ready caching GraphQL client for Angular and every GraphQL server 🎁
https://apollo-angular.com
MIT License
1.5k stars 309 forks source link

Feedback for “Pagination” #2040

Closed DzelmeRichards closed 1 week ago

DzelmeRichards commented 1 year ago

Hi Could You, please, help me figure this out. I am building an app in angular 15, using "apollo-angular": "^4.2.0" and "@apollo/client": "^3.0.0" I have a search page, that searches my database. search results are displayed as infinite scroll. I have two functions getData and fechMore. Second function is called when user scrolls down. It works with fetchPolicy: 'network-only', but i need to use Apollo caching feature. Documentation is confusing for me. I would like Apollo to cache data and if same search occurs second time, the data to be loaded from cache. Also if user loads more data, it should be merged in cache with existing one. So all previously fetched data could be loaded from cache on second search event. Is that possible? Which approach would You recommend to achieve desired result? Also I cant put updateQuery in loadMore() { this.feedQuery.fetchMore({ variables: { offset: this.offset, }, updateQuery: (prev, { fetchMoreResult }) => { if (!fetchMoreResult) return prev;

    return Object.assign({}, prev, {
      feed: [...prev.feed, ...fetchMoreResult.feed],
    });
  },
});

} } I get an error Argument of type '{ query: TypedDocumentNode<unknown, unknown>; variables: { input: SearchObj; cursor: string; }; updateQuery: (prev: any, { fetchMoreResult }: { fetchMoreResult: any; }) => any; }' is not assignable to parameter of type 'FetchMoreQueryOptions<unknown, MyQueryResponse>'. Object literal may only specify known properties, and 'updateQuery' does not exist in type 'FetchMoreQueryOptions<unknown, QueryResponse>'.