apollo-client-cors-hack
Version:
A simple yet functional GraphQL client.
38 lines • 1.32 kB
JavaScript
import { diffQueryAgainstStore, } from './readFromStore';
import { writeResultToStore, } from './writeToStore';
export function createStoreReducer(resultReducer, document, variables, config) {
return function (store, action) {
var _a = diffQueryAgainstStore({
store: store,
query: document,
variables: variables,
returnPartialData: true,
fragmentMatcherFunction: config.fragmentMatcher,
config: config,
}), result = _a.result, isMissing = _a.isMissing;
if (isMissing) {
return store;
}
var nextResult;
try {
nextResult = resultReducer(result, action, variables);
}
catch (err) {
console.warn('Unhandled error in result reducer', err);
throw err;
}
if (result !== nextResult) {
return writeResultToStore({
dataId: 'ROOT_QUERY',
result: nextResult,
store: store,
document: document,
variables: variables,
dataIdFromObject: config.dataIdFromObject,
fragmentMatcherFunction: config.fragmentMatcher,
});
}
return store;
};
}
//# sourceMappingURL=resultReducers.js.map