提交 fdb10d4f 编写于 作者: L laiso 提交者: Tim Neutkens

Update to Next v8.0 example on with-graphql-react (#6454)

I'm working on examples/with-graphql-react changes to:
- Next v7 to v8.0 and update dependencies
- fix some errors for the change of graphql-react API
上级 b8d3b7e6
...@@ -3,12 +3,12 @@ ...@@ -3,12 +3,12 @@
"private": true, "private": true,
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"cross-fetch": "^3.0.0", "cross-fetch": "^3.0.1",
"graphql-react": "^6.0.0", "graphql-react": "^8.0.2",
"next": "^7.0.0", "next": "^8.0.3",
"next-graphql-react": "^1.0.1", "next-graphql-react": "^3.0.0",
"react": "^16.6.0", "react": "^16.8.3",
"react-dom": "^16.6.0" "react-dom": "^16.8.3"
}, },
"scripts": { "scripts": {
"dev": "next", "dev": "next",
......
import 'cross-fetch/polyfill' import 'cross-fetch/polyfill'
import { Provider } from 'graphql-react' import { GraphQLContext } from 'graphql-react'
import { withGraphQL } from 'next-graphql-react' import { withGraphQLApp } from 'next-graphql-react'
import App, { Container } from 'next/app' import App, { Container } from 'next/app'
class CustomApp extends App { class CustomApp extends App {
...@@ -8,12 +8,12 @@ class CustomApp extends App { ...@@ -8,12 +8,12 @@ class CustomApp extends App {
const { Component, pageProps, graphql } = this.props const { Component, pageProps, graphql } = this.props
return ( return (
<Container> <Container>
<Provider value={graphql}> <GraphQLContext.Provider value={graphql}>
<Component {...pageProps} /> <Component {...pageProps} />
</Provider> </GraphQLContext.Provider>
</Container> </Container>
) )
} }
} }
export default withGraphQL(CustomApp) export default withGraphQLApp(CustomApp)
import { Query } from 'graphql-react' import { useGraphQL } from 'graphql-react'
export default () => ( export default () => {
<Query const { loading, cacheValue = {} } = useGraphQL({
loadOnMount fetchOptionsOverride (options) {
loadOnReset
fetchOptionsOverride={options => {
options.url = 'https://graphql-pokemon.now.sh' options.url = 'https://graphql-pokemon.now.sh'
}} },
operation={{ operation: { query: `
query: /* GraphQL */ `
{ {
pokemon(name: "Pikachu") { pokemon(name: "Pikachu") {
name name
image image
} }
} }
` ` }
}} })
>
{({ data, loading }) => const { data } = cacheValue
data ? ( return data ? (
<img src={data.pokemon.image} alt={data.pokemon.name} /> <img src={data.pokemon.image} alt={data.pokemon.name} />
) : loading ? ( ) : loading ? (
<p>Loading</p> <p>Loading</p>
) : ( ) : (
<p>Error!</p> <p>Error!</p>
) )
} }
</Query>
)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册