Next.js example with graphql-react
graphql-react
is a lightweight but powerful GraphQL client for React; the first Relay and Apollo alternative with server side rendering.
See how it can be used in a Next.js app for GraphQL queries with server side rendering and client side data hydration:
- In
pages/_app.js
a customApp
component is decorated with thewithGraphQL
higher-order component fromnext-graphql-react
, generating agraphql
prop that populates theProvider
component fromgraphql-react
. - In
pages/index.js
theQuery
component fromgraphql-react
is used to query the GraphQL Pokémon API and show a picture of Pikachu.
-
Download the example:
curl https://codeload.github.com/zeit/next.js/tar.gz/canary | tar -xz --strip=2 next.js-canary/examples/with-graphql-react
-
Change directory to it:
cd with-graphql-react
-
Install it:
npm install
-
Run it:
npm run dev