Skip to content

cache issues when using @defer directive and @urql/exchange-graphcache  #3161

@beerose

Description

@beerose

Describe the bug

I’ve run into a pretty weird issue while using urql and I could really use some help.

The main problem is that when my app sends a query with defer or when it receives chunked data, it seems to be the last request that’s ever fired.

For example, when I open my app and navigate through random pages, everything works just fine. But when I go to a page that uses defer and then move to another random page, I get a bunch of runtime errors due to missing data. It looks like the query was resolved (cache hit), but an API request was never fired. When I refresh the page, everything works again.

After some debugging, I narrowed it down to have something to do with @urql/exchange-graphcache (if I remove the exchange it works fine). Based on the logs and urql devtools, there’s a cache hit for those queries when I there shouldn’t be. Also, when I remove defer usage, logs from the same flow show cache misses.

Do you have any suggestions what could be causing this?

Urql dev tools:

  • There's no API call for the last four queries
  • The fifth one (from the bottom) is the one with defer directive

CleanShot 2023-04-18 at 17 01 19@2x

CleanShot 2023-04-18 at 17 02 33@2x

Here's a PR to GraphQL Hive with adding defer to one of the queries (and necessary setup): graphql-hive/console#1964

Reproduction

graphql-hive/console#1964

Urql version

@urql/core: 4.0.4

@urql/exchange-graphcache: 6.0.1

Validations

  • I can confirm that this is a bug report, and not a feature request, RFC, question, or discussion, for which GitHub Discussions should be used
  • Read the docs.
  • Follow our Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🐛Oh no! A bug or unintented behaviour.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions