@khanacademy/wonder-blocks-data 10.0.5 → 10.1.0
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 +14 -0
- package/dist/es/index.js +12 -2
- package/dist/index.js +12 -2
- package/dist/index.js.flow +1 -1
- package/package.json +4 -4
- package/src/components/__tests__/data.test.js +8 -14
- package/src/components/__tests__/gql-router.test.js +2 -2
- package/src/components/__tests__/intercept-requests.test.js +2 -2
- package/src/components/__tests__/track-data.test.js +2 -2
- package/src/components/data.js +3 -7
- package/src/components/gql-router.js +2 -2
- package/src/components/intercept-context.js +1 -1
- package/src/components/intercept-requests.js +2 -2
- package/src/components/track-data.js +1 -1
- package/src/hooks/__tests__/use-cached-effect.test.js +11 -14
- package/src/hooks/__tests__/use-gql-router-context.test.js +2 -2
- package/src/hooks/__tests__/use-gql.test.js +3 -3
- package/src/hooks/__tests__/use-hydratable-effect.test.js +10 -17
- package/src/hooks/__tests__/use-request-interception.test.js +2 -2
- package/src/hooks/__tests__/use-server-effect.test.js +8 -8
- package/src/hooks/__tests__/use-shared-cache.test.js +1 -1
- package/src/hooks/use-cached-effect.js +8 -12
- package/src/hooks/use-gql-router-context.js +4 -4
- package/src/hooks/use-gql.js +4 -4
- package/src/hooks/use-hydratable-effect.js +14 -16
- package/src/hooks/use-request-interception.js +2 -2
- package/src/hooks/use-server-effect.js +5 -5
- package/src/hooks/use-shared-cache.js +3 -3
- package/src/index.js +24 -32
- package/src/util/__tests__/get-gql-data-from-response.test.js +1 -1
- package/src/util/__tests__/get-gql-request-id.test.js +1 -1
- package/src/util/__tests__/graphql-document-node-parser.test.js +1 -1
- package/src/util/__tests__/hydration-cache-api.test.js +2 -2
- package/src/util/__tests__/merge-gql-context.test.js +1 -1
- package/src/util/__tests__/purge-caches.test.js +3 -3
- package/src/util/__tests__/request-api.test.js +3 -3
- package/src/util/__tests__/request-fulfillment.test.js +2 -2
- package/src/util/__tests__/request-tracking.test.js +2 -2
- package/src/util/__tests__/result-from-cache-response.test.js +1 -1
- package/src/util/__tests__/scoped-in-memory-cache.test.js +1 -1
- package/src/util/__tests__/serializable-in-memory-cache.test.js +1 -1
- package/src/util/__tests__/ssr-cache.test.js +2 -2
- package/src/util/__tests__/to-gql-operation.test.js +3 -3
- package/src/util/data-error.js +1 -1
- package/src/util/get-gql-data-from-response.js +2 -2
- package/src/util/get-gql-request-id.js +1 -1
- package/src/util/gql-error.js +1 -1
- package/src/util/gql-router-context.js +1 -1
- package/src/util/graphql-document-node-parser.js +2 -2
- package/src/util/hydration-cache-api.js +2 -2
- package/src/util/merge-gql-context.js +1 -1
- package/src/util/purge-caches.js +2 -2
- package/src/util/request-api.js +4 -4
- package/src/util/request-fulfillment.js +2 -2
- package/src/util/request-tracking.js +3 -3
- package/src/util/result-from-cache-response.js +3 -3
- package/src/util/scoped-in-memory-cache.js +2 -2
- package/src/util/serializable-in-memory-cache.js +3 -3
- package/src/util/ssr-cache.js +2 -2
- package/src/util/status.js +1 -1
- package/src/util/to-gql-operation.js +3 -3
- package/src/util/types.js +7 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @khanacademy/wonder-blocks-data
|
|
2
2
|
|
|
3
|
+
## 10.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 91cb727c: Convert enums to POJOs
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 91cb727c: Update wonder-stuff dependencies
|
|
12
|
+
- 91cb727c: Remove file extensions from imports
|
|
13
|
+
- Updated dependencies [91cb727c]
|
|
14
|
+
- Updated dependencies [91cb727c]
|
|
15
|
+
- @khanacademy/wonder-blocks-core@4.7.0
|
|
16
|
+
|
|
3
17
|
## 10.0.5
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/dist/es/index.js
CHANGED
|
@@ -4,7 +4,12 @@ import _extends from '@babel/runtime/helpers/extends';
|
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import { useContext, useRef, useMemo, useCallback } from 'react';
|
|
6
6
|
|
|
7
|
-
const FetchPolicy =
|
|
7
|
+
const FetchPolicy = {
|
|
8
|
+
CacheBeforeNetwork: "CacheBeforeNetwork",
|
|
9
|
+
CacheAndNetwork: "CacheAndNetwork",
|
|
10
|
+
CacheOnly: "CacheOnly",
|
|
11
|
+
NetworkOnly: "NetworkOnly"
|
|
12
|
+
};
|
|
8
13
|
|
|
9
14
|
const DataErrors = Object.freeze({
|
|
10
15
|
Unknown: "Unknown",
|
|
@@ -616,7 +621,12 @@ const useCachedEffect = (requestId, handler, options = {}) => {
|
|
|
616
621
|
return [result, fetchRequest];
|
|
617
622
|
};
|
|
618
623
|
|
|
619
|
-
const WhenClientSide =
|
|
624
|
+
const WhenClientSide = {
|
|
625
|
+
DoNotHydrate: "DoNotHydrate",
|
|
626
|
+
ExecuteWhenNoResult: "ExecuteWhenNoResult",
|
|
627
|
+
ExecuteWhenNoSuccessResult: "ExecuteWhenNoSuccessResult",
|
|
628
|
+
AlwaysExecute: "AlwaysExecute"
|
|
629
|
+
};
|
|
620
630
|
const DefaultScope = "useHydratableEffect";
|
|
621
631
|
const useHydratableEffect = (requestId, handler, options = {}) => {
|
|
622
632
|
const {
|
package/dist/index.js
CHANGED
|
@@ -30,7 +30,12 @@ function _interopNamespace(e) {
|
|
|
30
30
|
var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
|
|
31
31
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
32
32
|
|
|
33
|
-
const FetchPolicy =
|
|
33
|
+
const FetchPolicy = {
|
|
34
|
+
CacheBeforeNetwork: "CacheBeforeNetwork",
|
|
35
|
+
CacheAndNetwork: "CacheAndNetwork",
|
|
36
|
+
CacheOnly: "CacheOnly",
|
|
37
|
+
NetworkOnly: "NetworkOnly"
|
|
38
|
+
};
|
|
34
39
|
|
|
35
40
|
const DataErrors = Object.freeze({
|
|
36
41
|
Unknown: "Unknown",
|
|
@@ -642,7 +647,12 @@ const useCachedEffect = (requestId, handler, options = {}) => {
|
|
|
642
647
|
return [result, fetchRequest];
|
|
643
648
|
};
|
|
644
649
|
|
|
645
|
-
const WhenClientSide =
|
|
650
|
+
const WhenClientSide = {
|
|
651
|
+
DoNotHydrate: "DoNotHydrate",
|
|
652
|
+
ExecuteWhenNoResult: "ExecuteWhenNoResult",
|
|
653
|
+
ExecuteWhenNoSuccessResult: "ExecuteWhenNoSuccessResult",
|
|
654
|
+
AlwaysExecute: "AlwaysExecute"
|
|
655
|
+
};
|
|
646
656
|
const DefaultScope = "useHydratableEffect";
|
|
647
657
|
const useHydratableEffect = (requestId, handler, options = {}) => {
|
|
648
658
|
const {
|
package/dist/index.js.flow
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @flow
|
|
2
|
-
export * from "../src/index
|
|
2
|
+
export * from "../src/index";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@khanacademy/wonder-blocks-data",
|
|
3
|
-
"version": "10.0
|
|
3
|
+
"version": "10.1.0",
|
|
4
4
|
"design": "v1",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -14,15 +14,15 @@
|
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@babel/runtime": "^7.18.6",
|
|
17
|
-
"@khanacademy/wonder-blocks-core": "^4.
|
|
17
|
+
"@khanacademy/wonder-blocks-core": "^4.7.0"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
|
-
"@khanacademy/wonder-stuff-core": "^1.2.
|
|
20
|
+
"@khanacademy/wonder-stuff-core": "^1.2.1",
|
|
21
21
|
"flow-enums-runtime": "^0.0.6",
|
|
22
22
|
"react": "16.14.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"wb-dev-build-settings": "^0.7.
|
|
25
|
+
"wb-dev-build-settings": "^0.7.1"
|
|
26
26
|
},
|
|
27
27
|
"author": "",
|
|
28
28
|
"license": "MIT"
|
|
@@ -7,20 +7,14 @@ import {render, act} from "@testing-library/react";
|
|
|
7
7
|
import * as ReactDOMServer from "react-dom/server";
|
|
8
8
|
import {Server, View} from "@khanacademy/wonder-blocks-core";
|
|
9
9
|
|
|
10
|
-
import {SharedCache} from "../../hooks/use-shared-cache
|
|
11
|
-
import TrackData from "../track-data
|
|
12
|
-
import {RequestFulfillment} from "../../util/request-fulfillment
|
|
13
|
-
import {SsrCache} from "../../util/ssr-cache
|
|
14
|
-
import {RequestTracker} from "../../util/request-tracking
|
|
15
|
-
import InterceptRequests from "../intercept-requests
|
|
16
|
-
import Data from "../data
|
|
17
|
-
import {
|
|
18
|
-
// TODO(somewhatabstract, FEI-4174): Update eslint-plugin-import when they
|
|
19
|
-
// have fixed:
|
|
20
|
-
// https://github.com/import-js/eslint-plugin-import/issues/2073
|
|
21
|
-
// eslint-disable-next-line import/named
|
|
22
|
-
WhenClientSide,
|
|
23
|
-
} from "../../hooks/use-hydratable-effect.js";
|
|
10
|
+
import {SharedCache} from "../../hooks/use-shared-cache";
|
|
11
|
+
import TrackData from "../track-data";
|
|
12
|
+
import {RequestFulfillment} from "../../util/request-fulfillment";
|
|
13
|
+
import {SsrCache} from "../../util/ssr-cache";
|
|
14
|
+
import {RequestTracker} from "../../util/request-tracking";
|
|
15
|
+
import InterceptRequests from "../intercept-requests";
|
|
16
|
+
import Data from "../data";
|
|
17
|
+
import {WhenClientSide} from "../../hooks/use-hydratable-effect";
|
|
24
18
|
|
|
25
19
|
describe("Data", () => {
|
|
26
20
|
beforeEach(() => {
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import {render} from "@testing-library/react";
|
|
4
4
|
|
|
5
|
-
import {GqlRouterContext} from "../../util/gql-router-context
|
|
6
|
-
import {GqlRouter} from "../gql-router
|
|
5
|
+
import {GqlRouterContext} from "../../util/gql-router-context";
|
|
6
|
+
import {GqlRouter} from "../gql-router";
|
|
7
7
|
|
|
8
8
|
describe("GqlRouter", () => {
|
|
9
9
|
it("should provide the GqlRouterContext as configured", async () => {
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import {render} from "@testing-library/react";
|
|
4
4
|
|
|
5
|
-
import InterceptContext from "../intercept-context
|
|
6
|
-
import InterceptRequests from "../intercept-requests
|
|
5
|
+
import InterceptContext from "../intercept-context";
|
|
6
|
+
import InterceptRequests from "../intercept-requests";
|
|
7
7
|
|
|
8
8
|
describe("InterceptRequests", () => {
|
|
9
9
|
afterEach(() => {
|
|
@@ -3,8 +3,8 @@ import * as React from "react";
|
|
|
3
3
|
import {Server} from "@khanacademy/wonder-blocks-core";
|
|
4
4
|
import {render, screen} from "@testing-library/react";
|
|
5
5
|
|
|
6
|
-
import TrackData from "../track-data
|
|
7
|
-
import {RequestTracker, TrackerContext} from "../../util/request-tracking
|
|
6
|
+
import TrackData from "../track-data";
|
|
7
|
+
import {RequestTracker, TrackerContext} from "../../util/request-tracking";
|
|
8
8
|
|
|
9
9
|
describe("TrackData", () => {
|
|
10
10
|
afterEach(() => {
|
package/src/components/data.js
CHANGED
|
@@ -3,14 +3,10 @@ import * as React from "react";
|
|
|
3
3
|
|
|
4
4
|
import {
|
|
5
5
|
useHydratableEffect,
|
|
6
|
-
// TODO(somewhatabstract, FEI-4174): Update eslint-plugin-import when they
|
|
7
|
-
// have fixed:
|
|
8
|
-
// https://github.com/import-js/eslint-plugin-import/issues/2073
|
|
9
|
-
// eslint-disable-next-line import/named
|
|
10
6
|
WhenClientSide,
|
|
11
|
-
} from "../hooks/use-hydratable-effect
|
|
7
|
+
} from "../hooks/use-hydratable-effect";
|
|
12
8
|
|
|
13
|
-
import type {Result, ValidCacheData} from "../util/types
|
|
9
|
+
import type {Result, ValidCacheData} from "../util/types";
|
|
14
10
|
|
|
15
11
|
type Props<
|
|
16
12
|
/**
|
|
@@ -41,7 +37,7 @@ type Props<
|
|
|
41
37
|
*
|
|
42
38
|
* Default is `OnClientRender.ExecuteWhenNoSuccessResult`.
|
|
43
39
|
*/
|
|
44
|
-
clientBehavior?: WhenClientSide
|
|
40
|
+
clientBehavior?: $Values<typeof WhenClientSide>,
|
|
45
41
|
|
|
46
42
|
/**
|
|
47
43
|
* When true, the children will be rendered with the existing result
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
|
|
4
|
-
import {GqlRouterContext} from "../util/gql-router-context
|
|
4
|
+
import {GqlRouterContext} from "../util/gql-router-context";
|
|
5
5
|
|
|
6
6
|
import type {
|
|
7
7
|
GqlContext,
|
|
8
8
|
GqlFetchFn,
|
|
9
9
|
GqlRouterConfiguration,
|
|
10
|
-
} from "../util/gql-types
|
|
10
|
+
} from "../util/gql-types";
|
|
11
11
|
|
|
12
12
|
type Props<TContext: GqlContext> = {|
|
|
13
13
|
/**
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
|
|
4
|
-
import InterceptContext from "./intercept-context
|
|
4
|
+
import InterceptContext from "./intercept-context";
|
|
5
5
|
|
|
6
|
-
import type {ValidCacheData} from "../util/types
|
|
6
|
+
import type {ValidCacheData} from "../util/types";
|
|
7
7
|
|
|
8
8
|
type Props<TData: ValidCacheData> = {|
|
|
9
9
|
/**
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import {Server} from "@khanacademy/wonder-blocks-core";
|
|
4
4
|
|
|
5
|
-
import {RequestTracker, TrackerContext} from "../util/request-tracking
|
|
5
|
+
import {RequestTracker, TrackerContext} from "../util/request-tracking";
|
|
6
6
|
|
|
7
7
|
type TrackDataProps = {|
|
|
8
8
|
children: React.Node,
|
|
@@ -6,27 +6,24 @@ import {
|
|
|
6
6
|
} from "@testing-library/react-hooks";
|
|
7
7
|
import {renderHook as serverRenderHook} from "@testing-library/react-hooks/server";
|
|
8
8
|
import {render, act as reactAct} from "@testing-library/react";
|
|
9
|
+
import {values} from "@khanacademy/wonder-stuff-core";
|
|
9
10
|
|
|
10
11
|
import {Server} from "@khanacademy/wonder-blocks-core";
|
|
11
|
-
import {Status} from "../../util/status
|
|
12
|
+
import {Status} from "../../util/status";
|
|
12
13
|
|
|
13
|
-
import {RequestFulfillment} from "../../util/request-fulfillment
|
|
14
|
-
import * as UseRequestInterception from "../use-request-interception
|
|
15
|
-
import * as UseSharedCache from "../use-shared-cache
|
|
14
|
+
import {RequestFulfillment} from "../../util/request-fulfillment";
|
|
15
|
+
import * as UseRequestInterception from "../use-request-interception";
|
|
16
|
+
import * as UseSharedCache from "../use-shared-cache";
|
|
16
17
|
|
|
17
|
-
import {useCachedEffect} from "../use-cached-effect
|
|
18
|
+
import {useCachedEffect} from "../use-cached-effect";
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
// have fixed:
|
|
21
|
-
// https://github.com/import-js/eslint-plugin-import/issues/2073
|
|
22
|
-
// eslint-disable-next-line import/named
|
|
23
|
-
import {FetchPolicy} from "../../util/types.js";
|
|
20
|
+
import {FetchPolicy} from "../../util/types";
|
|
24
21
|
|
|
25
|
-
jest.mock("../use-request-interception
|
|
26
|
-
jest.mock("../use-shared-cache
|
|
22
|
+
jest.mock("../use-request-interception");
|
|
23
|
+
jest.mock("../use-shared-cache");
|
|
27
24
|
|
|
28
|
-
const allPolicies = Array.from(FetchPolicy
|
|
29
|
-
const allPoliciesBut = (policy: FetchPolicy) =>
|
|
25
|
+
const allPolicies = Array.from(values(FetchPolicy));
|
|
26
|
+
const allPoliciesBut = (policy: $Values<typeof FetchPolicy>) =>
|
|
30
27
|
allPolicies.filter((p) => p !== policy);
|
|
31
28
|
|
|
32
29
|
describe("#useCachedEffect", () => {
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import {renderHook} from "@testing-library/react-hooks";
|
|
4
4
|
|
|
5
|
-
import {GqlRouterContext} from "../../util/gql-router-context
|
|
6
|
-
import {useGqlRouterContext} from "../use-gql-router-context
|
|
5
|
+
import {GqlRouterContext} from "../../util/gql-router-context";
|
|
6
|
+
import {useGqlRouterContext} from "../use-gql-router-context";
|
|
7
7
|
|
|
8
8
|
describe("#useGqlRouterContext", () => {
|
|
9
9
|
it("should throw if there is no GqlRouterContext", () => {
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import {renderHook} from "@testing-library/react-hooks";
|
|
4
4
|
|
|
5
|
-
import * as GetGqlDataFromResponse from "../../util/get-gql-data-from-response
|
|
6
|
-
import {GqlRouterContext} from "../../util/gql-router-context
|
|
7
|
-
import {useGql} from "../use-gql
|
|
5
|
+
import * as GetGqlDataFromResponse from "../../util/get-gql-data-from-response";
|
|
6
|
+
import {GqlRouterContext} from "../../util/gql-router-context";
|
|
7
|
+
import {useGql} from "../use-gql";
|
|
8
8
|
|
|
9
9
|
describe("#useGql", () => {
|
|
10
10
|
beforeEach(() => {
|
|
@@ -7,25 +7,18 @@ import {
|
|
|
7
7
|
import {renderHook as serverRenderHook} from "@testing-library/react-hooks/server";
|
|
8
8
|
|
|
9
9
|
import {Server} from "@khanacademy/wonder-blocks-core";
|
|
10
|
-
import {Status} from "../../util/status
|
|
10
|
+
import {Status} from "../../util/status";
|
|
11
11
|
|
|
12
|
-
import {RequestFulfillment} from "../../util/request-fulfillment
|
|
13
|
-
import * as UseRequestInterception from "../use-request-interception
|
|
14
|
-
import * as UseServerEffect from "../use-server-effect
|
|
15
|
-
import * as UseSharedCache from "../use-shared-cache
|
|
12
|
+
import {RequestFulfillment} from "../../util/request-fulfillment";
|
|
13
|
+
import * as UseRequestInterception from "../use-request-interception";
|
|
14
|
+
import * as UseServerEffect from "../use-server-effect";
|
|
15
|
+
import * as UseSharedCache from "../use-shared-cache";
|
|
16
16
|
|
|
17
|
-
import {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
// eslint-disable-next-line import/named
|
|
23
|
-
WhenClientSide,
|
|
24
|
-
} from "../use-hydratable-effect.js";
|
|
25
|
-
|
|
26
|
-
jest.mock("../use-request-interception.js");
|
|
27
|
-
jest.mock("../use-server-effect.js");
|
|
28
|
-
jest.mock("../use-shared-cache.js");
|
|
17
|
+
import {useHydratableEffect, WhenClientSide} from "../use-hydratable-effect";
|
|
18
|
+
|
|
19
|
+
jest.mock("../use-request-interception");
|
|
20
|
+
jest.mock("../use-server-effect");
|
|
21
|
+
jest.mock("../use-shared-cache");
|
|
29
22
|
|
|
30
23
|
describe("#useHydratableEffect", () => {
|
|
31
24
|
beforeEach(() => {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import {renderHook} from "@testing-library/react-hooks";
|
|
4
|
-
import InterceptRequests from "../../components/intercept-requests
|
|
5
|
-
import {useRequestInterception} from "../use-request-interception
|
|
4
|
+
import InterceptRequests from "../../components/intercept-requests";
|
|
5
|
+
import {useRequestInterception} from "../use-request-interception";
|
|
6
6
|
|
|
7
7
|
describe("#useRequestInterception", () => {
|
|
8
8
|
it("should return a function", () => {
|
|
@@ -4,16 +4,16 @@ import {renderHook as serverRenderHook} from "@testing-library/react-hooks/serve
|
|
|
4
4
|
|
|
5
5
|
import {Server} from "@khanacademy/wonder-blocks-core";
|
|
6
6
|
|
|
7
|
-
import TrackData from "../../components/track-data
|
|
8
|
-
import {RequestFulfillment} from "../../util/request-fulfillment
|
|
9
|
-
import {SsrCache} from "../../util/ssr-cache
|
|
10
|
-
import {RequestTracker} from "../../util/request-tracking
|
|
11
|
-
import {DataError} from "../../util/data-error
|
|
12
|
-
import * as UseRequestInterception from "../use-request-interception
|
|
7
|
+
import TrackData from "../../components/track-data";
|
|
8
|
+
import {RequestFulfillment} from "../../util/request-fulfillment";
|
|
9
|
+
import {SsrCache} from "../../util/ssr-cache";
|
|
10
|
+
import {RequestTracker} from "../../util/request-tracking";
|
|
11
|
+
import {DataError} from "../../util/data-error";
|
|
12
|
+
import * as UseRequestInterception from "../use-request-interception";
|
|
13
13
|
|
|
14
|
-
import {useServerEffect} from "../use-server-effect
|
|
14
|
+
import {useServerEffect} from "../use-server-effect";
|
|
15
15
|
|
|
16
|
-
jest.mock("../use-request-interception
|
|
16
|
+
jest.mock("../use-request-interception");
|
|
17
17
|
|
|
18
18
|
describe("#useServerEffect", () => {
|
|
19
19
|
beforeEach(() => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import {renderHook as clientRenderHook} from "@testing-library/react-hooks";
|
|
3
3
|
|
|
4
|
-
import {useSharedCache, SharedCache} from "../use-shared-cache
|
|
4
|
+
import {useSharedCache, SharedCache} from "../use-shared-cache";
|
|
5
5
|
|
|
6
6
|
describe("#useSharedCache", () => {
|
|
7
7
|
beforeEach(() => {
|
|
@@ -1,21 +1,17 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import {useForceUpdate} from "@khanacademy/wonder-blocks-core";
|
|
4
|
-
import {DataError, DataErrors} from "../util/data-error
|
|
4
|
+
import {DataError, DataErrors} from "../util/data-error";
|
|
5
5
|
|
|
6
|
-
import {RequestFulfillment} from "../util/request-fulfillment
|
|
7
|
-
import {Status} from "../util/status
|
|
6
|
+
import {RequestFulfillment} from "../util/request-fulfillment";
|
|
7
|
+
import {Status} from "../util/status";
|
|
8
8
|
|
|
9
|
-
import {useSharedCache} from "./use-shared-cache
|
|
10
|
-
import {useRequestInterception} from "./use-request-interception
|
|
9
|
+
import {useSharedCache} from "./use-shared-cache";
|
|
10
|
+
import {useRequestInterception} from "./use-request-interception";
|
|
11
11
|
|
|
12
|
-
import type {Result, ValidCacheData} from "../util/types
|
|
12
|
+
import type {Result, ValidCacheData} from "../util/types";
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
// have fixed:
|
|
16
|
-
// https://github.com/import-js/eslint-plugin-import/issues/2073
|
|
17
|
-
// eslint-disable-next-line import/named
|
|
18
|
-
import {FetchPolicy} from "../util/types.js";
|
|
14
|
+
import {FetchPolicy} from "../util/types";
|
|
19
15
|
|
|
20
16
|
type CachedEffectOptions<TData: ValidCacheData> = {|
|
|
21
17
|
/**
|
|
@@ -24,7 +20,7 @@ type CachedEffectOptions<TData: ValidCacheData> = {|
|
|
|
24
20
|
*
|
|
25
21
|
* Defaults to `FetchPolicy.CacheBeforeNetwork`.
|
|
26
22
|
*/
|
|
27
|
-
fetchPolicy?: FetchPolicy
|
|
23
|
+
fetchPolicy?: $Values<typeof FetchPolicy>,
|
|
28
24
|
|
|
29
25
|
/**
|
|
30
26
|
* When `true`, the effect will not be executed; otherwise, the effect will
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import {useContext, useRef, useMemo} from "react";
|
|
3
3
|
|
|
4
|
-
import {mergeGqlContext} from "../util/merge-gql-context
|
|
5
|
-
import {GqlRouterContext} from "../util/gql-router-context
|
|
6
|
-
import {GqlError, GqlErrors} from "../util/gql-error
|
|
4
|
+
import {mergeGqlContext} from "../util/merge-gql-context";
|
|
5
|
+
import {GqlRouterContext} from "../util/gql-router-context";
|
|
6
|
+
import {GqlError, GqlErrors} from "../util/gql-error";
|
|
7
7
|
|
|
8
|
-
import type {GqlRouterConfiguration, GqlContext} from "../util/gql-types
|
|
8
|
+
import type {GqlRouterConfiguration, GqlContext} from "../util/gql-types";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Construct a GqlRouterContext from the current one and partial context.
|
package/src/hooks/use-gql.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import {useCallback} from "react";
|
|
3
3
|
|
|
4
|
-
import {mergeGqlContext} from "../util/merge-gql-context
|
|
5
|
-
import {useGqlRouterContext} from "./use-gql-router-context
|
|
6
|
-
import {getGqlDataFromResponse} from "../util/get-gql-data-from-response
|
|
4
|
+
import {mergeGqlContext} from "../util/merge-gql-context";
|
|
5
|
+
import {useGqlRouterContext} from "./use-gql-router-context";
|
|
6
|
+
import {getGqlDataFromResponse} from "../util/get-gql-data-from-response";
|
|
7
7
|
|
|
8
8
|
import type {
|
|
9
9
|
GqlContext,
|
|
10
10
|
GqlOperation,
|
|
11
11
|
GqlFetchOptions,
|
|
12
|
-
} from "../util/gql-types
|
|
12
|
+
} from "../util/gql-types";
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Hook to obtain a gqlFetch function for performing GraphQL requests.
|
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
|
|
4
|
-
import {useServerEffect} from "./use-server-effect
|
|
5
|
-
import {useSharedCache} from "./use-shared-cache
|
|
6
|
-
import {useCachedEffect} from "./use-cached-effect
|
|
4
|
+
import {useServerEffect} from "./use-server-effect";
|
|
5
|
+
import {useSharedCache} from "./use-shared-cache";
|
|
6
|
+
import {useCachedEffect} from "./use-cached-effect";
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
// https://github.com/import-js/eslint-plugin-import/issues/2073
|
|
11
|
-
// eslint-disable-next-line import/named
|
|
12
|
-
import {FetchPolicy} from "../util/types.js";
|
|
13
|
-
import type {Result, ValidCacheData} from "../util/types.js";
|
|
8
|
+
import {FetchPolicy} from "../util/types";
|
|
9
|
+
import type {Result, ValidCacheData} from "../util/types";
|
|
14
10
|
|
|
15
11
|
/**
|
|
16
12
|
* Policies to define how a hydratable effect should behave client-side.
|
|
17
13
|
*/
|
|
18
|
-
|
|
14
|
+
// TODO(FEI-5000): Convert to TS enum after all codebases have been migrated
|
|
15
|
+
export const WhenClientSide = {
|
|
19
16
|
/**
|
|
20
17
|
* The result from executing the effect server-side will not be hydrated.
|
|
21
18
|
* The effect will always be executed client-side.
|
|
@@ -24,7 +21,7 @@ export enum WhenClientSide {
|
|
|
24
21
|
* for properly hydrating this component (for example, the action invokes
|
|
25
22
|
* Apollo which manages its own cache to ensure things render properly).
|
|
26
23
|
*/
|
|
27
|
-
DoNotHydrate,
|
|
24
|
+
DoNotHydrate: ("DoNotHydrate": "DoNotHydrate"),
|
|
28
25
|
|
|
29
26
|
/**
|
|
30
27
|
* The result from executing the effect server-side will be hydrated.
|
|
@@ -32,7 +29,7 @@ export enum WhenClientSide {
|
|
|
32
29
|
* be hydrated (i.e. both error and success hydration results prevent the
|
|
33
30
|
* effect running client-side).
|
|
34
31
|
*/
|
|
35
|
-
ExecuteWhenNoResult,
|
|
32
|
+
ExecuteWhenNoResult: ("ExecuteWhenNoResult": "ExecuteWhenNoResult"),
|
|
36
33
|
|
|
37
34
|
/**
|
|
38
35
|
* The result from executing the effect server-side will be hydrated.
|
|
@@ -41,15 +38,16 @@ export enum WhenClientSide {
|
|
|
41
38
|
* If the hydrated result was not a success result, or there was no
|
|
42
39
|
* hydrated result, the effect will not be executed.
|
|
43
40
|
*/
|
|
44
|
-
ExecuteWhenNoSuccessResult
|
|
41
|
+
ExecuteWhenNoSuccessResult:
|
|
42
|
+
("ExecuteWhenNoSuccessResult": "ExecuteWhenNoSuccessResult"),
|
|
45
43
|
|
|
46
44
|
/**
|
|
47
45
|
* The result from executing the effect server-side will be hydrated.
|
|
48
46
|
* The effect will always be executed client-side, regardless of the
|
|
49
47
|
* hydrated result status.
|
|
50
48
|
*/
|
|
51
|
-
AlwaysExecute,
|
|
52
|
-
}
|
|
49
|
+
AlwaysExecute: ("AlwaysExecute": "AlwaysExecute"),
|
|
50
|
+
};
|
|
53
51
|
|
|
54
52
|
type HydratableEffectOptions<TData: ValidCacheData> = {|
|
|
55
53
|
/**
|
|
@@ -62,7 +60,7 @@ type HydratableEffectOptions<TData: ValidCacheData> = {|
|
|
|
62
60
|
* Changing this value after the first call is irrelevant as it only
|
|
63
61
|
* affects the initial render behavior.
|
|
64
62
|
*/
|
|
65
|
-
clientBehavior?: WhenClientSide
|
|
63
|
+
clientBehavior?: $Values<typeof WhenClientSide>,
|
|
66
64
|
|
|
67
65
|
/**
|
|
68
66
|
* When `true`, the effect will not be executed; otherwise, the effect will
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
|
|
4
|
-
import InterceptContext from "../components/intercept-context
|
|
5
|
-
import type {ValidCacheData} from "../util/types
|
|
4
|
+
import InterceptContext from "../components/intercept-context";
|
|
5
|
+
import type {ValidCacheData} from "../util/types";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Allow request handling to be intercepted.
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import {Server} from "@khanacademy/wonder-blocks-core";
|
|
3
3
|
import {useContext} from "react";
|
|
4
|
-
import {TrackerContext} from "../util/request-tracking
|
|
5
|
-
import {SsrCache} from "../util/ssr-cache
|
|
6
|
-
import {resultFromCachedResponse} from "../util/result-from-cache-response
|
|
7
|
-
import {useRequestInterception} from "./use-request-interception
|
|
4
|
+
import {TrackerContext} from "../util/request-tracking";
|
|
5
|
+
import {SsrCache} from "../util/ssr-cache";
|
|
6
|
+
import {resultFromCachedResponse} from "../util/result-from-cache-response";
|
|
7
|
+
import {useRequestInterception} from "./use-request-interception";
|
|
8
8
|
|
|
9
|
-
import type {Result, ValidCacheData} from "../util/types
|
|
9
|
+
import type {Result, ValidCacheData} from "../util/types";
|
|
10
10
|
|
|
11
11
|
type ServerEffectOptions = {|
|
|
12
12
|
/**
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import * as React from "react";
|
|
3
|
-
import {DataError, DataErrors} from "../util/data-error
|
|
4
|
-
import {ScopedInMemoryCache} from "../util/scoped-in-memory-cache
|
|
5
|
-
import type {ValidCacheData, ScopedCache} from "../util/types
|
|
3
|
+
import {DataError, DataErrors} from "../util/data-error";
|
|
4
|
+
import {ScopedInMemoryCache} from "../util/scoped-in-memory-cache";
|
|
5
|
+
import type {ValidCacheData, ScopedCache} from "../util/types";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* A function for inserting a value into the cache or clearing it.
|
package/src/index.js
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
// @flow
|
|
2
|
-
|
|
3
|
-
// have fixed:
|
|
4
|
-
// https://github.com/import-js/eslint-plugin-import/issues/2073
|
|
5
|
-
// eslint-disable-next-line import/named
|
|
6
|
-
export {FetchPolicy} from "./util/types.js";
|
|
2
|
+
export {FetchPolicy} from "./util/types";
|
|
7
3
|
export type {
|
|
8
4
|
ErrorOptions,
|
|
9
5
|
ResponseCache,
|
|
@@ -12,44 +8,40 @@ export type {
|
|
|
12
8
|
RawScopedCache,
|
|
13
9
|
ValidCacheData,
|
|
14
10
|
ScopedCache,
|
|
15
|
-
} from "./util/types
|
|
11
|
+
} from "./util/types";
|
|
16
12
|
|
|
17
|
-
export * from "./util/hydration-cache-api
|
|
18
|
-
export * from "./util/request-api
|
|
19
|
-
export {purgeCaches} from "./util/purge-caches
|
|
20
|
-
export {default as TrackData} from "./components/track-data
|
|
21
|
-
export {default as Data} from "./components/data
|
|
22
|
-
export {default as InterceptRequests} from "./components/intercept-requests
|
|
23
|
-
export {DataError, DataErrors} from "./util/data-error
|
|
24
|
-
export {useServerEffect} from "./hooks/use-server-effect
|
|
25
|
-
export {useCachedEffect} from "./hooks/use-cached-effect
|
|
26
|
-
export {useSharedCache, SharedCache} from "./hooks/use-shared-cache
|
|
13
|
+
export * from "./util/hydration-cache-api";
|
|
14
|
+
export * from "./util/request-api";
|
|
15
|
+
export {purgeCaches} from "./util/purge-caches";
|
|
16
|
+
export {default as TrackData} from "./components/track-data";
|
|
17
|
+
export {default as Data} from "./components/data";
|
|
18
|
+
export {default as InterceptRequests} from "./components/intercept-requests";
|
|
19
|
+
export {DataError, DataErrors} from "./util/data-error";
|
|
20
|
+
export {useServerEffect} from "./hooks/use-server-effect";
|
|
21
|
+
export {useCachedEffect} from "./hooks/use-cached-effect";
|
|
22
|
+
export {useSharedCache, SharedCache} from "./hooks/use-shared-cache";
|
|
27
23
|
export {
|
|
28
24
|
useHydratableEffect,
|
|
29
|
-
// TODO(somewhatabstract, FEI-4174): Update eslint-plugin-import when they
|
|
30
|
-
// have fixed:
|
|
31
|
-
// https://github.com/import-js/eslint-plugin-import/issues/2073
|
|
32
|
-
// eslint-disable-next-line import/named
|
|
33
25
|
WhenClientSide,
|
|
34
|
-
} from "./hooks/use-hydratable-effect
|
|
35
|
-
export {ScopedInMemoryCache} from "./util/scoped-in-memory-cache
|
|
36
|
-
export {SerializableInMemoryCache} from "./util/serializable-in-memory-cache
|
|
37
|
-
export {Status} from "./util/status
|
|
26
|
+
} from "./hooks/use-hydratable-effect";
|
|
27
|
+
export {ScopedInMemoryCache} from "./util/scoped-in-memory-cache";
|
|
28
|
+
export {SerializableInMemoryCache} from "./util/serializable-in-memory-cache";
|
|
29
|
+
export {Status} from "./util/status";
|
|
38
30
|
|
|
39
31
|
////////////////////////////////////////////////////////////////////////////////
|
|
40
32
|
// GraphQL
|
|
41
33
|
////////////////////////////////////////////////////////////////////////////////
|
|
42
|
-
export {getGqlRequestId} from "./util/get-gql-request-id
|
|
43
|
-
export {getGqlDataFromResponse} from "./util/get-gql-data-from-response
|
|
44
|
-
export {graphQLDocumentNodeParser} from "./util/graphql-document-node-parser
|
|
45
|
-
export {toGqlOperation} from "./util/to-gql-operation
|
|
46
|
-
export {GqlRouter} from "./components/gql-router
|
|
47
|
-
export {useGql} from "./hooks/use-gql
|
|
48
|
-
export {GqlError, GqlErrors} from "./util/gql-error
|
|
34
|
+
export {getGqlRequestId} from "./util/get-gql-request-id";
|
|
35
|
+
export {getGqlDataFromResponse} from "./util/get-gql-data-from-response";
|
|
36
|
+
export {graphQLDocumentNodeParser} from "./util/graphql-document-node-parser";
|
|
37
|
+
export {toGqlOperation} from "./util/to-gql-operation";
|
|
38
|
+
export {GqlRouter} from "./components/gql-router";
|
|
39
|
+
export {useGql} from "./hooks/use-gql";
|
|
40
|
+
export {GqlError, GqlErrors} from "./util/gql-error";
|
|
49
41
|
export type {
|
|
50
42
|
GqlContext,
|
|
51
43
|
GqlOperation,
|
|
52
44
|
GqlOperationType,
|
|
53
45
|
GqlFetchOptions,
|
|
54
46
|
GqlFetchFn,
|
|
55
|
-
} from "./util/gql-types
|
|
47
|
+
} from "./util/gql-types";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @flow
|
|
2
|
-
import {getGqlDataFromResponse} from "../get-gql-data-from-response
|
|
2
|
+
import {getGqlDataFromResponse} from "../get-gql-data-from-response";
|
|
3
3
|
|
|
4
4
|
describe("#getGqlDataFromReponse", () => {
|
|
5
5
|
it("should throw if the response cannot be parsed", async () => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @flow
|
|
2
|
-
import {graphQLDocumentNodeParser} from "../graphql-document-node-parser
|
|
2
|
+
import {graphQLDocumentNodeParser} from "../graphql-document-node-parser";
|
|
3
3
|
|
|
4
4
|
describe("#graphQLDocumentNodeParser", () => {
|
|
5
5
|
describe("in production - shorter error messages", () => {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// @flow
|
|
2
|
-
import {SsrCache} from "../ssr-cache
|
|
2
|
+
import {SsrCache} from "../ssr-cache";
|
|
3
3
|
|
|
4
4
|
import {
|
|
5
5
|
initializeHydrationCache,
|
|
6
6
|
purgeHydrationCache,
|
|
7
|
-
} from "../hydration-cache-api
|
|
7
|
+
} from "../hydration-cache-api";
|
|
8
8
|
|
|
9
9
|
describe("#initializeHydrationCache", () => {
|
|
10
10
|
it("should call SsrCache.Default.initialize", () => {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// @flow
|
|
2
|
-
import {SharedCache} from "../../hooks/use-shared-cache
|
|
3
|
-
import * as HydrationCacheApi from "../hydration-cache-api
|
|
2
|
+
import {SharedCache} from "../../hooks/use-shared-cache";
|
|
3
|
+
import * as HydrationCacheApi from "../hydration-cache-api";
|
|
4
4
|
|
|
5
|
-
import {purgeCaches} from "../purge-caches
|
|
5
|
+
import {purgeCaches} from "../purge-caches";
|
|
6
6
|
|
|
7
7
|
describe("#purgeCaches", () => {
|
|
8
8
|
it("should purge the shared cache", () => {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import {Server} from "@khanacademy/wonder-blocks-core";
|
|
3
|
-
import {RequestFulfillment} from "../request-fulfillment
|
|
4
|
-
import {RequestTracker} from "../request-tracking
|
|
3
|
+
import {RequestFulfillment} from "../request-fulfillment";
|
|
4
|
+
import {RequestTracker} from "../request-tracking";
|
|
5
5
|
|
|
6
6
|
import {
|
|
7
7
|
abortInflightRequests,
|
|
8
8
|
fetchTrackedRequests,
|
|
9
9
|
hasTrackedRequestsToBeFetched,
|
|
10
|
-
} from "../request-api
|
|
10
|
+
} from "../request-api";
|
|
11
11
|
|
|
12
12
|
describe("#fetchTrackedRequests", () => {
|
|
13
13
|
describe("when server-side", () => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @flow
|
|
2
|
-
import {RequestFulfillment} from "../request-fulfillment
|
|
3
|
-
import {DataError} from "../data-error
|
|
2
|
+
import {RequestFulfillment} from "../request-fulfillment";
|
|
3
|
+
import {DataError} from "../data-error";
|
|
4
4
|
|
|
5
5
|
describe("RequestFulfillment", () => {
|
|
6
6
|
it("should provide static default instance", () => {
|
|
@@ -3,8 +3,8 @@ import * as React from "react";
|
|
|
3
3
|
import {render} from "@testing-library/react";
|
|
4
4
|
|
|
5
5
|
import {Server} from "@khanacademy/wonder-blocks-core";
|
|
6
|
-
import {RequestTracker, TrackerContext} from "../request-tracking
|
|
7
|
-
import {SsrCache} from "../ssr-cache
|
|
6
|
+
import {RequestTracker, TrackerContext} from "../request-tracking";
|
|
7
|
+
import {SsrCache} from "../ssr-cache";
|
|
8
8
|
|
|
9
9
|
describe("../request-tracking.js", () => {
|
|
10
10
|
describe("TrackerContext", () => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import * as WSCore from "@khanacademy/wonder-stuff-core";
|
|
3
|
-
import {SerializableInMemoryCache} from "../serializable-in-memory-cache
|
|
3
|
+
import {SerializableInMemoryCache} from "../serializable-in-memory-cache";
|
|
4
4
|
|
|
5
5
|
describe("SerializableInMemoryCache", () => {
|
|
6
6
|
describe("#constructor", () => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import {Server} from "@khanacademy/wonder-blocks-core";
|
|
3
|
-
import {SsrCache} from "../ssr-cache
|
|
4
|
-
import {SerializableInMemoryCache} from "../serializable-in-memory-cache
|
|
3
|
+
import {SsrCache} from "../ssr-cache";
|
|
4
|
+
import {SerializableInMemoryCache} from "../serializable-in-memory-cache";
|
|
5
5
|
|
|
6
6
|
describe("../ssr-cache.js", () => {
|
|
7
7
|
afterEach(() => {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// @flow
|
|
2
|
-
import {toGqlOperation} from "../to-gql-operation
|
|
3
|
-
import * as GDNP from "../graphql-document-node-parser
|
|
2
|
+
import {toGqlOperation} from "../to-gql-operation";
|
|
3
|
+
import * as GDNP from "../graphql-document-node-parser";
|
|
4
4
|
|
|
5
|
-
jest.mock("../graphql-document-node-parser
|
|
5
|
+
jest.mock("../graphql-document-node-parser");
|
|
6
6
|
|
|
7
7
|
describe("#toGqlOperation", () => {
|
|
8
8
|
it("should parse the document node", () => {
|
package/src/util/data-error.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @flow
|
|
2
|
-
import {DataError, DataErrors} from "./data-error
|
|
3
|
-
import {GqlError, GqlErrors} from "./gql-error
|
|
2
|
+
import {DataError, DataErrors} from "./data-error";
|
|
3
|
+
import {GqlError, GqlErrors} from "./gql-error";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Validate a GQL operation response and extract the data.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import {entries} from "@khanacademy/wonder-stuff-core";
|
|
3
|
-
import type {GqlOperation, GqlContext} from "./gql-types
|
|
3
|
+
import type {GqlOperation, GqlContext} from "./gql-types";
|
|
4
4
|
|
|
5
5
|
const toString = (value: mixed): string => {
|
|
6
6
|
if (typeof value === "string") {
|
package/src/util/gql-error.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import * as React from "react";
|
|
3
|
-
import type {GqlRouterConfiguration} from "./gql-types
|
|
3
|
+
import type {GqlRouterConfiguration} from "./gql-types";
|
|
4
4
|
|
|
5
5
|
export const GqlRouterContext: React.Context<?GqlRouterConfiguration<any>> =
|
|
6
6
|
React.createContext<?GqlRouterConfiguration<any>>(null);
|
|
@@ -4,8 +4,8 @@ import type {
|
|
|
4
4
|
DefinitionNode,
|
|
5
5
|
VariableDefinitionNode,
|
|
6
6
|
OperationDefinitionNode,
|
|
7
|
-
} from "./graphql-types
|
|
8
|
-
import {DataError, DataErrors} from "./data-error
|
|
7
|
+
} from "./graphql-types";
|
|
8
|
+
import {DataError, DataErrors} from "./data-error";
|
|
9
9
|
|
|
10
10
|
export const DocumentTypes = Object.freeze({
|
|
11
11
|
query: "query",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// @flow
|
|
2
|
-
import {SsrCache} from "./ssr-cache
|
|
2
|
+
import {SsrCache} from "./ssr-cache";
|
|
3
3
|
|
|
4
|
-
import type {ValidCacheData, CachedResponse, ResponseCache} from "./types
|
|
4
|
+
import type {ValidCacheData, CachedResponse, ResponseCache} from "./types";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Initialize the hydration cache.
|
package/src/util/purge-caches.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @flow
|
|
2
|
-
import {SharedCache} from "../hooks/use-shared-cache
|
|
3
|
-
import {purgeHydrationCache} from "./hydration-cache-api
|
|
2
|
+
import {SharedCache} from "../hooks/use-shared-cache";
|
|
3
|
+
import {purgeHydrationCache} from "./hydration-cache-api";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Purge all caches managed by Wonder Blocks Data.
|
package/src/util/request-api.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import {Server} from "@khanacademy/wonder-blocks-core";
|
|
3
|
-
import {RequestTracker} from "./request-tracking
|
|
4
|
-
import {RequestFulfillment} from "./request-fulfillment
|
|
5
|
-
import {DataError, DataErrors} from "./data-error
|
|
3
|
+
import {RequestTracker} from "./request-tracking";
|
|
4
|
+
import {RequestFulfillment} from "./request-fulfillment";
|
|
5
|
+
import {DataError, DataErrors} from "./data-error";
|
|
6
6
|
|
|
7
|
-
import type {ResponseCache} from "./types
|
|
7
|
+
import type {ResponseCache} from "./types";
|
|
8
8
|
|
|
9
9
|
const SSRCheck = () => {
|
|
10
10
|
if (Server.isServerSide()) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// @flow
|
|
2
|
-
import type {Result, ValidCacheData} from "./types
|
|
2
|
+
import type {Result, ValidCacheData} from "./types";
|
|
3
3
|
|
|
4
|
-
import {DataError, DataErrors} from "./data-error
|
|
4
|
+
import {DataError, DataErrors} from "./data-error";
|
|
5
5
|
|
|
6
6
|
type RequestCache = {
|
|
7
7
|
[id: string]: Promise<Result<any>>,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import * as React from "react";
|
|
3
|
-
import {SsrCache} from "./ssr-cache
|
|
4
|
-
import {RequestFulfillment} from "./request-fulfillment
|
|
3
|
+
import {SsrCache} from "./ssr-cache";
|
|
4
|
+
import {RequestFulfillment} from "./request-fulfillment";
|
|
5
5
|
|
|
6
|
-
import type {ResponseCache, ValidCacheData} from "./types
|
|
6
|
+
import type {ResponseCache, ValidCacheData} from "./types";
|
|
7
7
|
|
|
8
8
|
type TrackerFn = <TData: ValidCacheData>(
|
|
9
9
|
id: string,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// @flow
|
|
2
|
-
import {Status} from "./status
|
|
3
|
-
import {DataError, DataErrors} from "./data-error
|
|
4
|
-
import type {ValidCacheData, CachedResponse, Result} from "./types
|
|
2
|
+
import {Status} from "./status";
|
|
3
|
+
import {DataError, DataErrors} from "./data-error";
|
|
4
|
+
import type {ValidCacheData, CachedResponse, Result} from "./types";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Turns a cache entry into a stateful result.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @flow
|
|
2
|
-
import {DataError, DataErrors} from "./data-error
|
|
3
|
-
import type {ScopedCache, RawScopedCache, ValidCacheData} from "./types
|
|
2
|
+
import {DataError, DataErrors} from "./data-error";
|
|
3
|
+
import type {ScopedCache, RawScopedCache, ValidCacheData} from "./types";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Describe an in-memory cache.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import {clone} from "@khanacademy/wonder-stuff-core";
|
|
3
|
-
import {DataError, DataErrors} from "./data-error
|
|
4
|
-
import {ScopedInMemoryCache} from "./scoped-in-memory-cache
|
|
5
|
-
import type {ValidCacheData, RawScopedCache} from "./types
|
|
3
|
+
import {DataError, DataErrors} from "./data-error";
|
|
4
|
+
import {ScopedInMemoryCache} from "./scoped-in-memory-cache";
|
|
5
|
+
import type {ValidCacheData, RawScopedCache} from "./types";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Describe a serializable in-memory cache.
|
package/src/util/ssr-cache.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import {Server} from "@khanacademy/wonder-blocks-core";
|
|
3
|
-
import {SerializableInMemoryCache} from "./serializable-in-memory-cache
|
|
3
|
+
import {SerializableInMemoryCache} from "./serializable-in-memory-cache";
|
|
4
4
|
|
|
5
|
-
import type {ValidCacheData, CachedResponse, ResponseCache} from "./types
|
|
5
|
+
import type {ValidCacheData, CachedResponse, ResponseCache} from "./types";
|
|
6
6
|
|
|
7
7
|
const DefaultScope = "default";
|
|
8
8
|
|
package/src/util/status.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// @flow
|
|
2
|
-
import {graphQLDocumentNodeParser} from "./graphql-document-node-parser
|
|
3
|
-
import type {GqlOperation} from "./gql-types
|
|
4
|
-
import type {DocumentNode} from "./graphql-types
|
|
2
|
+
import {graphQLDocumentNodeParser} from "./graphql-document-node-parser";
|
|
3
|
+
import type {GqlOperation} from "./gql-types";
|
|
4
|
+
import type {DocumentNode} from "./graphql-types";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Convert a GraphQL DocumentNode to a base Wonder Blocks Data GqlOperation.
|
package/src/util/types.js
CHANGED
|
@@ -4,29 +4,30 @@ import type {Metadata} from "@khanacademy/wonder-stuff-core";
|
|
|
4
4
|
/**
|
|
5
5
|
* Defines the various fetch policies that can be applied to requests.
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
// TODO(FEI-5000): Convert to TS enum after all codebases have been migrated
|
|
8
|
+
export const FetchPolicy = {
|
|
8
9
|
/**
|
|
9
10
|
* If the data is in the cache, return that; otherwise, fetch from the
|
|
10
11
|
* server.
|
|
11
12
|
*/
|
|
12
|
-
CacheBeforeNetwork,
|
|
13
|
+
CacheBeforeNetwork: ("CacheBeforeNetwork": "CacheBeforeNetwork"),
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* If the data is in the cache, return that; always fetch from the server
|
|
16
17
|
* regardless of cache.
|
|
17
18
|
*/
|
|
18
|
-
CacheAndNetwork,
|
|
19
|
+
CacheAndNetwork: ("CacheAndNetwork": "CacheAndNetwork"),
|
|
19
20
|
|
|
20
21
|
/**
|
|
21
22
|
* If the data is in the cache, return that; otherwise, do nothing.
|
|
22
23
|
*/
|
|
23
|
-
CacheOnly,
|
|
24
|
+
CacheOnly: ("CacheOnly": "CacheOnly"),
|
|
24
25
|
|
|
25
26
|
/**
|
|
26
27
|
* Ignore any existing cached result; always fetch from the server.
|
|
27
28
|
*/
|
|
28
|
-
NetworkOnly,
|
|
29
|
-
}
|
|
29
|
+
NetworkOnly: ("NetworkOnly": "NetworkOnly"),
|
|
30
|
+
};
|
|
30
31
|
|
|
31
32
|
/**
|
|
32
33
|
* Define what can be cached.
|