TallerWebSolutions / apollo-cache-instorage

Apollo Cache implementation that facilitates locally storing resources
MIT License
96 stars 11 forks source link

Empty responses for any query #6

Closed yantakus closed 5 years ago

yantakus commented 5 years ago

I'm trying to use this package as a drop in replacement for apollo-cache-inmemory. But in this case I get empty object for data in response for any query. Data gets from the server and is persisted (I see items in localStorage), but nothing comes from the queries. Any ides? How do I debug this at all?

lucasconstantino commented 5 years ago

Sorry dude, I'm short on time for debugging right now. Do you mind to setup a reproduction case? It can be on CodeSandbox, for instance.

adrian1388 commented 5 years ago

Hello @lucasconstantino. I see this project very valuable for my purposes and I have played with it a lil' but I have found this issue and I am blocked here right now.

I have made a test project for you to clone, install and link it react-native link (I could not get it working on Sandbox), then I am sure you can help us.

It is a simple use of the Query component where data comes as an empty object.

Also, I had to do two changes to your code to get the project working, please read the README file first.

https://github.com/adrian1388/ReactNativeInstorageTest

I am going to be waiting for your answer.

adrian1388 commented 5 years ago

@lucasconstantino Running your test file named 'inStorageCache.test.js' and adding a debug on objectStorageCache.js#get(), like this:


  get (dataId) {
    if (!this.data[dataId] && this.persistence.shouldPersist('get', dataId)) {
      console.info(this.persistence.storage)
      this.data[dataId] = this.persistence.denormalize(
        this.persistence.storage.getItem(`${this.persistence.prefix}${dataId}`)
      )
    }
    return this.data[dataId]
  }

I can see the next output:

for some cases:

  console.info src/objectStorageCache.js:57
    LocalStorage {}

and in other cases LocalStorage contains a Query result:

  console.info src/objectStorageCache.js:57
    LocalStorage {
      '$ROOT_QUERY.typeField': '{"field":"value","__typename":"TypeName"}' }

Is not it supposed that brings an output like this: ...?

{setItem: ƒ, getItem: ƒ, removeItem: ƒ, getAllKeys: ƒ}
adrian1388 commented 5 years ago

FYI:

lukadriel7 commented 5 years ago

Hello, any news concerning this issue ?

lucasconstantino commented 5 years ago

@yantakus @adrian1388 @lukadriel7 can any of you have a look at #7 if it fixes your issue?

lukadriel7 commented 5 years ago

@lucasconstantino it solves the problem thank you . I cloned the package and built it with the changes. it works. That being said, are you planning on keeping on maintaining this package ? You seem really busy

lucasconstantino commented 5 years ago

Hey, @lukadriel7. Thanks for validating the solution. I've already closed the PR and pushed a new version on NPM.

I usually only keep maintenance on projects I'm currently using, and if I face issues. Definitely, due to scarce time. I'm always looking forward to receive support on the projects, though, and quite often I simply give ownership to someone more currently involved on it.