Extracting data into specific cache slot from a query

query ShopReviews($shopId: Int!, $limit: Int!, $offset: Int!) {
  shopReviews(shopId: $shopId, limit: $limit, offset: $offset) @connection(key: "shopReviews") {
    success
    reviews {
      id
      __typename
      shopId
      body
      rating
      user {
        id
        __typename
        name
        avatar
      }
      created
      formattedData @client
      formattedBody @client
    }
    error {
      message
    }
  }
}

Here is my Mutation. I would like to put only the reviews part in a separate cache slot. without success and error. The goal is when I do the mutation. I can append the newly created review into the reviews slot.

Hi :wave:,

By definition, the reviews are stored as separate records. Because your reviews have an id field, you can use that to uniquely identify them. See this blog post for more information about normalization.

Looks like what you’re looking for is pagination helpers for your normalized cache? Different client have different level of support for that. What is the client you are using (web, ios, android)?

react-native. and ac-3. I’m having trouble with pagination.

Gotcha! I’m not super familiar with ac-3 (I do native Android mainly) but maybe someone else from the community can chip in. Or you can take a look at the docs. It contains a section offset-based pagination.

1 Like
{
  'review:1': {
    __typename: 'Review',
    id: 1,
    shopId: 1,
    body: 'good shop',
    ...
  },
  ...
  ROOT_QUERY: {
    reviews: {
      __typename: 'ReviewResponse',
      data: [
        { __ref: 'review:1' },
        ...,
      ]
    }
  }
}

I’m trying to visualize how this would look like in the cache