aerogear / offix

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

Cache redirects are not exposed to clients #69

Closed Hasan-git closed 4 years ago

Hasan-git commented 5 years ago

Documentation it's a little bit confusing, can you provide us with samples ?


EDITED BY @wtrocki

Target of this issue is to document way developers can specify Apollo Cache Redirects. Those redirects needs to be specified when creating InMemoryCache https://github.com/aerogear/offix/blob/master/packages/offix-client/src/OfflineClient.ts#L102

Currently there is no way to do so

wtrocki commented 5 years ago

What particular parts of the documentation are problematic? We are actually working on improving documentation and sample app so any feedback is more than welcomed. Offix is used in https://github.com/aerogear/ionic-showcase.

Demo video: https://www.youtube.com/embed/CrYinCtTHds

Hasan-git commented 5 years ago

All human beings will be thankful for your efforts Ionic showcase is a very good as startup.

What particular parts of the documentation are problematic? We are actually working on improving documentation and sample app so any feedback is more than welcomed. Offix is used in https://github.com/aerogear/ionic-showcase.

Demo video: https://www.youtube.com/embed/CrYinCtTHds

Hasan-git commented 5 years ago

how to add links and configure inMemoryCache ( cacheRedirects and dataIdFromObject ).

image

wtrocki commented 5 years ago

So currently we creating a client for developers. Adding links is possible only by overriding the init method of the ApolloClient. However, we are hoping to extract links in the coming week so it will be available to be used with existing clients.

Hasan-git commented 5 years ago

image

the Query "allTasks" accepts argument ( first : Int ) imagine we are providing this query with arg value.

@ ROOT_QUERY

how could updateQuery handle this situation.

In my case I am using pagination with arguments (filter, limit, page, sortBy, direction) then the queries should be invalid and out of date. But, in case the application is offline it should be able to resolve the query from store !?

I was thinking about invalidating the related queries, then any new request will pass through InMemoryCache "cacheRedirects" where I can get all items from store, the issue that I should loop over the whole cache to get the stored items by typename and then be able to resolve the data and build the query according to query arguments. but looping over the whole cache is not ideal and will cause performance drawbacks when the cache is growing and getting larger and larger.

wtrocki commented 5 years ago

In my case I am using pagination with arguments (filter, limit, page, sortBy, direction) then the queries should be invalid and out of date. But, in case the application is offline it should be able to resolve the query from the store !?

I think we need to have another issue (this one is about documentation) where we will ask for the team to provide support for pagination which is actually really tricky to get now and it will require some heavy lifting on the developer side. We had some use cases for Pagination but they were always business case specific, which is really tricky to get right.

I think we can threat paginated results separately (by not caching them as other things by variables but only by globals. Then this means that we will be able to do client-side pagination on top of the data

I think for we also need to have a separate cache update helper for pagination and document pagination case separately. This is something that definitely is in our roadmap.

Do you mind creating a separate issue for that so we can address those issues faster?

We hit so many issues with InMemoryCache so I think from now on we probably going to fork it to this repository and address the issues.

ping @StephenCoady @darahayes

wtrocki commented 5 years ago

To implement that: I will use cacheRedirects: Operate on the root object and ignoring the pages. Have some simplified equivalent of the pagination.

This will also require us to always cache the data on a query without any arguments which is not supported now by our out of the box cache helpers. We can wait until our team will figure that out or you can try to hack something that will satisfy your needs.

Pagination is tricky and since there could be many business requirements to do it. It is hard to do it on a generic level. However, we can try to provide some helpers that will assume some format of pagination that should work for the cases where users can adjust their API to accept it.

darahayes commented 4 years ago

@Hasan-git since the 0.9.0 release it's now possible to directly pass in your own InMemoryCache instance into OfflineClient.

const cache = new InMemoryCache();

const offlineClient = new OfflineClient({
  httpUrl: https://example.com/grapqhl,
  cache
});

We haven't got many test cases around how OfflineClient will behave using different cache instances with custom configs. If you could try that out and let us know how it works for you that would be great. If you have specific use cases and configurations in mind we could work to get some tests covering those.

wtrocki commented 4 years ago

Also worth note that we going to integrate with the Apollo 3.0 in upcoming releases that address pagination issues.

darahayes commented 4 years ago

Closing this for now as it's possible to create and configure your own cache instance. Feel free to reopen if needed.