Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add persistor options in ApolloOfflineClient constructor #281

Closed
JaEdmuva opened this issue Dec 4, 2019 · 5 comments
Closed

Add persistor options in ApolloOfflineClient constructor #281

JaEdmuva opened this issue Dec 4, 2019 · 5 comments
Assignees
Milestone

Comments

@JaEdmuva
Copy link

@JaEdmuva JaEdmuva commented Dec 4, 2019

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
Copy link
Member

@wtrocki wtrocki commented Dec 4, 2019

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: #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)

@wtrocki wtrocki added this to the offix.next milestone Dec 4, 2019
@JaEdmuva
Copy link
Author

@JaEdmuva JaEdmuva commented Dec 4, 2019

@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
Copy link
Contributor

@darahayes darahayes commented Dec 5, 2019

@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 darahayes self-assigned this Dec 12, 2019
@darahayes darahayes mentioned this issue Dec 16, 2019
4 tasks
@darahayes
Copy link
Contributor

@darahayes darahayes commented Jan 14, 2020

@JaEdmuva we recently merged and released #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
Copy link
Contributor

@darahayes darahayes commented Jan 14, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants