@khanacademy/wonder-blocks-data 8.0.2 → 8.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/dist/es/index.js +68 -70
- package/dist/index.js +124 -249
- package/package.json +4 -3
- package/src/hooks/use-cached-effect.js +3 -14
- package/src/hooks/use-hydratable-effect.js +0 -4
- package/src/index.js +1 -0
- package/src/util/types.js +0 -4
- package/src/__tests__/__snapshots__/generated-snapshot.test.js.snap +0 -337
- package/src/__tests__/generated-snapshot.test.js +0 -350
package/dist/index.js
CHANGED
|
@@ -175,17 +175,10 @@ module.exports = require("@khanacademy/wonder-blocks-core");
|
|
|
175
175
|
|
|
176
176
|
"use strict";
|
|
177
177
|
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return FetchPolicy; });
|
|
178
|
-
// TODO(somewhatabstract, FEI-4172): Update eslint-plugin-flowtype when
|
|
179
|
-
// they've fixed https://github.com/gajus/eslint-plugin-flowtype/issues/502
|
|
180
|
-
|
|
181
|
-
/* eslint-disable no-undef */
|
|
182
|
-
|
|
183
178
|
/**
|
|
184
179
|
* Defines the various fetch policies that can be applied to requests.
|
|
185
180
|
*/
|
|
186
|
-
const FetchPolicy = __webpack_require__(
|
|
187
|
-
/* eslint-enable no-undef */
|
|
188
|
-
|
|
181
|
+
const FetchPolicy = __webpack_require__(23).Mirrored(["CacheBeforeNetwork", "CacheAndNetwork", "CacheOnly", "NetworkOnly"]);
|
|
189
182
|
/**
|
|
190
183
|
* Define what can be cached.
|
|
191
184
|
*
|
|
@@ -931,7 +924,7 @@ class ScopedInMemoryCache {
|
|
|
931
924
|
/**
|
|
932
925
|
* Policies to define how a hydratable effect should behave client-side.
|
|
933
926
|
*/
|
|
934
|
-
const WhenClientSide = __webpack_require__(
|
|
927
|
+
const WhenClientSide = __webpack_require__(23).Mirrored(["DoNotHydrate", "ExecuteWhenNoResult", "ExecuteWhenNoSuccessResult", "AlwaysExecute"]);
|
|
935
928
|
const DefaultScope = "useHydratableEffect";
|
|
936
929
|
/**
|
|
937
930
|
* Hook to execute an async operation on server and client.
|
|
@@ -1125,8 +1118,8 @@ const purgeHydrationCache = predicate => _ssr_cache_js__WEBPACK_IMPORTED_MODULE_
|
|
|
1125
1118
|
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_1__);
|
|
1126
1119
|
/* harmony import */ var _util_request_tracking_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(8);
|
|
1127
1120
|
/* harmony import */ var _util_ssr_cache_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(9);
|
|
1128
|
-
/* harmony import */ var _util_result_from_cache_response_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(
|
|
1129
|
-
/* harmony import */ var _use_request_interception_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(
|
|
1121
|
+
/* harmony import */ var _util_result_from_cache_response_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(33);
|
|
1122
|
+
/* harmony import */ var _use_request_interception_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(20);
|
|
1130
1123
|
|
|
1131
1124
|
|
|
1132
1125
|
|
|
@@ -1190,7 +1183,7 @@ const useServerEffect = (requestId, handler, options = {}) => {
|
|
|
1190
1183
|
/* harmony import */ var _util_request_fulfillment_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(10);
|
|
1191
1184
|
/* harmony import */ var _util_status_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(6);
|
|
1192
1185
|
/* harmony import */ var _use_shared_cache_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(5);
|
|
1193
|
-
/* harmony import */ var _use_request_interception_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(
|
|
1186
|
+
/* harmony import */ var _use_request_interception_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(20);
|
|
1194
1187
|
/* harmony import */ var _util_types_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(3);
|
|
1195
1188
|
|
|
1196
1189
|
|
|
@@ -1343,10 +1336,7 @@ const useCachedEffect = (requestId, handler, options = {}) => {
|
|
|
1343
1336
|
// really make sense - the same requestId should be handled the same as
|
|
1344
1337
|
// each other.
|
|
1345
1338
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1346
|
-
}, [requestId, onResultChanged, forceUpdate, setMostRecentResult, fetchPolicy]); //
|
|
1347
|
-
// indicates its a different request.
|
|
1348
|
-
|
|
1349
|
-
const requestIdRef = react__WEBPACK_IMPORTED_MODULE_0__["useRef"](requestId); // Calculate if we want to fetch the result or not.
|
|
1339
|
+
}, [requestId, onResultChanged, forceUpdate, setMostRecentResult, fetchPolicy]); // Calculate if we want to fetch the result or not.
|
|
1350
1340
|
// If this is true, we will do a new fetch, cancelling the previous fetch
|
|
1351
1341
|
// if there is one inflight.
|
|
1352
1342
|
|
|
@@ -1363,9 +1353,8 @@ const useCachedEffect = (requestId, handler, options = {}) => {
|
|
|
1363
1353
|
return false;
|
|
1364
1354
|
|
|
1365
1355
|
case _util_types_js__WEBPACK_IMPORTED_MODULE_7__[/* FetchPolicy */ "a"].CacheBeforeNetwork:
|
|
1366
|
-
// If we don't have a cached value
|
|
1367
|
-
|
|
1368
|
-
return mostRecentResult == null || requestId !== requestIdRef.current;
|
|
1356
|
+
// If we don't have a cached value then we need to fetch.
|
|
1357
|
+
return mostRecentResult == null;
|
|
1369
1358
|
|
|
1370
1359
|
case _util_types_js__WEBPACK_IMPORTED_MODULE_7__[/* FetchPolicy */ "a"].CacheAndNetwork:
|
|
1371
1360
|
case _util_types_js__WEBPACK_IMPORTED_MODULE_7__[/* FetchPolicy */ "a"].NetworkOnly:
|
|
@@ -1373,9 +1362,7 @@ const useCachedEffect = (requestId, handler, options = {}) => {
|
|
|
1373
1362
|
// result, then we need to fetch one.
|
|
1374
1363
|
return networkResultRef.current == null;
|
|
1375
1364
|
}
|
|
1376
|
-
}, [
|
|
1377
|
-
|
|
1378
|
-
requestIdRef.current = requestId;
|
|
1365
|
+
}, [mostRecentResult, fetchPolicy, hardSkip]);
|
|
1379
1366
|
react__WEBPACK_IMPORTED_MODULE_0__["useEffect"](() => {
|
|
1380
1367
|
if (!shouldFetch) {
|
|
1381
1368
|
return;
|
|
@@ -1405,6 +1392,76 @@ const useCachedEffect = (requestId, handler, options = {}) => {
|
|
|
1405
1392
|
/* 18 */
|
|
1406
1393
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
1407
1394
|
|
|
1395
|
+
"use strict";
|
|
1396
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return getGqlDataFromResponse; });
|
|
1397
|
+
/* harmony import */ var _data_error_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
|
|
1398
|
+
/* harmony import */ var _gql_error_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(4);
|
|
1399
|
+
|
|
1400
|
+
|
|
1401
|
+
/**
|
|
1402
|
+
* Validate a GQL operation response and extract the data.
|
|
1403
|
+
*/
|
|
1404
|
+
|
|
1405
|
+
const getGqlDataFromResponse = async response => {
|
|
1406
|
+
// Get the response as text, that way we can use the text in error
|
|
1407
|
+
// messaging, should our parsing fail.
|
|
1408
|
+
const bodyText = await response.text();
|
|
1409
|
+
let result;
|
|
1410
|
+
|
|
1411
|
+
try {
|
|
1412
|
+
result = JSON.parse(bodyText);
|
|
1413
|
+
} catch (e) {
|
|
1414
|
+
throw new _data_error_js__WEBPACK_IMPORTED_MODULE_0__[/* DataError */ "a"]("Failed to parse response", _data_error_js__WEBPACK_IMPORTED_MODULE_0__[/* DataErrors */ "b"].Parse, {
|
|
1415
|
+
metadata: {
|
|
1416
|
+
statusCode: response.status,
|
|
1417
|
+
bodyText
|
|
1418
|
+
},
|
|
1419
|
+
cause: e
|
|
1420
|
+
});
|
|
1421
|
+
} // Check for a bad status code.
|
|
1422
|
+
|
|
1423
|
+
|
|
1424
|
+
if (response.status >= 300) {
|
|
1425
|
+
throw new _data_error_js__WEBPACK_IMPORTED_MODULE_0__[/* DataError */ "a"]("Response unsuccessful", _data_error_js__WEBPACK_IMPORTED_MODULE_0__[/* DataErrors */ "b"].Network, {
|
|
1426
|
+
metadata: {
|
|
1427
|
+
statusCode: response.status,
|
|
1428
|
+
result
|
|
1429
|
+
}
|
|
1430
|
+
});
|
|
1431
|
+
} // Check that we have a valid result payload.
|
|
1432
|
+
|
|
1433
|
+
|
|
1434
|
+
if ( // Flow shouldn't be warning about this.
|
|
1435
|
+
// $FlowIgnore[method-unbinding]
|
|
1436
|
+
!Object.prototype.hasOwnProperty.call(result, "data") && // Flow shouldn't be warning about this.
|
|
1437
|
+
// $FlowIgnore[method-unbinding]
|
|
1438
|
+
!Object.prototype.hasOwnProperty.call(result, "errors")) {
|
|
1439
|
+
throw new _gql_error_js__WEBPACK_IMPORTED_MODULE_1__[/* GqlError */ "a"]("Server response missing", _gql_error_js__WEBPACK_IMPORTED_MODULE_1__[/* GqlErrors */ "b"].BadResponse, {
|
|
1440
|
+
metadata: {
|
|
1441
|
+
statusCode: response.status,
|
|
1442
|
+
result
|
|
1443
|
+
}
|
|
1444
|
+
});
|
|
1445
|
+
} // If the response payload has errors, throw an error.
|
|
1446
|
+
|
|
1447
|
+
|
|
1448
|
+
if (result.errors != null && Array.isArray(result.errors) && result.errors.length > 0) {
|
|
1449
|
+
throw new _gql_error_js__WEBPACK_IMPORTED_MODULE_1__[/* GqlError */ "a"]("GraphQL errors", _gql_error_js__WEBPACK_IMPORTED_MODULE_1__[/* GqlErrors */ "b"].ErrorResult, {
|
|
1450
|
+
metadata: {
|
|
1451
|
+
statusCode: response.status,
|
|
1452
|
+
result
|
|
1453
|
+
}
|
|
1454
|
+
});
|
|
1455
|
+
} // We got here, so return the data.
|
|
1456
|
+
|
|
1457
|
+
|
|
1458
|
+
return result.data;
|
|
1459
|
+
};
|
|
1460
|
+
|
|
1461
|
+
/***/ }),
|
|
1462
|
+
/* 19 */
|
|
1463
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
1464
|
+
|
|
1408
1465
|
"use strict";
|
|
1409
1466
|
/* unused harmony export DocumentTypes */
|
|
1410
1467
|
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return graphQLDocumentNodeParser; });
|
|
@@ -1483,7 +1540,7 @@ function graphQLDocumentNodeParser(document) {
|
|
|
1483
1540
|
}
|
|
1484
1541
|
|
|
1485
1542
|
/***/ }),
|
|
1486
|
-
/*
|
|
1543
|
+
/* 20 */
|
|
1487
1544
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
1488
1545
|
|
|
1489
1546
|
"use strict";
|
|
@@ -1534,7 +1591,7 @@ const useRequestInterception = (requestId, handler) => {
|
|
|
1534
1591
|
};
|
|
1535
1592
|
|
|
1536
1593
|
/***/ }),
|
|
1537
|
-
/*
|
|
1594
|
+
/* 21 */
|
|
1538
1595
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
1539
1596
|
|
|
1540
1597
|
"use strict";
|
|
@@ -1545,7 +1602,7 @@ const useRequestInterception = (requestId, handler) => {
|
|
|
1545
1602
|
const GqlRouterContext = /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createContext"](null);
|
|
1546
1603
|
|
|
1547
1604
|
/***/ }),
|
|
1548
|
-
/*
|
|
1605
|
+
/* 22 */
|
|
1549
1606
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
1550
1607
|
|
|
1551
1608
|
"use strict";
|
|
@@ -1579,129 +1636,13 @@ const mergeGqlContext = (defaultContext, overrides) => {
|
|
|
1579
1636
|
};
|
|
1580
1637
|
|
|
1581
1638
|
/***/ }),
|
|
1582
|
-
/*
|
|
1583
|
-
/***/ (function(module, exports
|
|
1584
|
-
|
|
1585
|
-
"use strict";
|
|
1586
|
-
/**
|
|
1587
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
1588
|
-
*
|
|
1589
|
-
* This source code is licensed under the MIT license found in the
|
|
1590
|
-
* LICENSE file in the root directory of this source tree.
|
|
1591
|
-
*/
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
// Below we want to use `hasOwnProperty` on an object that doesn't have
|
|
1596
|
-
// `Object.prototype` in its proto chain, so we must extract it here.
|
|
1597
|
-
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
1598
|
-
|
|
1599
|
-
// Map from an enum object to a reverse map of its values to names
|
|
1600
|
-
var reverseMapCache = typeof WeakMap === 'function' ? new WeakMap() : new Map();
|
|
1601
|
-
|
|
1602
|
-
// Computes the reverse mapping of the enum object: from value to name.
|
|
1603
|
-
// Flow Enum values are unique (enforced by the parser), so this is a
|
|
1604
|
-
// one to one mapping.
|
|
1605
|
-
function getReverseMap(enumObject) {
|
|
1606
|
-
var reverseMap = reverseMapCache.get(enumObject);
|
|
1607
|
-
if (reverseMap !== undefined) {
|
|
1608
|
-
return reverseMap;
|
|
1609
|
-
}
|
|
1610
|
-
// We aren't using `Object.values` because that gets enumerable
|
|
1611
|
-
// properties, and our properties aren't enumerable.
|
|
1612
|
-
var newReverseMap = new Map();
|
|
1613
|
-
Object.getOwnPropertyNames(enumObject).forEach(function (name) {
|
|
1614
|
-
newReverseMap.set(enumObject[name], name);
|
|
1615
|
-
});
|
|
1616
|
-
reverseMapCache.set(enumObject, newReverseMap);
|
|
1617
|
-
return newReverseMap;
|
|
1618
|
-
}
|
|
1619
|
-
|
|
1620
|
-
var EnumPrototype = Object.freeze(
|
|
1621
|
-
Object.defineProperties(Object.create(null), {
|
|
1622
|
-
isValid: {
|
|
1623
|
-
value: function (x) {
|
|
1624
|
-
return getReverseMap(this).has(x);
|
|
1625
|
-
},
|
|
1626
|
-
},
|
|
1627
|
-
cast: {
|
|
1628
|
-
value: function (x) {
|
|
1629
|
-
return this.isValid(x) ? x : undefined;
|
|
1630
|
-
},
|
|
1631
|
-
},
|
|
1632
|
-
members: {
|
|
1633
|
-
value: function () {
|
|
1634
|
-
return getReverseMap(this).keys();
|
|
1635
|
-
},
|
|
1636
|
-
},
|
|
1637
|
-
getName: {
|
|
1638
|
-
value: function (value) {
|
|
1639
|
-
return getReverseMap(this).get(value);
|
|
1640
|
-
}
|
|
1641
|
-
}
|
|
1642
|
-
})
|
|
1643
|
-
);
|
|
1644
|
-
|
|
1645
|
-
// `members` is an object mapping name to value.
|
|
1646
|
-
function Enum(members) {
|
|
1647
|
-
var o = Object.create(EnumPrototype);
|
|
1648
|
-
for (var k in members) {
|
|
1649
|
-
if (hasOwnProperty.call(members, k)) {
|
|
1650
|
-
// Create non-enumerable properties.
|
|
1651
|
-
Object.defineProperty(o, k, {value: members[k]});
|
|
1652
|
-
}
|
|
1653
|
-
}
|
|
1654
|
-
return Object.freeze(o);
|
|
1655
|
-
}
|
|
1656
|
-
|
|
1657
|
-
// Mirrored enum (string enum with no member initializers).
|
|
1658
|
-
// Optimized implementation, taking advantage of the fact that
|
|
1659
|
-
// keys and values are identical.
|
|
1660
|
-
var EnumMirroredPrototype = Object.freeze(
|
|
1661
|
-
Object.defineProperties(Object.create(null), {
|
|
1662
|
-
isValid: {
|
|
1663
|
-
value: function (x) {
|
|
1664
|
-
if (typeof x === 'string') {
|
|
1665
|
-
return hasOwnProperty.call(this, x);
|
|
1666
|
-
}
|
|
1667
|
-
return false;
|
|
1668
|
-
},
|
|
1669
|
-
},
|
|
1670
|
-
cast: {
|
|
1671
|
-
value: EnumPrototype.cast,
|
|
1672
|
-
},
|
|
1673
|
-
members: {
|
|
1674
|
-
value: function () {
|
|
1675
|
-
// We aren't using `Object.values` because that gets enumerable
|
|
1676
|
-
// properties, and our properties aren't enumerable.
|
|
1677
|
-
return Object.getOwnPropertyNames(this).values();
|
|
1678
|
-
},
|
|
1679
|
-
},
|
|
1680
|
-
getName: {
|
|
1681
|
-
value: function (value) {
|
|
1682
|
-
return value;
|
|
1683
|
-
}
|
|
1684
|
-
}
|
|
1685
|
-
})
|
|
1686
|
-
);
|
|
1687
|
-
|
|
1688
|
-
// `members` is an array of names (which, are also the values).
|
|
1689
|
-
Enum.Mirrored = function EnumMirrored(members) {
|
|
1690
|
-
var o = Object.create(EnumMirroredPrototype);
|
|
1691
|
-
for (var i = 0, len = members.length; i < len; ++i) {
|
|
1692
|
-
// Value is same as key. Also, non-enumerable.
|
|
1693
|
-
Object.defineProperty(o, members[i], {value: members[i]});
|
|
1694
|
-
}
|
|
1695
|
-
return Object.freeze(o);
|
|
1696
|
-
};
|
|
1697
|
-
|
|
1698
|
-
Object.freeze(Enum.Mirrored);
|
|
1699
|
-
|
|
1700
|
-
module.exports = Object.freeze(Enum);
|
|
1639
|
+
/* 23 */
|
|
1640
|
+
/***/ (function(module, exports) {
|
|
1701
1641
|
|
|
1642
|
+
module.exports = require("flow-enums-runtime");
|
|
1702
1643
|
|
|
1703
1644
|
/***/ }),
|
|
1704
|
-
/*
|
|
1645
|
+
/* 24 */
|
|
1705
1646
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
1706
1647
|
|
|
1707
1648
|
"use strict";
|
|
@@ -1778,7 +1719,7 @@ const abortInflightRequests = () => {
|
|
|
1778
1719
|
};
|
|
1779
1720
|
|
|
1780
1721
|
/***/ }),
|
|
1781
|
-
/*
|
|
1722
|
+
/* 25 */
|
|
1782
1723
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
1783
1724
|
|
|
1784
1725
|
"use strict";
|
|
@@ -1801,7 +1742,7 @@ const purgeCaches = () => {
|
|
|
1801
1742
|
};
|
|
1802
1743
|
|
|
1803
1744
|
/***/ }),
|
|
1804
|
-
/*
|
|
1745
|
+
/* 26 */
|
|
1805
1746
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
1806
1747
|
|
|
1807
1748
|
"use strict";
|
|
@@ -1832,7 +1773,7 @@ class TrackData extends react__WEBPACK_IMPORTED_MODULE_0__["Component"] {
|
|
|
1832
1773
|
}
|
|
1833
1774
|
|
|
1834
1775
|
/***/ }),
|
|
1835
|
-
/*
|
|
1776
|
+
/* 27 */
|
|
1836
1777
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
1837
1778
|
|
|
1838
1779
|
"use strict";
|
|
@@ -1864,7 +1805,7 @@ const Data = ({
|
|
|
1864
1805
|
/* harmony default export */ __webpack_exports__["a"] = (Data);
|
|
1865
1806
|
|
|
1866
1807
|
/***/ }),
|
|
1867
|
-
/*
|
|
1808
|
+
/* 28 */
|
|
1868
1809
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
1869
1810
|
|
|
1870
1811
|
"use strict";
|
|
@@ -1905,7 +1846,7 @@ const InterceptRequests = ({
|
|
|
1905
1846
|
/* harmony default export */ __webpack_exports__["a"] = (InterceptRequests);
|
|
1906
1847
|
|
|
1907
1848
|
/***/ }),
|
|
1908
|
-
/*
|
|
1849
|
+
/* 29 */
|
|
1909
1850
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
1910
1851
|
|
|
1911
1852
|
"use strict";
|
|
@@ -1954,12 +1895,12 @@ const getGqlRequestId = (operation, variables, context) => {
|
|
|
1954
1895
|
};
|
|
1955
1896
|
|
|
1956
1897
|
/***/ }),
|
|
1957
|
-
/*
|
|
1898
|
+
/* 30 */
|
|
1958
1899
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
1959
1900
|
|
|
1960
1901
|
"use strict";
|
|
1961
1902
|
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return toGqlOperation; });
|
|
1962
|
-
/* harmony import */ var _graphql_document_node_parser_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(
|
|
1903
|
+
/* harmony import */ var _graphql_document_node_parser_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(19);
|
|
1963
1904
|
|
|
1964
1905
|
|
|
1965
1906
|
/**
|
|
@@ -2001,14 +1942,14 @@ const toGqlOperation = documentNode => {
|
|
|
2001
1942
|
};
|
|
2002
1943
|
|
|
2003
1944
|
/***/ }),
|
|
2004
|
-
/*
|
|
1945
|
+
/* 31 */
|
|
2005
1946
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
2006
1947
|
|
|
2007
1948
|
"use strict";
|
|
2008
1949
|
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return GqlRouter; });
|
|
2009
1950
|
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
|
|
2010
1951
|
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
2011
|
-
/* harmony import */ var _util_gql_router_context_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(
|
|
1952
|
+
/* harmony import */ var _util_gql_router_context_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(21);
|
|
2012
1953
|
|
|
2013
1954
|
|
|
2014
1955
|
|
|
@@ -2045,16 +1986,16 @@ const GqlRouter = ({
|
|
|
2045
1986
|
};
|
|
2046
1987
|
|
|
2047
1988
|
/***/ }),
|
|
2048
|
-
/*
|
|
1989
|
+
/* 32 */
|
|
2049
1990
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
2050
1991
|
|
|
2051
1992
|
"use strict";
|
|
2052
1993
|
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return useGql; });
|
|
2053
1994
|
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
|
|
2054
1995
|
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
2055
|
-
/* harmony import */ var _util_merge_gql_context_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(
|
|
2056
|
-
/* harmony import */ var _use_gql_router_context_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(
|
|
2057
|
-
/* harmony import */ var _util_get_gql_data_from_response_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(
|
|
1996
|
+
/* harmony import */ var _util_merge_gql_context_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(22);
|
|
1997
|
+
/* harmony import */ var _use_gql_router_context_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(34);
|
|
1998
|
+
/* harmony import */ var _util_get_gql_data_from_response_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(18);
|
|
2058
1999
|
|
|
2059
2000
|
|
|
2060
2001
|
|
|
@@ -2095,7 +2036,7 @@ const useGql = (context = {}) => {
|
|
|
2095
2036
|
};
|
|
2096
2037
|
|
|
2097
2038
|
/***/ }),
|
|
2098
|
-
/*
|
|
2039
|
+
/* 33 */
|
|
2099
2040
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
2100
2041
|
|
|
2101
2042
|
"use strict";
|
|
@@ -2135,15 +2076,15 @@ const resultFromCachedResponse = cacheEntry => {
|
|
|
2135
2076
|
};
|
|
2136
2077
|
|
|
2137
2078
|
/***/ }),
|
|
2138
|
-
/*
|
|
2079
|
+
/* 34 */
|
|
2139
2080
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
2140
2081
|
|
|
2141
2082
|
"use strict";
|
|
2142
2083
|
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return useGqlRouterContext; });
|
|
2143
2084
|
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
|
|
2144
2085
|
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
2145
|
-
/* harmony import */ var _util_merge_gql_context_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(
|
|
2146
|
-
/* harmony import */ var _util_gql_router_context_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(
|
|
2086
|
+
/* harmony import */ var _util_merge_gql_context_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(22);
|
|
2087
|
+
/* harmony import */ var _util_gql_router_context_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(21);
|
|
2147
2088
|
/* harmony import */ var _util_gql_error_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(4);
|
|
2148
2089
|
|
|
2149
2090
|
|
|
@@ -2186,76 +2127,6 @@ const useGqlRouterContext = (contextOverrides = {}) => {
|
|
|
2186
2127
|
return finalRouterContext;
|
|
2187
2128
|
};
|
|
2188
2129
|
|
|
2189
|
-
/***/ }),
|
|
2190
|
-
/* 34 */
|
|
2191
|
-
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
2192
|
-
|
|
2193
|
-
"use strict";
|
|
2194
|
-
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return getGqlDataFromResponse; });
|
|
2195
|
-
/* harmony import */ var _data_error_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
|
|
2196
|
-
/* harmony import */ var _gql_error_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(4);
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
/**
|
|
2200
|
-
* Validate a GQL operation response and extract the data.
|
|
2201
|
-
*/
|
|
2202
|
-
|
|
2203
|
-
const getGqlDataFromResponse = async response => {
|
|
2204
|
-
// Get the response as text, that way we can use the text in error
|
|
2205
|
-
// messaging, should our parsing fail.
|
|
2206
|
-
const bodyText = await response.text();
|
|
2207
|
-
let result;
|
|
2208
|
-
|
|
2209
|
-
try {
|
|
2210
|
-
result = JSON.parse(bodyText);
|
|
2211
|
-
} catch (e) {
|
|
2212
|
-
throw new _data_error_js__WEBPACK_IMPORTED_MODULE_0__[/* DataError */ "a"]("Failed to parse response", _data_error_js__WEBPACK_IMPORTED_MODULE_0__[/* DataErrors */ "b"].Parse, {
|
|
2213
|
-
metadata: {
|
|
2214
|
-
statusCode: response.status,
|
|
2215
|
-
bodyText
|
|
2216
|
-
},
|
|
2217
|
-
cause: e
|
|
2218
|
-
});
|
|
2219
|
-
} // Check for a bad status code.
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
if (response.status >= 300) {
|
|
2223
|
-
throw new _data_error_js__WEBPACK_IMPORTED_MODULE_0__[/* DataError */ "a"]("Response unsuccessful", _data_error_js__WEBPACK_IMPORTED_MODULE_0__[/* DataErrors */ "b"].Network, {
|
|
2224
|
-
metadata: {
|
|
2225
|
-
statusCode: response.status,
|
|
2226
|
-
result
|
|
2227
|
-
}
|
|
2228
|
-
});
|
|
2229
|
-
} // Check that we have a valid result payload.
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
if ( // Flow shouldn't be warning about this.
|
|
2233
|
-
// $FlowIgnore[method-unbinding]
|
|
2234
|
-
!Object.prototype.hasOwnProperty.call(result, "data") && // Flow shouldn't be warning about this.
|
|
2235
|
-
// $FlowIgnore[method-unbinding]
|
|
2236
|
-
!Object.prototype.hasOwnProperty.call(result, "errors")) {
|
|
2237
|
-
throw new _gql_error_js__WEBPACK_IMPORTED_MODULE_1__[/* GqlError */ "a"]("Server response missing", _gql_error_js__WEBPACK_IMPORTED_MODULE_1__[/* GqlErrors */ "b"].BadResponse, {
|
|
2238
|
-
metadata: {
|
|
2239
|
-
statusCode: response.status,
|
|
2240
|
-
result
|
|
2241
|
-
}
|
|
2242
|
-
});
|
|
2243
|
-
} // If the response payload has errors, throw an error.
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
if (result.errors != null && Array.isArray(result.errors) && result.errors.length > 0) {
|
|
2247
|
-
throw new _gql_error_js__WEBPACK_IMPORTED_MODULE_1__[/* GqlError */ "a"]("GraphQL errors", _gql_error_js__WEBPACK_IMPORTED_MODULE_1__[/* GqlErrors */ "b"].ErrorResult, {
|
|
2248
|
-
metadata: {
|
|
2249
|
-
statusCode: response.status,
|
|
2250
|
-
result
|
|
2251
|
-
}
|
|
2252
|
-
});
|
|
2253
|
-
} // We got here, so return the data.
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
return result.data;
|
|
2257
|
-
};
|
|
2258
|
-
|
|
2259
2130
|
/***/ }),
|
|
2260
2131
|
/* 35 */
|
|
2261
2132
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
@@ -2270,23 +2141,23 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
2270
2141
|
|
|
2271
2142
|
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "purgeHydrationCache", function() { return _util_hydration_cache_api_js__WEBPACK_IMPORTED_MODULE_1__["b"]; });
|
|
2272
2143
|
|
|
2273
|
-
/* harmony import */ var _util_request_api_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(
|
|
2144
|
+
/* harmony import */ var _util_request_api_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(24);
|
|
2274
2145
|
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "fetchTrackedRequests", function() { return _util_request_api_js__WEBPACK_IMPORTED_MODULE_2__["b"]; });
|
|
2275
2146
|
|
|
2276
2147
|
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "hasTrackedRequestsToBeFetched", function() { return _util_request_api_js__WEBPACK_IMPORTED_MODULE_2__["c"]; });
|
|
2277
2148
|
|
|
2278
2149
|
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "abortInflightRequests", function() { return _util_request_api_js__WEBPACK_IMPORTED_MODULE_2__["a"]; });
|
|
2279
2150
|
|
|
2280
|
-
/* harmony import */ var _util_purge_caches_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(
|
|
2151
|
+
/* harmony import */ var _util_purge_caches_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(25);
|
|
2281
2152
|
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "purgeCaches", function() { return _util_purge_caches_js__WEBPACK_IMPORTED_MODULE_3__["a"]; });
|
|
2282
2153
|
|
|
2283
|
-
/* harmony import */ var _components_track_data_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(
|
|
2154
|
+
/* harmony import */ var _components_track_data_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(26);
|
|
2284
2155
|
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "TrackData", function() { return _components_track_data_js__WEBPACK_IMPORTED_MODULE_4__["a"]; });
|
|
2285
2156
|
|
|
2286
|
-
/* harmony import */ var _components_data_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(
|
|
2157
|
+
/* harmony import */ var _components_data_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(27);
|
|
2287
2158
|
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "Data", function() { return _components_data_js__WEBPACK_IMPORTED_MODULE_5__["a"]; });
|
|
2288
2159
|
|
|
2289
|
-
/* harmony import */ var _components_intercept_requests_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(
|
|
2160
|
+
/* harmony import */ var _components_intercept_requests_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(28);
|
|
2290
2161
|
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "InterceptRequests", function() { return _components_intercept_requests_js__WEBPACK_IMPORTED_MODULE_6__["a"]; });
|
|
2291
2162
|
|
|
2292
2163
|
/* harmony import */ var _util_data_error_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(0);
|
|
@@ -2319,25 +2190,28 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
2319
2190
|
/* harmony import */ var _util_status_js__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(6);
|
|
2320
2191
|
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "Status", function() { return _util_status_js__WEBPACK_IMPORTED_MODULE_14__["a"]; });
|
|
2321
2192
|
|
|
2322
|
-
/* harmony import */ var _util_get_gql_request_id_js__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(
|
|
2193
|
+
/* harmony import */ var _util_get_gql_request_id_js__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(29);
|
|
2323
2194
|
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "getGqlRequestId", function() { return _util_get_gql_request_id_js__WEBPACK_IMPORTED_MODULE_15__["a"]; });
|
|
2324
2195
|
|
|
2325
|
-
/* harmony import */ var
|
|
2326
|
-
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "
|
|
2196
|
+
/* harmony import */ var _util_get_gql_data_from_response_js__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(18);
|
|
2197
|
+
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "getGqlDataFromResponse", function() { return _util_get_gql_data_from_response_js__WEBPACK_IMPORTED_MODULE_16__["a"]; });
|
|
2198
|
+
|
|
2199
|
+
/* harmony import */ var _util_graphql_document_node_parser_js__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(19);
|
|
2200
|
+
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "graphQLDocumentNodeParser", function() { return _util_graphql_document_node_parser_js__WEBPACK_IMPORTED_MODULE_17__["a"]; });
|
|
2327
2201
|
|
|
2328
|
-
/* harmony import */ var
|
|
2329
|
-
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "toGqlOperation", function() { return
|
|
2202
|
+
/* harmony import */ var _util_to_gql_operation_js__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(30);
|
|
2203
|
+
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "toGqlOperation", function() { return _util_to_gql_operation_js__WEBPACK_IMPORTED_MODULE_18__["a"]; });
|
|
2330
2204
|
|
|
2331
|
-
/* harmony import */ var
|
|
2332
|
-
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GqlRouter", function() { return
|
|
2205
|
+
/* harmony import */ var _components_gql_router_js__WEBPACK_IMPORTED_MODULE_19__ = __webpack_require__(31);
|
|
2206
|
+
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GqlRouter", function() { return _components_gql_router_js__WEBPACK_IMPORTED_MODULE_19__["a"]; });
|
|
2333
2207
|
|
|
2334
|
-
/* harmony import */ var
|
|
2335
|
-
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "useGql", function() { return
|
|
2208
|
+
/* harmony import */ var _hooks_use_gql_js__WEBPACK_IMPORTED_MODULE_20__ = __webpack_require__(32);
|
|
2209
|
+
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "useGql", function() { return _hooks_use_gql_js__WEBPACK_IMPORTED_MODULE_20__["a"]; });
|
|
2336
2210
|
|
|
2337
|
-
/* harmony import */ var
|
|
2338
|
-
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GqlError", function() { return
|
|
2211
|
+
/* harmony import */ var _util_gql_error_js__WEBPACK_IMPORTED_MODULE_21__ = __webpack_require__(4);
|
|
2212
|
+
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GqlError", function() { return _util_gql_error_js__WEBPACK_IMPORTED_MODULE_21__["a"]; });
|
|
2339
2213
|
|
|
2340
|
-
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GqlErrors", function() { return
|
|
2214
|
+
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GqlErrors", function() { return _util_gql_error_js__WEBPACK_IMPORTED_MODULE_21__["b"]; });
|
|
2341
2215
|
|
|
2342
2216
|
// TODO(somewhatabstract, FEI-4174): Update eslint-plugin-import when they
|
|
2343
2217
|
// have fixed:
|
|
@@ -2368,5 +2242,6 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
2368
2242
|
|
|
2369
2243
|
|
|
2370
2244
|
|
|
2245
|
+
|
|
2371
2246
|
/***/ })
|
|
2372
2247
|
/******/ ]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@khanacademy/wonder-blocks-data",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.5",
|
|
4
4
|
"design": "v1",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -13,11 +13,12 @@
|
|
|
13
13
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@babel/runtime": "^7.
|
|
17
|
-
"@khanacademy/wonder-blocks-core": "^4.3.
|
|
16
|
+
"@babel/runtime": "^7.18.6",
|
|
17
|
+
"@khanacademy/wonder-blocks-core": "^4.3.2"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
20
|
"@khanacademy/wonder-stuff-core": "^0.1.2",
|
|
21
|
+
"flow-enums-runtime": "^0.0.6",
|
|
21
22
|
"react": "16.14.0"
|
|
22
23
|
},
|
|
23
24
|
"devDependencies": {
|
|
@@ -232,10 +232,6 @@ export const useCachedEffect = <TData: ValidCacheData>(
|
|
|
232
232
|
fetchPolicy,
|
|
233
233
|
]);
|
|
234
234
|
|
|
235
|
-
// We need to trigger a re-render when the request ID changes as that
|
|
236
|
-
// indicates its a different request.
|
|
237
|
-
const requestIdRef = React.useRef(requestId);
|
|
238
|
-
|
|
239
235
|
// Calculate if we want to fetch the result or not.
|
|
240
236
|
// If this is true, we will do a new fetch, cancelling the previous fetch
|
|
241
237
|
// if there is one inflight.
|
|
@@ -252,12 +248,8 @@ export const useCachedEffect = <TData: ValidCacheData>(
|
|
|
252
248
|
return false;
|
|
253
249
|
|
|
254
250
|
case FetchPolicy.CacheBeforeNetwork:
|
|
255
|
-
// If we don't have a cached value
|
|
256
|
-
|
|
257
|
-
return (
|
|
258
|
-
mostRecentResult == null ||
|
|
259
|
-
requestId !== requestIdRef.current
|
|
260
|
-
);
|
|
251
|
+
// If we don't have a cached value then we need to fetch.
|
|
252
|
+
return mostRecentResult == null;
|
|
261
253
|
|
|
262
254
|
case FetchPolicy.CacheAndNetwork:
|
|
263
255
|
case FetchPolicy.NetworkOnly:
|
|
@@ -265,10 +257,7 @@ export const useCachedEffect = <TData: ValidCacheData>(
|
|
|
265
257
|
// result, then we need to fetch one.
|
|
266
258
|
return networkResultRef.current == null;
|
|
267
259
|
}
|
|
268
|
-
}, [
|
|
269
|
-
|
|
270
|
-
// Let's make sure our ref is set to the most recent requestId.
|
|
271
|
-
requestIdRef.current = requestId;
|
|
260
|
+
}, [mostRecentResult, fetchPolicy, hardSkip]);
|
|
272
261
|
|
|
273
262
|
React.useEffect(() => {
|
|
274
263
|
if (!shouldFetch) {
|
|
@@ -16,9 +16,6 @@ import type {Result, ValidCacheData} from "../util/types.js";
|
|
|
16
16
|
* Policies to define how a hydratable effect should behave client-side.
|
|
17
17
|
*/
|
|
18
18
|
export enum WhenClientSide {
|
|
19
|
-
// TODO(somewhatabstract, FEI-4172): Update eslint-plugin-flowtype when
|
|
20
|
-
// they've fixed https://github.com/gajus/eslint-plugin-flowtype/issues/502
|
|
21
|
-
/* eslint-disable no-undef */
|
|
22
19
|
/**
|
|
23
20
|
* The result from executing the effect server-side will not be hydrated.
|
|
24
21
|
* The effect will always be executed client-side.
|
|
@@ -52,7 +49,6 @@ export enum WhenClientSide {
|
|
|
52
49
|
* hydrated result status.
|
|
53
50
|
*/
|
|
54
51
|
AlwaysExecute,
|
|
55
|
-
/* eslint-enable no-undef */
|
|
56
52
|
}
|
|
57
53
|
|
|
58
54
|
type HydratableEffectOptions<TData: ValidCacheData> = {|
|