Feature Request
Related discussion here: darahayes/offix-example-react#1
Is your feature request related to a problem? Please describe.
The main problem right now is that the flow to create a client looks something like this.
let client = new OfflineClient(config);
await client.init();
let apolloClient = client.apolloClient
The apolloClient is really what we're looking for but it doesn't become available to us until after we await client.init()
. I noticed while trying to build a react application that the main way to pass an ApolloClient around a React application is to use an ApolloProvider
either from react-apollo-hooks
or react-apollo
.
Example:
import React from 'react';
import { render } from 'react-dom';
import { ApolloProvider } from 'react-apollo-hooks';
const client = ... // create Apollo client
const App = () => (
<ApolloProvider client={client}>
<MyRootComponent />
</ApolloProvider>
);
render(<App />, document.getElementById('root'))
Now useApolloClient
can be used within components.
The problem is that ApolloProvider
must be passed a client and you can't really await
for things during a component render.
The hacky solution I found so far was to create a regular apollo client, inject that into my application, and use a hook to swap out the regular client with the one coming from Offix after the init
has completed.
Describe the solution you'd like
Ideally we would have one of two fixes:
OfflineClient.init()
synchronously returns the ApolloClient.
OfflineClient
extends ApolloClient
and somehow everything can be synchronously set up in the constructor.
I think I would actually prefer the first option for now because it's less of a drastic change.