71d899f128
* Install UrQL dependencies - Created the examples folder `with-urql` - Installed the dependencies - Got a simple index.js page setup * Basic UrQL example - Connects to Pokemon GraphQL API * Loading Pokemon list + Pokemon page - Using `isomorphic-unfetch` because `urql` uses `window.fetch` to get data because we need to query the GraphQL API using Node (in `getStaticProps`) - Deleted `_app.js` since we're not using UrQL to query data on the clientside - Put all GraphQL related code in `/graphql` * Update README for UrQL example * Update urql casing * Update examples/with-urql/graphql/client.js Co-authored-by: Joe Haddad <timer150@gmail.com> * Update examples/with-urql/pages/index.js Co-authored-by: Joe Haddad <timer150@gmail.com> * Update examples/with-urql/pages/pokemon/[name].js Co-authored-by: Joe Haddad <timer150@gmail.com> * Fix linting Co-authored-by: Tim Neutkens <tim@timneutkens.nl> Co-authored-by: Joe Haddad <timer150@gmail.com> Co-authored-by: Joe Haddad <joe.haddad@zeit.co>
33 lines
636 B
JavaScript
33 lines
636 B
JavaScript
import { getPokemon } from '../../graphql/getPokemon'
|
|
import { getPokemons } from '../../graphql/getPokemons'
|
|
|
|
export default function Pokemon({ pokemon }) {
|
|
return (
|
|
<div>
|
|
<h1>{pokemon.name}</h1>
|
|
<img src={pokemon.image} />
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export const getStaticPaths = async () => {
|
|
const pokemons = await getPokemons()
|
|
|
|
return {
|
|
paths: pokemons.map(({ name }) => ({
|
|
params: { name },
|
|
})),
|
|
fallback: true,
|
|
}
|
|
}
|
|
|
|
export const getStaticProps = async (context) => {
|
|
const { name } = context.params
|
|
const pokemon = await getPokemon(name)
|
|
|
|
return {
|
|
props: {
|
|
pokemon,
|
|
},
|
|
}
|
|
}
|