Merge fetchMore Results

Hi, I’m trying do infinite Scroll and I struggle with merge results of fetchMore function.
I use useQuery, but in typePolicies I can not merge the next page result, I’m doing same like in docs,but nothing happens.
When I’ve used relayStylePagination func, useQuery doesnt, get result on the begining, when component load with search varr then useQuery returned response and fetchMore worked, but when search word is incoming dynamicly response is empty.
Is anyone has same problem ??

My typePolicies look like:

const client = new ApolloClient({
  link: authLink.concat(
    new HttpLink({ uri: "https://api.github.com/graphql" })
  ),
  cache: new InMemoryCache({
    typePolicies: {
      Query: {
        fields: {
          search: {
            merge(existing = {}, incoming) {
              return { ...existing, ...incoming };
            },
          },
        },
      },
    },
  }),
});

Hi @Robert_Palser were you able to solve this problem? I’m having the same issue

This is the one piece of working with the GitHub API that I did manage to figure out - I wrote my own merge function like this:

merge(existing = {}, incoming) {
        const existingNodes = existing.nodes || [];
        const incomingNodes = incoming.nodes || [];

        return {
            ...existing,
            ...incoming,
            nodes: [...existingNodes, ...incomingNodes],
            pageInfo: incoming.pageInfo
        };
    },

You will need to have the nodes and the pageInfo in your fragments so they can be used to fetch/merge. If you’re using edges instead of nodes, I don’t know how to do this…

My full source is here: GitHub - TryGhost/slimer-dashboard: GitHub Dashboard built in Apollo

1 Like

Thanks you @ErisDS, I’ll check it out