# Apollo Client ignoring cached items

**URL:** <https://community.apollographql.com/t/apollo-client-ignoring-cached-items/6424>\
**Category:** Client SDKs\
**Tags:** client, web\
**Created:** [June 29, 2023, 1:26pm UTC](https://community.apollographql.com/t/apollo-client-ignoring-cached-items/6424 "2023-06-29T13:26:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Raymond\_Caddick](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/raymond_caddick/32/4399_2.png) [@Raymond\_Caddick](https://community.apollographql.com/u/Raymond_Caddick)\
**Post date:** [June 29, 2023, 1:26pm UTC](https://community.apollographql.com/t/apollo-client-ignoring-cached-items/6424/1 "2023-06-29T13:26:32Z")

</div>

Asked on stackoverlfow as well here:

[Stackoverflow](https://stackoverflow.com/questions/76580365/apollo-client-cache-read-policy)

I have two queries like so:

```auto
const GET_GROUP_DATA = gql`
  query GetGroups {
    groups {
      id
      name
      type
      ...etc
    }
  }
`;

const GET_FORM_DATA = gql`
  query GetFormData {
    contactTypes {
      type
    }
    groups {
      id
      name
    }
  }
`;

```

Both are retrieving data for groups.

If I run GET\_GROUP\_DATA first, all the data for groups saved in my cache, however when running GET\_FORM\_DATA that requests contactTypes and groups, Apollo ignores the groups already in the cache and re fetches the groups along with contactTypes.

All the required fields (id and name) are present in the cache so shouldn’t Apollo only send the request to fetch contactTypes?

I am assuming that I need a read policy to instruct Apollo to look in the cache first, however I have only managed to get this working with single entities like so:

```auto
readGroup: {
  read(_, { args: { groupId }, toReference }) {
    return toReference({
      __typename: "Group",
      id: groupId,
    });
  },
},

```

How can I set this up so that GET\_FORM\_DATA can make use of the cached values for group if they are available.

Not sure if its because I am requesting two different types in a single query maybe?

---

<div class="post-metadata">

**Author:** ![jerelmiller](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/jerelmiller/32/3314_2.png) [@jerelmiller](https://community.apollographql.com/u/jerelmiller)\
**Post date:** [June 29, 2023, 3:33pm UTC](https://community.apollographql.com/t/apollo-client-ignoring-cached-items/6424/2 "2023-06-29T15:33:37Z")

</div>

Hey @Raymond_Caddick 👋

When Apollo determines whether to return results from the cache or fetch, it checks to see if it can fulfill the _entire_ query. Assuming you don’t have `contactTypes` in your cache for your second query, the client determines that it can’t fulfill that query from the cache, so it executes a network request. At this time, the client doesn’t do any intelligent stripping of fields that are already cached, so the entire query is sent to the network.

I’m curious how you’re executing this query? Are you using `client.query(...)` directly? Or something like `useQuery` with React to fetch this data? I may have a suggestion for you depending on how you’re executing this query.

---

<div class="post-metadata">

**Author:** ![Raymond\_Caddick](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/raymond_caddick/32/4399_2.png) [@Raymond\_Caddick](https://community.apollographql.com/u/Raymond_Caddick)\
**Post date:** [June 29, 2023, 3:44pm UTC](https://community.apollographql.com/t/apollo-client-ignoring-cached-items/6424/3 "2023-06-29T15:44:41Z")

</div>

Thanks for getting back to me @jerelmiller !

That make a lot of sense that its looking at the entire query over just individual types within the query.

At the moment I’m using useQuery with React because it exposes loading and refetch, but could also create a custom hook using client.query if it will help?

Would love to to hear any suggestion you have, because it does seem like a waste to ignore data I already have, and I would rather not split this into two separate queries if I don’t have to.

---

<div class="post-metadata">

**Author:** ![jerelmiller](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/jerelmiller/32/3314_2.png) [@jerelmiller](https://community.apollographql.com/u/jerelmiller)\
**Post date:** [June 29, 2023, 3:48pm UTC](https://community.apollographql.com/t/apollo-client-ignoring-cached-items/6424/4 "2023-06-29T15:48:44Z")

</div>

I was hoping you were using `useQuery` 😆! If you want to get access to those cached `groups` before the network request is finished, set the [`returnPartialData`](https://www.apollographql.com/docs/react/api/react/hooks#returnpartialdata) option to `true`. This won’t prevent the `groups` from being requested in the query, but it will allow you to use that cached data before the network request is finished.

```auto
const { data } = useQuery(GET_FORM_DATA, { returnPartialData: true });

```

Give this a go and see if this gives helps!

---

<div class="post-metadata">

**Author:** ![Justin\_Gonzalez](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/justin_gonzalez/32/5359_2.png) [@Justin\_Gonzalez](https://community.apollographql.com/u/Justin_Gonzalez)\
**Post date:** [February 6, 2025, 8:48pm UTC](https://community.apollographql.com/t/apollo-client-ignoring-cached-items/6424/5 "2025-02-06T20:48:40Z")

</div>


