Skip to content

Change default fetchPolicy to "cache-and-network" #2061

@pcorey

Description

@pcorey

Hello,

I thought I'd open up this issue for discussion. The current fetchPolicy on GraphQL queries is "cache-first". This default assumes that all mutations are either made by, or can be predicted by the client. I would argue that this isn't true for most web applications.

Defaulting fetchPolicy to "cache-first" opens up the possibility of stale cache reads throughout an app if any queried data has been updated on the server (or by another client) without the client's knowledge. The only way to fix this is to go though your app and mark every query with a more appropriate fetchPolicy (like "cache-and-network").

I think a more sane default for fetchPolicy would be "cache-and-network". In my mind, this gives developers a more predictable experience. If a query result lives in cache, it will be returned while a network round trip takes place. If a developer knows that a query can only be affected by client-initiated changes (which I believe is a more rare use case), they can change their fetchPolicy to "cache-first" for performance gains.

Short of changing the fetchPolicy default value from "cache-first" to "cache-and-network", it might be worth considering making this default value configurable when initializing the Apollo client instance.

Any thoughts? Thanks!

  • apollo-client@1.9.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions