DEV Community

Samuel Durante for Woovi

Posted on

6

How to use the Relay fetch policy to ensure fast rendering?

One of the main tools of Woovi is Relay. Relay is a GraphQL Client designed for high performance on any scale. When performing one of your main operations, query, we use a hook called useLazyLoadQuery, this hook has a property called fetchPolicy, which defines whether the query will be made from the local cache (we call it "store") or whether it should be made from a network request (we call it "network").

The following definitions fetchPolicy are:

store-or-network

store-or-network is the default value, if data exists in the store, and is not obsolete, it won't do a network request, otherwise, it will do a network request.

store-or-network

Example: We can use it in high-flow places to save network requests. Consequently avoiding unnecessary requests.

store-and-network

store-and-network will use the data of the store, and always do a network request without making regardless.

store-and-network

Example: We can imagine the Instagram home, we can render outdated data while fetching new data.

network-only

network-only always will search the data making a network request.

network-only

Example: We need to render the balance of the customer, we can't render a balance out of date, so always we will make a new network request without considering the store.

store-only

store-only always will search the data of the store.

store-only

Example: We use store-only when we assume that this data already exists in the store, and we will not need the refetch.

If you want to work with us, we are hiring!

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

SurveyJS custom survey software

JavaScript UI Libraries for Surveys and Forms

SurveyJS lets you build a JSON-based form management system that integrates with any backend, giving you full control over your data and no user limits. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay