aerogear / offix

GraphQL Offline Client and Server
https://offix.dev
Apache License 2.0
758 stars 45 forks source link

React-apollo 2.5.5 doesn't add client to context #29

Closed evelant closed 5 years ago

evelant commented 5 years ago

Using offix 0.5.0. This is a basic react-native expo project as discussed in #23. With react-apollo 2.5.5 <ApolloConsumer> fails to find the client on the context. Pinning react-apollo to 2.5.2 works. I'm not sure if this is caused by a react-apollo bug or by offix. https://github.com/apollographql/react-apollo/issues/2900 discusses the issue but only when using MockedProvider and it appears a fix was put in for that.

wtrocki commented 5 years ago

@AndrewMorsillo I think we are missing documentation how to get thins running in react (and react native). Apollo Provider will have client propperty where we should provide client as follows:

  async componentDidMount() {
    const offlineClient = await createClient(...)
    this.setState({offlineClient})
  }

  render() {
    const {offlineClient} = this.state
    if (!apolloClient) return 'Loading the app'

    return (
      <ApolloProvider client={offlineClient}>
        ...
      </ApolloProvider>
    )
  }

Going to add this to documentation.

evelant commented 5 years ago

Sorry I didn't provide a snippet, I am providing the client to as you illustrated. That fails on react-apollo 2.5.5 but works on 2.5.2. I haven't had the opportunity to dig further into the issue yet but I'll update here if I find up with something. I'm more focused on getting a complete working example set up before investigating this since it has an easy workaround for now.

wtrocki commented 5 years ago

@AndrewMorsillo Maybe this is related to the problem in breaking API upstream. I will update the package and check what was changed here and resolve the issue.

Let me check that carefully and I will provide update here and release new fix.

wtrocki commented 5 years ago

Simply updating dependencies to Apollo here should work fine. We are working now on React sample app with Ionic where we going to try out these cases and improve things.

wtrocki commented 5 years ago

Tried that now with Apollo 2.6 and it felt that this was bug on their side.