Git Product home page Git Product logo

apollo-client-cache-rehydration-in-next-js's Introduction

Apollo Client Cache Rehydration in Next.js

Next.js app code for this blog post: https://developers.wpengine.com/blog/apollo-client-cache-rehydration-in-next-js/

This repo demonstrates how to:

  1. Fetch data on the server using server-side rendering (SSR), static site generation (SSG) or incremental static regeneration (ISR) and populate Apollo Client's cache
  2. Send that cache data to the client
  3. Use it to "rehydrate", or initialize, Apollo Client's cache in the browser

This way, you get the benefits of SSR/SSG/ISR (a fully rendered HTML document on the initial page load, great SEO, etc.), and still have the data in Apollo Client's cache. This prevents your app from making unnecessary client-side network requests for data you already have.

apollo-client-cache-rehydration-in-next-js's People

Contributors

kellenmace avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

apollo-client-cache-rehydration-in-next-js's Issues

getStaticPaths Implementation on Dynamic Paths ?

Hello @kellenmace this repository is very helpful, I have successfully implemented Apollo cache on my getStaticProps, but in some Dynamic pages (e.g. [slug].tsx, [...slugs].tsx) where in addition to getStaticProps we need to implement getStaticPaths as well. So the question is how to implement getStaticPaths using this Apollo lib. Here is my current getStaticPaths:

export const getStaticPaths: GetStaticPaths = async ( _ ) => {

  const apolloClient = new ApolloClient({
     uri: process.env.GQL_ENDPOINT,
     cache: new InMemoryCache()
   })

  const {  data: { categories }  } = await apolloClient.query({
    query: GET_CATEGORY_PATHS
  })

  const paths = categories.map( (category: TCategory) => ({
    params: {
      categorySlug: category.slug
    }
  }))

  return {
    paths,
    fallback: true
  }
}

Thx. ๐Ÿ‘

--
Best regards
Valdenio Marinho

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.