1 | function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
2 |
|
3 | import { print } from 'graphql/language/printer';
|
4 | import { objToKey } from './utils';
|
5 | var cachedQueriesByClient = new WeakMap();
|
6 | export function getCachedObservableQuery(client, options) {
|
7 | var queriesForClient = getCachedQueriesForClient(client);
|
8 | var cacheKey = getCacheKey(options);
|
9 | var observableQuery = queriesForClient.get(cacheKey);
|
10 |
|
11 | if (observableQuery == null) {
|
12 | observableQuery = client.watchQuery(options);
|
13 | queriesForClient.set(cacheKey, observableQuery);
|
14 | }
|
15 |
|
16 | return observableQuery;
|
17 | }
|
18 | export function invalidateCachedObservableQuery(client, options) {
|
19 | var queriesForClient = getCachedQueriesForClient(client);
|
20 | var cacheKey = getCacheKey(options);
|
21 | queriesForClient["delete"](cacheKey);
|
22 | }
|
23 |
|
24 | function getCachedQueriesForClient(client) {
|
25 | var queriesForClient = cachedQueriesByClient.get(client);
|
26 |
|
27 | if (queriesForClient == null) {
|
28 | queriesForClient = new Map();
|
29 | cachedQueriesByClient.set(client, queriesForClient);
|
30 | }
|
31 |
|
32 | return queriesForClient;
|
33 | }
|
34 |
|
35 | function getCacheKey(_ref) {
|
36 | var query = _ref.query,
|
37 | options = _objectWithoutPropertiesLoose(_ref, ["query"]);
|
38 |
|
39 | return print(query) + "@@" + objToKey(options);
|
40 | } |
\ | No newline at end of file |