-
Notifications
You must be signed in to change notification settings - Fork 26k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
with-apollo SSR example added. (#21956)
Co-authored-by: Lee Robinson <me@leerob.io>
- Loading branch information
1 parent
394bbf6
commit 74e0c6d
Showing
2 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |