aerogear / offix

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

Add persistor options in ApolloOfflineClient constructor #281

Closed JaEdmuva closed 4 years ago

JaEdmuva commented 4 years ago

Feature Request

Is your feature request related to a problem? Please describe. I'm using v0.11.0. It is not possible to specify persistor options in the ApolloOfflineClient constructor. When using with react native, it is necessary to use a 'wrapper' to force serialization of data saved in AsyncStorage since the default options passed to the persistor has the serialize option value as false which causes a problem when persisting the cache data.

Describe the solution you'd like Instead of having to define a 'wrapper' which is just a workaround, not a solution. Allow to define optional persistor options through the ApolloOfflineClient constructor. This will even solve #273

Describe alternatives you've considered None.

wtrocki commented 4 years ago

Ah.. right. We kinda provided a workaround for that. Please see official docs: https://offix.dev/docs/react-native

We detect if an object is a string or object, but that will be a much better approach. As for the persistor itself: It is possible to provide persistor (using undocumented API). See here: https://github.com/aerogear/offix/issues/273

So TL;DR

  1. We going to fix it!
  2. It is possible to make it work anyway by following the docs example
  3. You can also provide your own persistor (documented in the issue above)
JaEdmuva commented 4 years ago

@wtrocki about item 3. Yes, I can provide my own persistor, in fact I do. But there is an issue with that, which I do not fully understand yet. The thing is that when you first create the ApolloOfflineClient, you create a persistor with serialize: false and It doesn't matter if I later define my own, it is already created. Then (and it's my guess) the time comes when the first persistor still tries to read/write the cache to AsyncStorage and the exception comes, since it's trying to write an object (array) to the store but it only supports Strings. That'll be the main issue with RN I think.

darahayes commented 4 years ago

@JaEdmuva we'll definitely work on allowing you to pass down the persistor options through the constructor. In the meantime did you try following the steps for passing in a custom storage mechanism in our react native document? This storage mechanism might help you get past the error you are seeing. See https://offix.dev/docs/react-native#integration

darahayes commented 4 years ago

@JaEdmuva we recently merged and released https://github.com/aerogear/offix/pull/306 which allows you to create your own CachePersistor object and pass it into the OfflineClient constructor. You can check the PR description or the client configuration docs to learn how to do it. It can be used with version 0.13.1

darahayes commented 4 years ago

I'm going to close this issue now, but please do not hesitate to reach out again with any more questions or feedback.