Caching nested objects in pagination

Hello, I am trying to implement offsetLimitPagination function to GetApplicationComments query. The problem comes when I have nested comments ( items ). Comment typename is ApplicationComment .

In this situation getApplicationComments query returns data that is an empty array.

image

query GetApplicationComments($offset: Int! $limit: Int!) {
  getApplicationComments(offset: $offset limit: $limit) {
    count
    items {
      id
      message
    }
  }
}

new InMemoryCache({
  typePolicies: {
    ApplicationComment: { keyFields: ["id"] },
    Query: {
      fields: {
         getApplicationComments: offsetLimitPagination(),
      },
    },
  },
})

The default offsetLimitPagination helper function only works if the field that accepts the arguments is the one that returns the array. In this case your backend schema is different than what the default offsetLimitPagination function expects, so you’ll need to write your own type policy. The code for the default offsetLimitPagination function is located here in case you want to reference it: apollo-client/pagination.ts at main · apollographql/apollo-client · GitHub