/plushcap/analysis/hasura/graphql-data-fetching-swr-react-hooks-hasura

GraphQL Data Fetching with SWR React Hooks and Hasura

What's this blog post about?

This text discusses how to use SWR React Hooks with Hasura Cloud, a GraphQL API, for efficient data fetching. The name "SWR" stands for stale-while-revalidate, a cache invalidation strategy that first returns cached data and then updates it with the latest information. In this context, SWR is used to manage HTTP POST requests and native websocket connections in combination with GraphQL. The text provides an example of how to use the `useSWR` hook with a GraphQL query and a fetcher function. It also demonstrates how to handle errors and loading states. Additionally, it explains how to update existing state using the `mutate` method after performing a mutation. Finally, the text briefly touches upon handling real-time data subscriptions with WebSocket connections and pre-rendering for SEO/Caching benefits by passing initial data to the `initialData` option in combination with `getStaticProps`. The source code is available on GitHub at https://github.com/praveenweb/swr-graphql.

Company
Hasura

Date published
Dec. 14, 2020

Author(s)
Praveen Durairaju

Word count
868

Hacker News points
None found.

Language
English


By Matt Makai. 2021-2024.