Skip to content

Commit

Permalink
with-apollo SSR example added. (#21956)
Browse files Browse the repository at this point in the history
Co-authored-by: Lee Robinson <me@leerob.io>
  • Loading branch information
smitbarmase and leerob committed Feb 9, 2021
1 parent 394bbf6 commit 74e0c6d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
3 changes: 3 additions & 0 deletions examples/with-apollo/components/Header.js
Expand Up @@ -17,6 +17,9 @@ export default function Header() {
Client-Only
</a>
</Link>
<Link href="/ssr">
<a className={pathname === '/ssr' ? 'is-active' : ''}>SSR</a>
</Link>
<style jsx>{`
header {
margin-bottom: 25px;
Expand Down
33 changes: 33 additions & 0 deletions examples/with-apollo/pages/ssr.js
@@ -0,0 +1,33 @@
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, addApolloState } from '../lib/apolloClient'

const SSRPage = () => (
<App>
<Header />
<InfoBox>ℹ️ This page shows how to use SSR with Apollo.</InfoBox>
<Submit />
<PostList />
</App>
)

export async function getServerSideProps() {
const apolloClient = initializeApollo()

await apolloClient.query({
query: ALL_POSTS_QUERY,
variables: allPostsQueryVars,
})

return addApolloState(apolloClient, {
props: {},
})
}

export default SSRPage

0 comments on commit 74e0c6d

Please sign in to comment.