Skip to content

Commit

Permalink
Merge pull request #3773 from apollographql/hwillson/issue-3709
Browse files Browse the repository at this point in the history
Adjust `subscribe` to recognize the `no-cache` fetch policy
  • Loading branch information
hwillson authored Aug 2, 2018
2 parents 76a24e6 + bf6c610 commit 24d188e
Show file tree
Hide file tree
Showing 12 changed files with 294 additions and 245 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
[@PowerKiKi](https://github.com/PowerKiKi) in [#3692](https://github.com/apollographql/apollo-client/pull/3692)
- Corrected `ApolloClient.queryManager` typing as it may be `undefined`. <br/>
[@danilobuerger](https://github.com/danilobuerger) in [#3661](https://github.com/apollographql/apollo-client/pull/3661)
- Make sure using a `no-cache` fetch policy with subscriptions prevents data
from being cached. <br/>
[@hwillson](https://github.com/hwillson) in [#3773](https://github.com/apollographql/apollo-client/pull/3773)
- Documentation updates. <br/>
[@hwillson](https://github.com/hwillson) in [#3750](https://github.com/apollographql/apollo-client/pull/3750) <br/>
[@hwillson](https://github.com/hwillson) in [#3754](https://github.com/apollographql/apollo-client/pull/3754) <br/>
Expand Down
17 changes: 12 additions & 5 deletions packages/apollo-cache-inmemory/src/mapCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,36 @@ import { NormalizedCache, NormalizedCacheObject, StoreObject } from './types';
* Note that you need a polyfill for Object.entries for this to work.
*/
export class MapCache implements NormalizedCache {
cache: Map<string, StoreObject>;
private cache: Map<string, StoreObject>;

constructor(data: NormalizedCacheObject = {}) {
this.cache = new Map(Object.entries(data));
}
get(dataId: string): StoreObject {

public get(dataId: string): StoreObject {
return this.cache.get(`${dataId}`);
}
set(dataId: string, value: StoreObject): void {

public set(dataId: string, value: StoreObject): void {
this.cache.set(`${dataId}`, value);
}
delete(dataId: string): void {

public delete(dataId: string): void {
this.cache.delete(`${dataId}`);
}
clear(): void {

public clear(): void {
return this.cache.clear();
}

public toObject(): NormalizedCacheObject {
const obj: NormalizedCacheObject = {};
this.cache.forEach((dataId, key) => {
obj[key] = dataId;
});
return obj;
}

public replace(newData: NormalizedCacheObject): void {
this.cache.clear();
Object.entries(newData).forEach(([dataId, value]) =>
Expand Down
4 changes: 2 additions & 2 deletions packages/apollo-cache-inmemory/src/recordingCache.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { NormalizedCache, NormalizedCacheObject, StoreObject } from './types';

export class RecordingCache implements NormalizedCache {
constructor(private readonly data: NormalizedCacheObject = {}) {}

private recordedData: NormalizedCacheObject = {};

constructor(private readonly data: NormalizedCacheObject = {}) {}

public record(
transaction: (recordingCache: RecordingCache) => void,
): NormalizedCacheObject {
Expand Down
Loading

0 comments on commit 24d188e

Please sign in to comment.