rsnext/examples/with-apollo/pages/index.js
Luis Alvarez D 2d2c7626e3
[Examples] Move with-apollo to SSG (#13742)
Based on https://github.com/vercel/next.js/pull/13607 - I created a new PR as I can't push changes to the initial PR.

Migrated the Apollo client to use SSG, also removed the link to the live demo because I don't know who the owner is or how to update the deployment.

The implementation is pretty simple and will be added to all the other Apollo examples
2020-06-05 15:41:42 +00:00

36 lines
806 B
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import App from '../components/App'
import InfoBox from '../components/InfoBox'
import Header from '../components/Header'
import Submit from '../components/Submit'
import PostList, {
ALL_POSTS_QUERY,
allPostsQueryVars,
} from '../components/PostList'
import { initializeApollo } from '../lib/apolloClient'
const IndexPage = () => (
<App>
<Header />
<InfoBox> This page shows how to use SSG with Apollo.</InfoBox>
<Submit />
<PostList />
</App>
)
export async function getStaticProps() {
const apolloClient = initializeApollo()
await apolloClient.query({
query: ALL_POSTS_QUERY,
variables: allPostsQueryVars,
})
return {
props: {
initialApolloState: apolloClient.cache.extract(),
},
unstable_revalidate: 1,
}
}
export default IndexPage