UNPKG

gqty

Version:

The No-GraphQL Client for TypeScript

46 lines (39 loc) 1.38 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); const extend = require('just-extend'); const index = require('../Error/index.js'); function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; } const extend__default = /*#__PURE__*/_interopDefault(extend); const updateCaches = (results, caches, cacheSetOptions) => { var _a; const errorSet = /* @__PURE__ */ new Set(); for (const response of results) { const { data, error, extensions } = response; const type = extensions == null ? void 0 : extensions.type; if (!type || typeof type !== "string") { if (process.env.NODE_ENV !== "production") { console.warn("[GQty] Missing extensions.type in query result."); } continue; } if (data !== void 0) { const newValues = { [type]: extend__default["default"](true, {}, data) }; for (const cache of caches) { cache.set(newValues, cacheSetOptions); } } if (error) { if (!(error instanceof index.GQtyError) || !((_a = error.graphQLErrors) == null ? void 0 : _a.length)) { throw error; } else { error.graphQLErrors.forEach((error2) => errorSet.add(error2)); } } } if (errorSet.size) { throw index.GQtyError.fromGraphQLErrors(Array.from(errorSet)); } }; exports.updateCaches = updateCaches;