This is how I'm trying to implement apollo graphQL in my react native application.
But with that I do get the error
Could not find "client" in the context of Query or as passed props. Wrap the root component in an <ApolloProvider>
So I thought I have done exactly this, but obviously I'm missunderstanding something.
import React, { Component } from 'react'
import { ApolloProvider, graphql } from 'react-apollo'
import { ApolloClient } from 'apollo-client'
import { createHttpLink } from 'apollo-link-http'
import { InMemoryCache } from 'apollo-cache-inmemory'
import gql from 'graphql-tag'
import Routes from './config/routes'
// Initialize the Apollo Client
const client = new ApolloClient({
link: createHttpLink({ uri: 'http://localhost:3000' }),
cache: new InMemoryCache()
})
// Define query types
const DATA_QUERY = gql`
query {
getVersion {
version
}
}
`
export class App extends Component {
render () {
console.log(this.props)
// ApolloProvider lets us use Apollo Client in descendant components
return (
<ApolloProvider client={client}>
<Routes />
</ApolloProvider>
)
}
}
// Inject query response as `this.props.data`
export default graphql(DATA_QUERY)(App)