@khanacademy/wonder-blocks-data 10.1.0 → 10.1.2
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 +31 -0
- package/dist/components/data.d.ts +52 -0
- package/dist/components/data.js.flow +63 -0
- package/dist/components/gql-router.d.ts +24 -0
- package/dist/components/gql-router.js.flow +33 -0
- package/dist/components/intercept-context.d.ts +10 -0
- package/dist/components/intercept-context.js.flow +19 -0
- package/dist/components/intercept-requests.d.ts +42 -0
- package/dist/components/intercept-requests.js.flow +51 -0
- package/dist/components/track-data.d.ts +11 -0
- package/dist/components/track-data.js.flow +18 -0
- package/dist/es/index.js +184 -212
- package/dist/hooks/use-cached-effect.d.ts +70 -0
- package/dist/hooks/use-cached-effect.js.flow +85 -0
- package/dist/hooks/use-gql-router-context.d.ts +5 -0
- package/dist/hooks/use-gql-router-context.js.flow +15 -0
- package/dist/hooks/use-gql.d.ts +12 -0
- package/dist/hooks/use-gql.js.flow +29 -0
- package/dist/hooks/use-hydratable-effect.d.ts +102 -0
- package/dist/hooks/use-hydratable-effect.js.flow +125 -0
- package/dist/hooks/use-request-interception.d.ts +14 -0
- package/dist/hooks/use-request-interception.js.flow +25 -0
- package/dist/hooks/use-server-effect.d.ts +39 -0
- package/dist/hooks/use-server-effect.js.flow +51 -0
- package/dist/hooks/use-shared-cache.d.ts +32 -0
- package/dist/hooks/use-shared-cache.js.flow +43 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +186 -217
- package/dist/index.js.flow +48 -2
- package/dist/util/data-error.d.ts +45 -0
- package/dist/util/data-error.js.flow +64 -0
- package/dist/util/get-gql-data-from-response.d.ts +4 -0
- package/dist/util/get-gql-data-from-response.js.flow +13 -0
- package/dist/util/get-gql-request-id.d.ts +5 -0
- package/dist/util/get-gql-request-id.js.flow +20 -0
- package/dist/util/gql-error.d.ts +28 -0
- package/dist/util/gql-error.js.flow +43 -0
- package/dist/util/gql-router-context.d.ts +3 -0
- package/dist/util/gql-router-context.js.flow +10 -0
- package/dist/util/gql-types.d.ts +34 -0
- package/dist/util/gql-types.js.flow +53 -0
- package/dist/util/graphql-document-node-parser.d.ts +18 -0
- package/dist/util/graphql-document-node-parser.js.flow +31 -0
- package/dist/util/graphql-types.d.ts +19 -0
- package/dist/util/graphql-types.js.flow +30 -0
- package/dist/util/hydration-cache-api.d.ts +17 -0
- package/dist/util/hydration-cache-api.js.flow +30 -0
- package/dist/util/merge-gql-context.d.ts +8 -0
- package/dist/util/merge-gql-context.js.flow +19 -0
- package/dist/util/purge-caches.d.ts +8 -0
- package/dist/util/purge-caches.js.flow +15 -0
- package/dist/util/request-api.d.ts +28 -0
- package/dist/util/request-api.js.flow +34 -0
- package/dist/util/request-fulfillment.d.ts +37 -0
- package/dist/util/request-fulfillment.js.flow +50 -0
- package/dist/util/request-tracking.d.ts +62 -0
- package/dist/util/request-tracking.js.flow +81 -0
- package/dist/util/result-from-cache-response.d.ts +5 -0
- package/dist/util/result-from-cache-response.js.flow +15 -0
- package/dist/util/scoped-in-memory-cache.d.ts +38 -0
- package/dist/util/scoped-in-memory-cache.js.flow +57 -0
- package/dist/util/serializable-in-memory-cache.d.ts +16 -0
- package/dist/util/serializable-in-memory-cache.js.flow +26 -0
- package/dist/util/ssr-cache.d.ts +51 -0
- package/dist/util/ssr-cache.js.flow +87 -0
- package/dist/util/status.d.ts +10 -0
- package/dist/util/status.js.flow +19 -0
- package/dist/util/to-gql-operation.d.ts +32 -0
- package/dist/util/to-gql-operation.js.flow +45 -0
- package/dist/util/types.d.ts +111 -0
- package/dist/util/types.js.flow +151 -0
- package/package.json +5 -6
- package/src/components/__tests__/{data.test.js → data.test.tsx} +42 -2
- package/src/components/__tests__/{gql-router.test.js → gql-router.test.tsx} +4 -5
- package/src/components/__tests__/{intercept-requests.test.js → intercept-requests.test.tsx} +2 -3
- package/src/components/__tests__/{track-data.test.js → track-data.test.tsx} +2 -3
- package/src/components/{data.js → data.ts} +11 -15
- package/src/components/{gql-router.js → gql-router.tsx} +12 -14
- package/src/components/{intercept-context.js → intercept-context.ts} +4 -3
- package/src/components/{intercept-requests.js → intercept-requests.tsx} +7 -8
- package/src/components/{track-data.js → track-data.tsx} +4 -5
- package/src/hooks/__tests__/{use-cached-effect.test.js → use-cached-effect.test.tsx} +55 -50
- package/src/hooks/__tests__/{use-gql-router-context.test.js → use-gql-router-context.test.tsx} +7 -7
- package/src/hooks/__tests__/{use-gql.test.js → use-gql.test.tsx} +20 -21
- package/src/hooks/__tests__/{use-hydratable-effect.test.js → use-hydratable-effect.test.ts} +42 -37
- package/src/hooks/__tests__/{use-request-interception.test.js → use-request-interception.test.tsx} +5 -3
- package/src/hooks/__tests__/{use-server-effect.test.js → use-server-effect.test.ts} +8 -2
- package/src/hooks/__tests__/{use-shared-cache.test.js → use-shared-cache.test.ts} +12 -12
- package/src/hooks/{use-cached-effect.js → use-cached-effect.ts} +27 -20
- package/src/hooks/{use-gql-router-context.js → use-gql-router-context.ts} +2 -3
- package/src/hooks/{use-gql.js → use-gql.ts} +5 -5
- package/src/hooks/{use-hydratable-effect.js → use-hydratable-effect.ts} +53 -58
- package/src/hooks/{use-request-interception.js → use-request-interception.ts} +4 -4
- package/src/hooks/{use-server-effect.js → use-server-effect.ts} +7 -9
- package/src/hooks/{use-shared-cache.js → use-shared-cache.ts} +13 -8
- package/src/{index.js → index.ts} +0 -1
- package/src/util/__tests__/{get-gql-data-from-response.test.js → get-gql-data-from-response.test.ts} +0 -1
- package/src/util/__tests__/{get-gql-request-id.test.js → get-gql-request-id.test.ts} +9 -11
- package/src/util/__tests__/{graphql-document-node-parser.test.js → graphql-document-node-parser.test.ts} +11 -12
- package/src/util/__tests__/{hydration-cache-api.test.js → hydration-cache-api.test.ts} +1 -2
- package/src/util/__tests__/{merge-gql-context.test.js → merge-gql-context.test.ts} +4 -5
- package/src/util/__tests__/{purge-caches.test.js → purge-caches.test.ts} +0 -1
- package/src/util/__tests__/{request-api.test.js → request-api.test.ts} +2 -2
- package/src/util/__tests__/{request-fulfillment.test.js → request-fulfillment.test.ts} +0 -1
- package/src/util/__tests__/{request-tracking.test.js → request-tracking.test.tsx} +13 -6
- package/src/util/__tests__/{result-from-cache-response.test.js → result-from-cache-response.test.ts} +2 -4
- package/src/util/__tests__/{scoped-in-memory-cache.test.js → scoped-in-memory-cache.test.ts} +4 -5
- package/src/util/__tests__/{serializable-in-memory-cache.test.js → serializable-in-memory-cache.test.ts} +7 -7
- package/src/util/__tests__/{ssr-cache.test.js → ssr-cache.test.ts} +3 -2
- package/src/util/__tests__/{to-gql-operation.test.js → to-gql-operation.test.ts} +2 -1
- package/src/util/{data-error.js → data-error.ts} +2 -3
- package/src/util/{get-gql-data-from-response.js → get-gql-data-from-response.ts} +1 -6
- package/src/util/{get-gql-request-id.js → get-gql-request-id.ts} +12 -16
- package/src/util/{gql-error.js → gql-error.ts} +2 -3
- package/src/util/gql-router-context.ts +6 -0
- package/src/util/{gql-types.js → gql-types.ts} +27 -23
- package/src/util/{graphql-document-node-parser.js → graphql-document-node-parser.ts} +6 -7
- package/src/util/graphql-types.ts +27 -0
- package/src/util/{hydration-cache-api.js → hydration-cache-api.ts} +4 -2
- package/src/util/{merge-gql-context.js → merge-gql-context.ts} +2 -2
- package/src/util/{purge-caches.js → purge-caches.ts} +0 -1
- package/src/util/{request-api.js → request-api.ts} +0 -1
- package/src/util/{request-fulfillment.js → request-fulfillment.ts} +13 -12
- package/src/util/{request-tracking.js → request-tracking.ts} +12 -13
- package/src/util/{result-from-cache-response.js → result-from-cache-response.ts} +3 -4
- package/src/util/{scoped-in-memory-cache.js → scoped-in-memory-cache.ts} +1 -2
- package/src/util/{serializable-in-memory-cache.js → serializable-in-memory-cache.ts} +2 -3
- package/src/util/{ssr-cache.js → ssr-cache.ts} +19 -18
- package/src/util/{status.js → status.ts} +4 -5
- package/src/util/{to-gql-operation.js → to-gql-operation.ts} +1 -2
- package/src/util/{types.js → types.ts} +39 -48
- package/tsconfig.json +11 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/src/__docs__/_overview_.stories.mdx +0 -18
- package/src/__docs__/_overview_graphql.stories.mdx +0 -35
- package/src/__docs__/_overview_ssr_.stories.mdx +0 -185
- package/src/__docs__/_overview_testing_.stories.mdx +0 -123
- package/src/__docs__/exports.abort-inflight-requests.stories.mdx +0 -20
- package/src/__docs__/exports.data-error.stories.mdx +0 -23
- package/src/__docs__/exports.data-errors.stories.mdx +0 -23
- package/src/__docs__/exports.data.stories.mdx +0 -146
- package/src/__docs__/exports.fetch-tracked-requests.stories.mdx +0 -24
- package/src/__docs__/exports.get-gql-request-id.stories.mdx +0 -24
- package/src/__docs__/exports.gql-error.stories.mdx +0 -23
- package/src/__docs__/exports.gql-errors.stories.mdx +0 -20
- package/src/__docs__/exports.gql-router.stories.mdx +0 -29
- package/src/__docs__/exports.has-tracked-requests-to-be-fetched.stories.mdx +0 -20
- package/src/__docs__/exports.intercept-requests.stories.mdx +0 -69
- package/src/__docs__/exports.intialize-hydration-cache.stories.mdx +0 -29
- package/src/__docs__/exports.purge-caches.stories.mdx +0 -23
- package/src/__docs__/exports.purge-hydration-cache.stories.mdx +0 -24
- package/src/__docs__/exports.scoped-in-memory-cache.stories.mdx +0 -92
- package/src/__docs__/exports.serializable-in-memory-cache.stories.mdx +0 -112
- package/src/__docs__/exports.shared-cache.stories.mdx +0 -16
- package/src/__docs__/exports.status.stories.mdx +0 -31
- package/src/__docs__/exports.track-data.stories.mdx +0 -209
- package/src/__docs__/exports.use-cached-effect.stories.mdx +0 -44
- package/src/__docs__/exports.use-gql.stories.mdx +0 -41
- package/src/__docs__/exports.use-hydratable-effect.stories.mdx +0 -43
- package/src/__docs__/exports.use-server-effect.stories.mdx +0 -50
- package/src/__docs__/exports.use-shared-cache.stories.mdx +0 -30
- package/src/__docs__/exports.when-client-side.stories.mdx +0 -33
- package/src/__docs__/types.cached-response.stories.mdx +0 -29
- package/src/__docs__/types.error-options.stories.mdx +0 -21
- package/src/__docs__/types.fetch-policy.stories.mdx +0 -44
- package/src/__docs__/types.gql-context.stories.mdx +0 -20
- package/src/__docs__/types.gql-fetch-fn.stories.mdx +0 -24
- package/src/__docs__/types.gql-fetch-options.stories.mdx +0 -24
- package/src/__docs__/types.gql-operation-type.stories.mdx +0 -24
- package/src/__docs__/types.gql-operation.stories.mdx +0 -67
- package/src/__docs__/types.raw-scoped-cache.stories.mdx +0 -27
- package/src/__docs__/types.response-cache.stories.mdx +0 -33
- package/src/__docs__/types.result.stories.mdx +0 -39
- package/src/__docs__/types.scoped-cache.stories.mdx +0 -114
- package/src/__docs__/types.valid-cache-data.stories.mdx +0 -23
- package/src/util/gql-router-context.js +0 -6
- package/src/util/graphql-types.js +0 -30
- /package/src/hooks/__tests__/__snapshots__/{use-shared-cache.test.js.snap → use-shared-cache.test.ts.snap} +0 -0
- /package/src/util/__tests__/__snapshots__/{scoped-in-memory-cache.test.js.snap → scoped-in-memory-cache.test.ts.snap} +0 -0
- /package/src/util/__tests__/__snapshots__/{serializable-in-memory-cache.test.js.snap → serializable-in-memory-cache.test.ts.snap} +0 -0
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import * as React from "react";
|
|
3
2
|
|
|
4
3
|
import {
|
|
@@ -12,15 +11,14 @@ type Props<
|
|
|
12
11
|
/**
|
|
13
12
|
* The type of data resolved by the handler's fulfillRequest method.
|
|
14
13
|
*/
|
|
15
|
-
TData
|
|
16
|
-
> = {
|
|
14
|
+
TData extends ValidCacheData,
|
|
15
|
+
> = {
|
|
17
16
|
/**
|
|
18
17
|
* A unique identifier for the request.
|
|
19
18
|
*
|
|
20
19
|
* This should not be shared by other uses of this component.
|
|
21
20
|
*/
|
|
22
|
-
requestId: string
|
|
23
|
-
|
|
21
|
+
requestId: string;
|
|
24
22
|
/**
|
|
25
23
|
* This defines how the request is fulfilled.
|
|
26
24
|
*
|
|
@@ -28,8 +26,7 @@ type Props<
|
|
|
28
26
|
* old handler result may be given. This is not a supported mode of
|
|
29
27
|
* operation.
|
|
30
28
|
*/
|
|
31
|
-
handler: () => Promise<TData
|
|
32
|
-
|
|
29
|
+
handler: () => Promise<TData>;
|
|
33
30
|
/**
|
|
34
31
|
* How the hook should behave when rendering client-side for the first time.
|
|
35
32
|
*
|
|
@@ -37,8 +34,7 @@ type Props<
|
|
|
37
34
|
*
|
|
38
35
|
* Default is `OnClientRender.ExecuteWhenNoSuccessResult`.
|
|
39
36
|
*/
|
|
40
|
-
clientBehavior?:
|
|
41
|
-
|
|
37
|
+
clientBehavior?: typeof WhenClientSide[keyof typeof WhenClientSide];
|
|
42
38
|
/**
|
|
43
39
|
* When true, the children will be rendered with the existing result
|
|
44
40
|
* until the pending load is completed. Otherwise, the children will be
|
|
@@ -46,28 +42,28 @@ type Props<
|
|
|
46
42
|
*
|
|
47
43
|
* Defaults to false.
|
|
48
44
|
*/
|
|
49
|
-
retainResultOnChange?: boolean
|
|
50
|
-
|
|
45
|
+
retainResultOnChange?: boolean;
|
|
51
46
|
/**
|
|
52
47
|
* A function that will render the content of this component using the
|
|
53
48
|
* loading state and data or error that gets retrieved from cache or loaded
|
|
54
49
|
* via the request if no cached value is available.
|
|
55
50
|
*/
|
|
56
|
-
children: (result: Result<TData>) => React.
|
|
57
|
-
|
|
51
|
+
children: (result: Result<TData>) => React.ReactElement;
|
|
52
|
+
};
|
|
58
53
|
|
|
59
54
|
/**
|
|
60
55
|
* This component is the main component of Wonder Blocks Data. With this, data
|
|
61
56
|
* requirements can be placed in a React application in a manner that will
|
|
62
57
|
* support server-side rendering and efficient caching.
|
|
63
58
|
*/
|
|
64
|
-
|
|
59
|
+
// TODO(FEI-5000): Update this support generic props correctly
|
|
60
|
+
const Data: React.FC<Props<any>> = <TData extends ValidCacheData>({
|
|
65
61
|
requestId,
|
|
66
62
|
handler,
|
|
67
63
|
children,
|
|
68
64
|
retainResultOnChange = false,
|
|
69
65
|
clientBehavior = WhenClientSide.ExecuteWhenNoSuccessResult,
|
|
70
|
-
}: Props<TData>): React.
|
|
66
|
+
}: Props<TData>): React.ReactElement => {
|
|
71
67
|
const result = useHydratableEffect(requestId, handler, {
|
|
72
68
|
retainResultOnChange,
|
|
73
69
|
clientBehavior,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import * as React from "react";
|
|
3
2
|
|
|
4
3
|
import {GqlRouterContext} from "../util/gql-router-context";
|
|
@@ -9,22 +8,20 @@ import type {
|
|
|
9
8
|
GqlRouterConfiguration,
|
|
10
9
|
} from "../util/gql-types";
|
|
11
10
|
|
|
12
|
-
type Props<TContext
|
|
11
|
+
type Props<TContext extends GqlContext> = {
|
|
13
12
|
/**
|
|
14
13
|
* The default context to be used by operations when no context is provided.
|
|
15
14
|
*/
|
|
16
|
-
defaultContext: TContext
|
|
17
|
-
|
|
15
|
+
defaultContext: TContext;
|
|
18
16
|
/**
|
|
19
17
|
* The function to use when fetching requests.
|
|
20
18
|
*/
|
|
21
|
-
fetch: GqlFetchFn<any, any, TContext
|
|
22
|
-
|
|
19
|
+
fetch: GqlFetchFn<any, any, TContext>;
|
|
23
20
|
/**
|
|
24
21
|
* The children to be rendered inside the router.
|
|
25
22
|
*/
|
|
26
|
-
children: React.
|
|
27
|
-
|
|
23
|
+
children: React.ReactNode;
|
|
24
|
+
};
|
|
28
25
|
|
|
29
26
|
/**
|
|
30
27
|
* Configure GraphQL routing for GraphQL hooks and components.
|
|
@@ -32,17 +29,18 @@ type Props<TContext: GqlContext> = {|
|
|
|
32
29
|
* These can be nested. Components and hooks relying on the GraphQL routing
|
|
33
30
|
* will use the configuration from their closest ancestral GqlRouter.
|
|
34
31
|
*/
|
|
35
|
-
|
|
32
|
+
// TODO(FEI-5000): Update this support generic props correctly
|
|
33
|
+
export const GqlRouter: React.FC<Props<any>> = <TContext extends GqlContext>({
|
|
36
34
|
defaultContext: thisDefaultContext,
|
|
37
35
|
fetch: thisFetch,
|
|
38
36
|
children,
|
|
39
|
-
}: Props<TContext>): React.
|
|
37
|
+
}: Props<TContext>): React.ReactElement => {
|
|
40
38
|
// We don't care if we're nested. We always force our callers to define
|
|
41
39
|
// everything. It makes for a clearer API and requires less error checking
|
|
42
|
-
// code (assuming our
|
|
43
|
-
// to anything - our callers can tell us what function to use quite
|
|
44
|
-
// If code that consumes this wants more nuanced nesting, it can
|
|
45
|
-
// it within its own GqlRouter than then defers to this one.
|
|
40
|
+
// code (assuming our TypeScript types are correct). We also don't default
|
|
41
|
+
// fetch to anything - our callers can tell us what function to use quite
|
|
42
|
+
// easily. If code that consumes this wants more nuanced nesting, it can
|
|
43
|
+
// implement it within its own GqlRouter than then defers to this one.
|
|
46
44
|
|
|
47
45
|
// We want to always use the same object if things haven't changed to avoid
|
|
48
46
|
// over-rendering consumers of our context, let's memoize the configuration.
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import * as React from "react";
|
|
3
2
|
import type {ValidCacheData} from "../util/types";
|
|
4
3
|
|
|
5
|
-
type InterceptContextData =
|
|
6
|
-
(
|
|
4
|
+
type InterceptContextData = ReadonlyArray<
|
|
5
|
+
(
|
|
6
|
+
requestId: string,
|
|
7
|
+
) => Promise<ValidCacheData | null | undefined> | null | undefined
|
|
7
8
|
>;
|
|
8
9
|
|
|
9
10
|
/**
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import * as React from "react";
|
|
3
2
|
|
|
4
3
|
import InterceptContext from "./intercept-context";
|
|
5
4
|
|
|
6
5
|
import type {ValidCacheData} from "../util/types";
|
|
7
6
|
|
|
8
|
-
type Props<TData
|
|
7
|
+
type Props<TData extends ValidCacheData> = {
|
|
9
8
|
/**
|
|
10
9
|
* Called to intercept and possibly handle the request.
|
|
11
10
|
* If this returns null, the request will be handled by ancestor
|
|
@@ -20,16 +19,15 @@ type Props<TData: ValidCacheData> = {|
|
|
|
20
19
|
* so make sure to only intercept requests that you recognize from the
|
|
21
20
|
* identifier.
|
|
22
21
|
*/
|
|
23
|
-
interceptor: (requestId: string) =>
|
|
24
|
-
|
|
22
|
+
interceptor: (requestId: string) => Promise<TData> | null | undefined;
|
|
25
23
|
/**
|
|
26
24
|
* The children to render within this component. Any requests by `Data`
|
|
27
25
|
* components that use same ID as this component will be intercepted.
|
|
28
26
|
* If `InterceptRequests` is used within `children`, that interception will
|
|
29
27
|
* be given a chance to intercept first.
|
|
30
28
|
*/
|
|
31
|
-
children: React.
|
|
32
|
-
|
|
29
|
+
children: React.ReactNode;
|
|
30
|
+
};
|
|
33
31
|
|
|
34
32
|
/**
|
|
35
33
|
* This component provides a mechanism to intercept data requests.
|
|
@@ -45,10 +43,11 @@ type Props<TData: ValidCacheData> = {|
|
|
|
45
43
|
* interceptor closest to the intercepted request is called first, and the
|
|
46
44
|
* furthest interceptor is called last.
|
|
47
45
|
*/
|
|
48
|
-
|
|
46
|
+
// TODO(FEI-5000): Update this support generic props correctly
|
|
47
|
+
const InterceptRequests: React.FC<Props<any>> = <TData extends ValidCacheData>({
|
|
49
48
|
interceptor,
|
|
50
49
|
children,
|
|
51
|
-
}: Props<TData>): React.
|
|
50
|
+
}: Props<TData>): React.ReactElement => {
|
|
52
51
|
const interceptors = React.useContext(InterceptContext);
|
|
53
52
|
|
|
54
53
|
const updatedInterceptors = React.useMemo(
|
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import * as React from "react";
|
|
3
2
|
import {Server} from "@khanacademy/wonder-blocks-core";
|
|
4
3
|
|
|
5
4
|
import {RequestTracker, TrackerContext} from "../util/request-tracking";
|
|
6
5
|
|
|
7
|
-
type TrackDataProps = {
|
|
8
|
-
children: React.
|
|
9
|
-
|
|
6
|
+
type TrackDataProps = {
|
|
7
|
+
children: React.ReactNode;
|
|
8
|
+
};
|
|
10
9
|
|
|
11
10
|
/**
|
|
12
11
|
* Component to enable data request tracking when server-side rendering.
|
|
13
12
|
*/
|
|
14
13
|
export default class TrackData extends React.Component<TrackDataProps> {
|
|
15
|
-
render(): React.
|
|
14
|
+
render(): React.ReactElement {
|
|
16
15
|
if (!Server.isServerSide()) {
|
|
17
16
|
throw new Error(
|
|
18
17
|
"This component is not for use during client-side rendering",
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import * as React from "react";
|
|
3
2
|
import {
|
|
4
3
|
renderHook as clientRenderHook,
|
|
@@ -23,8 +22,8 @@ jest.mock("../use-request-interception");
|
|
|
23
22
|
jest.mock("../use-shared-cache");
|
|
24
23
|
|
|
25
24
|
const allPolicies = Array.from(values(FetchPolicy));
|
|
26
|
-
const allPoliciesBut = (policy:
|
|
27
|
-
allPolicies.filter((p) => p !== policy);
|
|
25
|
+
const allPoliciesBut = (policy: typeof FetchPolicy[keyof typeof FetchPolicy]) =>
|
|
26
|
+
allPolicies.filter((p: any) => p !== policy);
|
|
28
27
|
|
|
29
28
|
describe("#useCachedEffect", () => {
|
|
30
29
|
beforeEach(() => {
|
|
@@ -38,14 +37,14 @@ describe("#useCachedEffect", () => {
|
|
|
38
37
|
jest.spyOn(
|
|
39
38
|
UseRequestInterception,
|
|
40
39
|
"useRequestInterception",
|
|
41
|
-
).mockImplementation((_, handler) => handler);
|
|
40
|
+
).mockImplementation((_: any, handler: any) => handler);
|
|
42
41
|
|
|
43
42
|
// We need the cache to work a little so that we get our result.
|
|
44
|
-
const cache = {};
|
|
43
|
+
const cache: Record<string, any> = {};
|
|
45
44
|
jest.spyOn(UseSharedCache, "useSharedCache").mockImplementation(
|
|
46
|
-
(id, _, defaultValue) => {
|
|
45
|
+
(id: any, _: any, defaultValue: any) => {
|
|
47
46
|
const setCache = React.useCallback(
|
|
48
|
-
(v) => (cache[id] = v),
|
|
47
|
+
(v: any) => (cache[id] = v),
|
|
49
48
|
[id],
|
|
50
49
|
);
|
|
51
50
|
return [cache[id] ?? defaultValue, setCache];
|
|
@@ -81,7 +80,7 @@ describe("#useCachedEffect", () => {
|
|
|
81
80
|
${"foo"} | ${"foo"}
|
|
82
81
|
`(
|
|
83
82
|
"should call useSharedCache with id, scope=$scope, without a default",
|
|
84
|
-
({scope, cachedResult, expectedScope}) => {
|
|
83
|
+
({scope, cachedResult, expectedScope}: any) => {
|
|
85
84
|
const fakeHandler = jest.fn();
|
|
86
85
|
const useSharedCacheSpy = jest.spyOn(
|
|
87
86
|
UseSharedCache,
|
|
@@ -103,7 +102,7 @@ describe("#useCachedEffect", () => {
|
|
|
103
102
|
|
|
104
103
|
it.each(allPolicies)(
|
|
105
104
|
"should not request data for FetchPolicy.%s",
|
|
106
|
-
(fetchPolicy) => {
|
|
105
|
+
(fetchPolicy: any) => {
|
|
107
106
|
// Arrange
|
|
108
107
|
const fakeHandler = jest.fn().mockResolvedValue("data");
|
|
109
108
|
|
|
@@ -119,7 +118,7 @@ describe("#useCachedEffect", () => {
|
|
|
119
118
|
|
|
120
119
|
describe.each(allPolicies)(
|
|
121
120
|
"with FetchPolicy.%s without cached result",
|
|
122
|
-
(fetchPolicy) => {
|
|
121
|
+
(fetchPolicy: any) => {
|
|
123
122
|
it("should return a loading result", () => {
|
|
124
123
|
// Arrange
|
|
125
124
|
const fakeHandler = jest.fn();
|
|
@@ -141,7 +140,7 @@ describe("#useCachedEffect", () => {
|
|
|
141
140
|
|
|
142
141
|
describe.each(allPoliciesBut(FetchPolicy.NetworkOnly))(
|
|
143
142
|
"with FetchPolicy.%s with cached result",
|
|
144
|
-
(fetchPolicy) => {
|
|
143
|
+
(fetchPolicy: any) => {
|
|
145
144
|
it("should return the result", () => {
|
|
146
145
|
// Arrange
|
|
147
146
|
const fakeHandler = jest.fn();
|
|
@@ -216,7 +215,7 @@ describe("#useCachedEffect", () => {
|
|
|
216
215
|
|
|
217
216
|
it("should share inflight requests for the same requestId", () => {
|
|
218
217
|
// Arrange
|
|
219
|
-
const pending = new Promise((resolve, reject) => {
|
|
218
|
+
const pending = new Promise((resolve: any, reject: any) => {
|
|
220
219
|
/*pending*/
|
|
221
220
|
});
|
|
222
221
|
const fakeHandler = jest.fn().mockReturnValue(pending);
|
|
@@ -231,7 +230,7 @@ describe("#useCachedEffect", () => {
|
|
|
231
230
|
|
|
232
231
|
it.each(allPoliciesBut(FetchPolicy.CacheOnly))(
|
|
233
232
|
"should provide function that causes refetch with FetchPolicy.%s",
|
|
234
|
-
async (fetchPolicy) => {
|
|
233
|
+
async (fetchPolicy: any) => {
|
|
235
234
|
// Arrange
|
|
236
235
|
const response = Promise.resolve("DATA1");
|
|
237
236
|
const fakeHandler = jest.fn().mockReturnValue(response);
|
|
@@ -245,9 +244,11 @@ describe("#useCachedEffect", () => {
|
|
|
245
244
|
useCachedEffect("ID", fakeHandler, {fetchPolicy}),
|
|
246
245
|
);
|
|
247
246
|
fakeHandler.mockClear();
|
|
248
|
-
|
|
247
|
+
// @ts-expect-error [FEI-5019] - TS2769 - No overload matches this call.
|
|
248
|
+
await act((): Promise<unknown> => response);
|
|
249
249
|
act(refetch);
|
|
250
|
-
|
|
250
|
+
// @ts-expect-error [FEI-5019] - TS2769 - No overload matches this call.
|
|
251
|
+
await act((): Promise<unknown> => response);
|
|
251
252
|
|
|
252
253
|
// Assert
|
|
253
254
|
expect(fakeHandler).toHaveBeenCalledTimes(1);
|
|
@@ -278,7 +279,7 @@ describe("#useCachedEffect", () => {
|
|
|
278
279
|
|
|
279
280
|
it.each(allPoliciesBut(FetchPolicy.CacheOnly))(
|
|
280
281
|
"should fulfill request when there is no cached value and FetchPolicy.%s",
|
|
281
|
-
(fetchPolicy) => {
|
|
282
|
+
(fetchPolicy: any) => {
|
|
282
283
|
// Arrange
|
|
283
284
|
const fakeHandler = jest.fn();
|
|
284
285
|
jest.spyOn(UseSharedCache, "useSharedCache").mockReturnValue([
|
|
@@ -298,7 +299,7 @@ describe("#useCachedEffect", () => {
|
|
|
298
299
|
|
|
299
300
|
it.each([FetchPolicy.CacheAndNetwork, FetchPolicy.NetworkOnly])(
|
|
300
301
|
"should fulfill request when there is a cached value and FetchPolicy.%s",
|
|
301
|
-
(fetchPolicy) => {
|
|
302
|
+
(fetchPolicy: any) => {
|
|
302
303
|
// Arrange
|
|
303
304
|
const fakeHandler = jest.fn();
|
|
304
305
|
jest.spyOn(UseSharedCache, "useSharedCache").mockReturnValue([
|
|
@@ -325,7 +326,7 @@ describe("#useCachedEffect", () => {
|
|
|
325
326
|
${Status.aborted()}
|
|
326
327
|
`(
|
|
327
328
|
"should not fulfill request when there is a cached response of $cachedResult and FetchPolicy.CacheBeforeNetwork",
|
|
328
|
-
({cachedResult}) => {
|
|
329
|
+
({cachedResult}: any) => {
|
|
329
330
|
const fakeHandler = jest.fn();
|
|
330
331
|
jest.spyOn(UseSharedCache, "useSharedCache").mockReturnValue([
|
|
331
332
|
cachedResult,
|
|
@@ -352,7 +353,7 @@ describe("#useCachedEffect", () => {
|
|
|
352
353
|
${Status.aborted()}
|
|
353
354
|
`(
|
|
354
355
|
"should not fulfill request when there is a cached response of $cachedResult and FetchPolicy.CacheOnly",
|
|
355
|
-
({cachedResult}) => {
|
|
356
|
+
({cachedResult}: any) => {
|
|
356
357
|
const fakeHandler = jest.fn();
|
|
357
358
|
jest.spyOn(UseSharedCache, "useSharedCache").mockReturnValue([
|
|
358
359
|
cachedResult,
|
|
@@ -392,7 +393,7 @@ describe("#useCachedEffect", () => {
|
|
|
392
393
|
|
|
393
394
|
// Act
|
|
394
395
|
const {rerender, waitForNextUpdate} = clientRenderHook(
|
|
395
|
-
({requestId}) => useCachedEffect(requestId, fakeHandler),
|
|
396
|
+
({requestId}: any) => useCachedEffect(requestId, fakeHandler),
|
|
396
397
|
{
|
|
397
398
|
initialProps: {requestId: "ID"},
|
|
398
399
|
},
|
|
@@ -434,15 +435,13 @@ describe("#useCachedEffect", () => {
|
|
|
434
435
|
|
|
435
436
|
// Act
|
|
436
437
|
const {rerender, result} = clientRenderHook(
|
|
437
|
-
({requestId}) => useCachedEffect(requestId, fakeHandler),
|
|
438
|
+
({requestId}: any) => useCachedEffect(requestId, fakeHandler),
|
|
438
439
|
{
|
|
439
440
|
initialProps: {requestId: "ID"},
|
|
440
441
|
},
|
|
441
442
|
);
|
|
442
443
|
rerender({requestId: "ID2"});
|
|
443
|
-
await act((): Promise<
|
|
444
|
-
Promise.all([response1, response2]),
|
|
445
|
-
);
|
|
444
|
+
await act((): Promise<any> => Promise.all([response1, response2]));
|
|
446
445
|
|
|
447
446
|
// Assert
|
|
448
447
|
expect(result.all).not.toContainEqual(Status.success("DATA1"));
|
|
@@ -459,15 +458,13 @@ describe("#useCachedEffect", () => {
|
|
|
459
458
|
|
|
460
459
|
// Act
|
|
461
460
|
const {rerender, result} = clientRenderHook(
|
|
462
|
-
({requestId}) => useCachedEffect(requestId, fakeHandler),
|
|
461
|
+
({requestId}: any) => useCachedEffect(requestId, fakeHandler),
|
|
463
462
|
{
|
|
464
463
|
initialProps: {requestId: "ID"},
|
|
465
464
|
},
|
|
466
465
|
);
|
|
467
466
|
rerender({requestId: "ID2"});
|
|
468
|
-
await act((): Promise<
|
|
469
|
-
Promise.all([response1, response2]),
|
|
470
|
-
);
|
|
467
|
+
await act((): Promise<any> => Promise.all([response1, response2]));
|
|
471
468
|
|
|
472
469
|
// Assert
|
|
473
470
|
expect(result.current[0]).toStrictEqual(Status.success("DATA2"));
|
|
@@ -493,13 +490,14 @@ describe("#useCachedEffect", () => {
|
|
|
493
490
|
|
|
494
491
|
// Act
|
|
495
492
|
const {rerender, result} = clientRenderHook(
|
|
496
|
-
({skip}) => useCachedEffect("ID", fakeHandler, {skip}),
|
|
493
|
+
({skip}: any) => useCachedEffect("ID", fakeHandler, {skip}),
|
|
497
494
|
{
|
|
498
495
|
initialProps: {skip: false},
|
|
499
496
|
},
|
|
500
497
|
);
|
|
501
498
|
rerender({skip: true});
|
|
502
|
-
|
|
499
|
+
// @ts-expect-error [FEI-5019] - TS2769 - No overload matches this call.
|
|
500
|
+
await act((): Promise<unknown> => response1);
|
|
503
501
|
|
|
504
502
|
// Assert
|
|
505
503
|
expect(result.all).not.toContainEqual(Status.success("DATA1"));
|
|
@@ -514,15 +512,13 @@ describe("#useCachedEffect", () => {
|
|
|
514
512
|
|
|
515
513
|
// Act
|
|
516
514
|
const {rerender, result} = clientRenderHook(
|
|
517
|
-
({handler}) => useCachedEffect("ID", handler),
|
|
515
|
+
({handler}: any) => useCachedEffect("ID", handler),
|
|
518
516
|
{
|
|
519
517
|
initialProps: {handler: fakeHandler1},
|
|
520
518
|
},
|
|
521
519
|
);
|
|
522
520
|
rerender({handler: fakeHandler2});
|
|
523
|
-
await act((): Promise<
|
|
524
|
-
Promise.all([response1, response2]),
|
|
525
|
-
);
|
|
521
|
+
await act((): Promise<any> => Promise.all([response1, response2]));
|
|
526
522
|
|
|
527
523
|
// Assert
|
|
528
524
|
expect(result.current[0]).toStrictEqual(Status.success("DATA1"));
|
|
@@ -535,17 +531,19 @@ describe("#useCachedEffect", () => {
|
|
|
535
531
|
|
|
536
532
|
// Act
|
|
537
533
|
const {rerender, result} = clientRenderHook(
|
|
538
|
-
({options}) => useCachedEffect("ID", fakeHandler),
|
|
534
|
+
({options}: any) => useCachedEffect("ID", fakeHandler),
|
|
539
535
|
{
|
|
540
536
|
initialProps: {options: undefined},
|
|
541
537
|
},
|
|
542
538
|
);
|
|
543
539
|
rerender({
|
|
540
|
+
// @ts-expect-error [FEI-5019] - TS2322 - Type '{ scope: string; }' is not assignable to type 'undefined'.
|
|
544
541
|
options: {
|
|
545
542
|
scope: "BLAH!",
|
|
546
543
|
},
|
|
547
544
|
});
|
|
548
|
-
|
|
545
|
+
// @ts-expect-error [FEI-5019] - TS2769 - No overload matches this call.
|
|
546
|
+
await act((): Promise<unknown> => response1);
|
|
549
547
|
|
|
550
548
|
// Assert
|
|
551
549
|
expect(result.current[0]).toStrictEqual(Status.success("DATA1"));
|
|
@@ -566,7 +564,7 @@ describe("#useCachedEffect", () => {
|
|
|
566
564
|
result: hookResult,
|
|
567
565
|
waitForNextUpdate,
|
|
568
566
|
} = clientRenderHook(
|
|
569
|
-
({requestId}) =>
|
|
567
|
+
({requestId}: any) =>
|
|
570
568
|
useCachedEffect(requestId, fakeHandler, {
|
|
571
569
|
retainResultOnChange: true,
|
|
572
570
|
}),
|
|
@@ -574,7 +572,8 @@ describe("#useCachedEffect", () => {
|
|
|
574
572
|
initialProps: {requestId: "ID"},
|
|
575
573
|
},
|
|
576
574
|
);
|
|
577
|
-
|
|
575
|
+
// @ts-expect-error [FEI-5019] - TS2769 - No overload matches this call.
|
|
576
|
+
await act((): Promise<unknown> => response1);
|
|
578
577
|
rerender({requestId: "ID2"});
|
|
579
578
|
const [result] = hookResult.current;
|
|
580
579
|
await waitForNextUpdate();
|
|
@@ -596,7 +595,7 @@ describe("#useCachedEffect", () => {
|
|
|
596
595
|
|
|
597
596
|
// Act
|
|
598
597
|
const {rerender, result} = clientRenderHook(
|
|
599
|
-
({requestId}) =>
|
|
598
|
+
({requestId}: any) =>
|
|
600
599
|
useCachedEffect(requestId, fakeHandler, {
|
|
601
600
|
retainResultOnChange: false,
|
|
602
601
|
}),
|
|
@@ -604,7 +603,8 @@ describe("#useCachedEffect", () => {
|
|
|
604
603
|
initialProps: {requestId: "ID"},
|
|
605
604
|
},
|
|
606
605
|
);
|
|
607
|
-
|
|
606
|
+
// @ts-expect-error [FEI-5019] - TS2769 - No overload matches this call.
|
|
607
|
+
await act((): Promise<unknown> => response1);
|
|
608
608
|
rerender({requestId: "ID2"});
|
|
609
609
|
|
|
610
610
|
// Assert
|
|
@@ -613,7 +613,7 @@ describe("#useCachedEffect", () => {
|
|
|
613
613
|
|
|
614
614
|
it.each(allPoliciesBut(FetchPolicy.CacheOnly))(
|
|
615
615
|
"should trigger render when request is fulfilled and onResultChanged is undefined for FetchPolicy.%s",
|
|
616
|
-
async (fetchPolicy) => {
|
|
616
|
+
async (fetchPolicy: any) => {
|
|
617
617
|
// Arrange
|
|
618
618
|
const response = Promise.resolve("DATA");
|
|
619
619
|
const fakeHandler = jest.fn().mockReturnValue(response);
|
|
@@ -626,7 +626,8 @@ describe("#useCachedEffect", () => {
|
|
|
626
626
|
|
|
627
627
|
// Act
|
|
628
628
|
render(<Component />);
|
|
629
|
-
|
|
629
|
+
// @ts-expect-error [FEI-5019] - TS2769 - No overload matches this call.
|
|
630
|
+
await reactAct((): Promise<unknown> => response);
|
|
630
631
|
|
|
631
632
|
// Assert
|
|
632
633
|
expect(renderCount).toBe(2);
|
|
@@ -635,7 +636,7 @@ describe("#useCachedEffect", () => {
|
|
|
635
636
|
|
|
636
637
|
it.each(allPoliciesBut(FetchPolicy.CacheOnly))(
|
|
637
638
|
"should trigger render once per inflight request being fulfilled and onResultChanged is undefined for FetchPolicy.%s",
|
|
638
|
-
async (fetchPolicy) => {
|
|
639
|
+
async (fetchPolicy: any) => {
|
|
639
640
|
// Arrange
|
|
640
641
|
const response = Promise.resolve("DATA");
|
|
641
642
|
const fakeHandler = jest.fn().mockReturnValue(response);
|
|
@@ -656,7 +657,8 @@ describe("#useCachedEffect", () => {
|
|
|
656
657
|
|
|
657
658
|
// Act
|
|
658
659
|
render(<Component />);
|
|
659
|
-
|
|
660
|
+
// @ts-expect-error [FEI-5019] - TS2769 - No overload matches this call.
|
|
661
|
+
await reactAct((): Promise<unknown> => response);
|
|
660
662
|
|
|
661
663
|
// Assert
|
|
662
664
|
expect(renderCount).toBe(2);
|
|
@@ -665,7 +667,7 @@ describe("#useCachedEffect", () => {
|
|
|
665
667
|
|
|
666
668
|
it.each(allPoliciesBut(FetchPolicy.CacheOnly))(
|
|
667
669
|
"should not trigger render when request is fulfilled and onResultChanged is defined for FetchPolicy.%s",
|
|
668
|
-
async (fetchPolicy) => {
|
|
670
|
+
async (fetchPolicy: any) => {
|
|
669
671
|
// Arrange
|
|
670
672
|
const response = Promise.resolve("DATA");
|
|
671
673
|
const fakeHandler = jest.fn().mockReturnValue(response);
|
|
@@ -681,7 +683,8 @@ describe("#useCachedEffect", () => {
|
|
|
681
683
|
|
|
682
684
|
// Act
|
|
683
685
|
render(<Component />);
|
|
684
|
-
|
|
686
|
+
// @ts-expect-error [FEI-5019] - TS2769 - No overload matches this call.
|
|
687
|
+
await reactAct((): Promise<unknown> => response);
|
|
685
688
|
|
|
686
689
|
// Assert
|
|
687
690
|
expect(renderCount).toBe(1);
|
|
@@ -690,7 +693,7 @@ describe("#useCachedEffect", () => {
|
|
|
690
693
|
|
|
691
694
|
it.each(allPoliciesBut(FetchPolicy.CacheOnly))(
|
|
692
695
|
"should call onResultChanged when request is fulfilled and onResultChanged is defined for FetchPolicy.%s",
|
|
693
|
-
async (fetchPolicy) => {
|
|
696
|
+
async (fetchPolicy: any) => {
|
|
694
697
|
// Arrange
|
|
695
698
|
const response = Promise.resolve("DATA");
|
|
696
699
|
const fakeHandler = jest.fn().mockReturnValue(response);
|
|
@@ -703,7 +706,8 @@ describe("#useCachedEffect", () => {
|
|
|
703
706
|
fetchPolicy,
|
|
704
707
|
}),
|
|
705
708
|
);
|
|
706
|
-
|
|
709
|
+
// @ts-expect-error [FEI-5019] - TS2769 - No overload matches this call.
|
|
710
|
+
await act((): Promise<unknown> => response);
|
|
707
711
|
|
|
708
712
|
// Assert
|
|
709
713
|
expect(onResultChanged).toHaveBeenCalledWith(
|
|
@@ -714,7 +718,7 @@ describe("#useCachedEffect", () => {
|
|
|
714
718
|
|
|
715
719
|
it.each(allPoliciesBut(FetchPolicy.CacheOnly))(
|
|
716
720
|
"should call onResultChanged once per inflight request being fulfilled and onResultChanged is defined for FetchPolicy.%s",
|
|
717
|
-
async (fetchPolicy) => {
|
|
721
|
+
async (fetchPolicy: any) => {
|
|
718
722
|
// Arrange
|
|
719
723
|
const response = Promise.resolve("DATA");
|
|
720
724
|
const fakeHandler = jest.fn().mockReturnValue(response);
|
|
@@ -735,7 +739,8 @@ describe("#useCachedEffect", () => {
|
|
|
735
739
|
act(refetch);
|
|
736
740
|
act(refetch);
|
|
737
741
|
act(refetch);
|
|
738
|
-
|
|
742
|
+
// @ts-expect-error [FEI-5019] - TS2769 - No overload matches this call.
|
|
743
|
+
await act((): Promise<unknown> => response);
|
|
739
744
|
|
|
740
745
|
// Assert
|
|
741
746
|
expect(onResultChanged).toHaveBeenCalledTimes(1);
|
package/src/hooks/__tests__/{use-gql-router-context.test.js → use-gql-router-context.test.tsx}
RENAMED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import * as React from "react";
|
|
3
2
|
import {renderHook} from "@testing-library/react-hooks";
|
|
4
3
|
|
|
@@ -27,7 +26,7 @@ describe("#useGqlRouterContext", () => {
|
|
|
27
26
|
defaultContext: {
|
|
28
27
|
foo: "bar",
|
|
29
28
|
},
|
|
30
|
-
};
|
|
29
|
+
} as const;
|
|
31
30
|
const Wrapper = ({children}: any) => (
|
|
32
31
|
<GqlRouterContext.Provider value={baseContext}>
|
|
33
32
|
{children}
|
|
@@ -50,7 +49,7 @@ describe("#useGqlRouterContext", () => {
|
|
|
50
49
|
defaultContext: {
|
|
51
50
|
foo: "bar",
|
|
52
51
|
},
|
|
53
|
-
};
|
|
52
|
+
} as const;
|
|
54
53
|
const Wrapper = ({children}: any) => (
|
|
55
54
|
<GqlRouterContext.Provider value={baseContext}>
|
|
56
55
|
{children}
|
|
@@ -76,7 +75,7 @@ describe("#useGqlRouterContext", () => {
|
|
|
76
75
|
defaultContext: {
|
|
77
76
|
foo: "bar",
|
|
78
77
|
},
|
|
79
|
-
};
|
|
78
|
+
} as const;
|
|
80
79
|
const Wrapper = ({children}: any) => (
|
|
81
80
|
<GqlRouterContext.Provider value={baseContext}>
|
|
82
81
|
{children}
|
|
@@ -85,7 +84,7 @@ describe("#useGqlRouterContext", () => {
|
|
|
85
84
|
|
|
86
85
|
// Act
|
|
87
86
|
const wrapper = renderHook(
|
|
88
|
-
({overrides}) => useGqlRouterContext(overrides),
|
|
87
|
+
({overrides}: any) => useGqlRouterContext(overrides),
|
|
89
88
|
{
|
|
90
89
|
wrapper: Wrapper,
|
|
91
90
|
initialProps: {},
|
|
@@ -106,7 +105,7 @@ describe("#useGqlRouterContext", () => {
|
|
|
106
105
|
defaultContext: {
|
|
107
106
|
foo: "bar",
|
|
108
107
|
},
|
|
109
|
-
};
|
|
108
|
+
} as const;
|
|
110
109
|
const Wrapper = ({children}: any) => (
|
|
111
110
|
<GqlRouterContext.Provider value={baseContext}>
|
|
112
111
|
{children}
|
|
@@ -115,7 +114,7 @@ describe("#useGqlRouterContext", () => {
|
|
|
115
114
|
|
|
116
115
|
// Act
|
|
117
116
|
const wrapper = renderHook(
|
|
118
|
-
({overrides}) => useGqlRouterContext(overrides),
|
|
117
|
+
({overrides}: any) => useGqlRouterContext(overrides),
|
|
119
118
|
{
|
|
120
119
|
wrapper: Wrapper,
|
|
121
120
|
initialProps: {
|
|
@@ -124,6 +123,7 @@ describe("#useGqlRouterContext", () => {
|
|
|
124
123
|
},
|
|
125
124
|
);
|
|
126
125
|
const result1 = wrapper.result.current;
|
|
126
|
+
// @ts-expect-error [FEI-5019] - TS2741 - Property 'fiz' is missing in type '{}' but required in type '{ fiz: string; }'.
|
|
127
127
|
wrapper.rerender({overrides: {}});
|
|
128
128
|
const result2 = wrapper.result.current;
|
|
129
129
|
|