Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
docs: document support for paginated cache updates
Browse files Browse the repository at this point in the history
  • Loading branch information
kingsleyzissou committed Jun 23, 2020
1 parent 46490d9 commit 8a8fe80
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions docs/ref-cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,28 @@ const options = createMutationOptions(mutationOptions);
apolloClient.mutate(options);
```

> NOTE: Cache helpers currently support only GraphQL Queries that return arrays.
> For example `getUsers():[User]`.
> When working with single objects returned by Queries we usually do not need use any helper as Query will be updated automatically on every update
### Pagination and relationships

It may be necessary to update a field within the query and not the entire query, for example with relationships. In order to do this, it is necessary to provide the name of the field being updated with the `returnField` parameter.

```javascript
const mutationOptions = {
mutation: ADD_COMMENT,
variables: {
title: 'comment title'
},
updateQuery: {
query: GET_TASK,
variables: {
filterBy: 'some filter'
}
},
returnType: 'Comment',
operationType: CacheOperation.ADD,
idField: 'id',
returnField: 'comments
};
```
## Subscription Helpers
Expand Down Expand Up @@ -121,6 +140,20 @@ query.subscribeToMore(subscriptionOptions);
The cache will now be kept up to date with automatic data deduplication being performed.
### Pagination and relationships
Similarly to the mutation cache update helpers, it is necessary to provide the `returnField` parameter to specify the name of the field to update within the query.
```javascript
export const editSubscriptionOptions = createSubscriptionOptions({
subscriptionQuery: NEW_COMMENT,
cacheUpdateQuery: GET_TASK,
operationType: CacheOperation.ADD,
idField: 'id',
returnField: 'comments'
});
```
### Multiple Subscriptions
`offix-cache` also provides the ability to automatically call `subscribeToMore` on your `ObservableQuery`. This can be useful in a situation where you may have multiple subscriptions which can affect one single query. For example, if you have a `TaskAdded`, `TaskDeleted` and a `TaskUpdated` subscription you would need three separate `subscribeToMore` function calls. This can become tedious as your number of subscriptions grow. To combat this, we can use the `subscribeToMoreHelper` function from offix-cache to automatically handle this for us by passing it an array of subscriptions and their corresponding queries which need to be updated.
Expand Down

0 comments on commit 8a8fe80

Please sign in to comment.