UNPKG

apollo-client

Version:
29 lines 1.11 kB
import { print, } from 'graphql-tag/printer'; var Deduplicator = (function () { function Deduplicator(networkInterface) { this.networkInterface = networkInterface; this.inFlightRequestPromises = {}; } Deduplicator.prototype.query = function (request, deduplicate) { var _this = this; if (deduplicate === void 0) { deduplicate = true; } if (!deduplicate) { return this.networkInterface.query(request); } var key = this.getKey(request); if (!this.inFlightRequestPromises[key]) { this.inFlightRequestPromises[key] = this.networkInterface.query(request); } return this.inFlightRequestPromises[key] .then(function (res) { delete _this.inFlightRequestPromises[key]; return res; }); }; Deduplicator.prototype.getKey = function (request) { return print(request.query) + "|" + JSON.stringify(request.variables) + "|" + request.operationName; }; return Deduplicator; }()); export { Deduplicator }; //# sourceMappingURL=Deduplicator.js.map