|
|
@@ -8,26 +8,27 @@ import {
|
|
|
// Types
|
|
|
CacheConfig,
|
|
|
ObservableFromValue,
|
|
|
+ GraphQLResponse,
|
|
|
+ RequestParameters,
|
|
|
FetchFunction,
|
|
|
- QueryPayload,
|
|
|
- RequestNode,
|
|
|
Variables,
|
|
|
} from 'relay-runtime';
|
|
|
|
|
|
// 100 cache entries, 300 seconds until cache is invalid.
|
|
|
-const cache = new QueryResponseCache({size: 100, ttl: 300000});
|
|
|
+export const cache = new QueryResponseCache({size: 100, ttl: 300000});
|
|
|
|
|
|
export const fetchQuery: FetchFunction = (
|
|
|
- operation: RequestNode,
|
|
|
+ operation: RequestParameters,
|
|
|
variables: Variables,
|
|
|
cacheConfig: CacheConfig
|
|
|
-): ObservableFromValue<QueryPayload> => {
|
|
|
+): ObservableFromValue<GraphQLResponse> => {
|
|
|
const queryId: string = operation.name;
|
|
|
- const cachedData: QueryPayload = cache.get(queryId, variables);
|
|
|
+ const cachedData: GraphQLResponse = cache.get(queryId, variables);
|
|
|
const forceLoad: boolean = cacheConfig && cacheConfig.force;
|
|
|
|
|
|
if (!forceLoad && cachedData) {
|
|
|
- return cachedData;
|
|
|
+ // Return promise to keep returns consistent
|
|
|
+ return new Promise(resolve => resolve(cachedData));
|
|
|
}
|
|
|
|
|
|
return fetch('/api/graphql', {
|