# relayStylePagination doesn't check if edges were actually queried

**URL:** <https://community.apollographql.com/t/relaystylepagination-doesnt-check-if-edges-were-actually-queried/8731>\
**Category:** Client SDKs\
**Tags:** client\
**Created:** [March 19, 2025, 2:33pm UTC](https://community.apollographql.com/t/relaystylepagination-doesnt-check-if-edges-were-actually-queried/8731 "2025-03-19T14:33:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tpict](https://avatars.discourse-cdn.com/v4/letter/t/7ea924/32.png) [@tpict](https://community.apollographql.com/u/tpict)\
**Post date:** [March 19, 2025, 2:33pm UTC](https://community.apollographql.com/t/relaystylepagination-doesnt-check-if-edges-were-actually-queried/8731/1 "2025-03-19T14:33:10Z")

</div>

I’m encountering an issue where I have two documents querying the same field, which is configured to use `relayStylePagination` with the relevant key args.

One of those documents doesn’t include `edges` in its selection set:

```auto
{
  totalCount
}

```

The other one does:

```auto
{
  totalCount
  edges {
    node {
      id
    }
  }
}

```

If the former completes first, then with the default `cache-first` policy, Apollo doesn’t perform a network request for the latter. This would make sense if `edges` had been queried by the former… but they haven’t.

The `totalCount` field is a deviation of the official Connection interface I’m aware–is this just something that we should account for on our end? Or would it be reasonable to update the upstream function to check if `edges` has been populated?

---

<div class="post-metadata">

**Author:** ![lenz](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/lenz/32/4007_2.png) [@lenz](https://community.apollographql.com/u/lenz)\
**Post date:** [March 24, 2025, 5:23pm UTC](https://community.apollographql.com/t/relaystylepagination-doesnt-check-if-edges-were-actually-queried/8731/2 "2025-03-24T17:23:03Z")

</div>

That is actually a shortcoming I believe we currently have in there.

A workaround could be using a [`@connection`](https://www.apollographql.com/docs/react/data/directives#connection) directive to store these two queries in different places in the cache:

```gql
{
  parent @connection(key: "parentTotalCount") {
    totalCount
  }
}

```

That way, the `totalCount`-only query would be stored in a different place and not mix in.

Generally, though, `relayStylePagination` does need `pageInfo`, so please make sure to always query that!

---

<div class="post-metadata">

**Author:** ![tpict](https://avatars.discourse-cdn.com/v4/letter/t/7ea924/32.png) [@tpict](https://community.apollographql.com/u/tpict)\
**Post date:** [March 25, 2025, 2:58pm UTC](https://community.apollographql.com/t/relaystylepagination-doesnt-check-if-edges-were-actually-queried/8731/3 "2025-03-25T14:58:46Z")

</div>

Thanks @lenz. I’ve implemented a workaround in the field policy for now but bumped into another issue; doing e.g.

```auto
{
  edges {
    __typename
  }
}

```

will result in `edges` being written to the cache as `[]` even if there _were_ results.

I’m beginning to feel like there’s a bit of a documentation gap here. Or that perhaps there should be a “strict” option for `relayStylePagination` that throws if a query didn’t check the necessary fields.

---

<div class="post-metadata">

**Author:** ![lenz](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/lenz/32/4007_2.png) [@lenz](https://community.apollographql.com/u/lenz)\
**Post date:** [March 26, 2025, 4:13pm UTC](https://community.apollographql.com/t/relaystylepagination-doesnt-check-if-edges-were-actually-queried/8731/4 "2025-03-26T16:13:01Z")

</div>

Yeah, I fear what you are doing is just outside the assumptions that the `relayStylePagination` was written with.

I feel your pain and we might revisit that in the future, but right now we’re working hard on the Apollo Client 4.0 release, so that is just a comparatively low priority.

The best I can suggest right now is that you copy the pagination over into your codebase and adjust it to your individual needs:

> <https://github.com/apollographql/apollo-client/blob/11b03e1673e3d0f6e040ce21fcec181303200f42/src/utilities/policies/pagination.ts#L95-L271>
