@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
package/dist/index.js.flow
CHANGED
|
@@ -1,2 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for index
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
declare export { FetchPolicy } from "./util/types";
|
|
9
|
+
export type {
|
|
10
|
+
ErrorOptions,
|
|
11
|
+
ResponseCache,
|
|
12
|
+
CachedResponse,
|
|
13
|
+
Result,
|
|
14
|
+
RawScopedCache,
|
|
15
|
+
ValidCacheData,
|
|
16
|
+
ScopedCache,
|
|
17
|
+
} from "./util/types";
|
|
18
|
+
declare export * from "./util/hydration-cache-api";
|
|
19
|
+
declare export * from "./util/request-api";
|
|
20
|
+
declare export { purgeCaches } from "./util/purge-caches";
|
|
21
|
+
declare export { default as TrackData } from "./components/track-data";
|
|
22
|
+
declare export { default as Data } from "./components/data";
|
|
23
|
+
declare export { default as InterceptRequests } from "./components/intercept-requests";
|
|
24
|
+
declare export { DataError, DataErrors } from "./util/data-error";
|
|
25
|
+
declare export { useServerEffect } from "./hooks/use-server-effect";
|
|
26
|
+
declare export { useCachedEffect } from "./hooks/use-cached-effect";
|
|
27
|
+
declare export { useSharedCache, SharedCache } from "./hooks/use-shared-cache";
|
|
28
|
+
declare export {
|
|
29
|
+
useHydratableEffect,
|
|
30
|
+
WhenClientSide,
|
|
31
|
+
} from "./hooks/use-hydratable-effect";
|
|
32
|
+
declare export { ScopedInMemoryCache } from "./util/scoped-in-memory-cache";
|
|
33
|
+
declare export { SerializableInMemoryCache } from "./util/serializable-in-memory-cache";
|
|
34
|
+
declare export { Status } from "./util/status";
|
|
35
|
+
declare export { getGqlRequestId } from "./util/get-gql-request-id";
|
|
36
|
+
declare export { getGqlDataFromResponse } from "./util/get-gql-data-from-response";
|
|
37
|
+
declare export { graphQLDocumentNodeParser } from "./util/graphql-document-node-parser";
|
|
38
|
+
declare export { toGqlOperation } from "./util/to-gql-operation";
|
|
39
|
+
declare export { GqlRouter } from "./components/gql-router";
|
|
40
|
+
declare export { useGql } from "./hooks/use-gql";
|
|
41
|
+
declare export { GqlError, GqlErrors } from "./util/gql-error";
|
|
42
|
+
export type {
|
|
43
|
+
GqlContext,
|
|
44
|
+
GqlOperation,
|
|
45
|
+
GqlOperationType,
|
|
46
|
+
GqlFetchOptions,
|
|
47
|
+
GqlFetchFn,
|
|
48
|
+
} from "./util/gql-types";
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { KindError } from "@khanacademy/wonder-stuff-core";
|
|
2
|
+
import type { ErrorOptions } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Error kinds for DataError.
|
|
5
|
+
*/
|
|
6
|
+
export declare const DataErrors: Readonly<{
|
|
7
|
+
/**
|
|
8
|
+
* The kind of error is not known.
|
|
9
|
+
*/
|
|
10
|
+
Unknown: "Unknown";
|
|
11
|
+
/**
|
|
12
|
+
* The error is internal to the executing code.
|
|
13
|
+
*/
|
|
14
|
+
Internal: "Internal";
|
|
15
|
+
/**
|
|
16
|
+
* There was a problem with the provided input.
|
|
17
|
+
*/
|
|
18
|
+
InvalidInput: "InvalidInput";
|
|
19
|
+
/**
|
|
20
|
+
* A network error occurred.
|
|
21
|
+
*/
|
|
22
|
+
Network: "Network";
|
|
23
|
+
/**
|
|
24
|
+
* There was a problem due to the state of the system not matching the
|
|
25
|
+
* requested operation or input.
|
|
26
|
+
*/
|
|
27
|
+
NotAllowed: "NotAllowed";
|
|
28
|
+
/**
|
|
29
|
+
* Response could not be parsed.
|
|
30
|
+
*/
|
|
31
|
+
Parse: "Parse";
|
|
32
|
+
/**
|
|
33
|
+
* An error that occurred during SSR and was hydrated from cache
|
|
34
|
+
*/
|
|
35
|
+
Hydrated: "Hydrated";
|
|
36
|
+
}>;
|
|
37
|
+
/**
|
|
38
|
+
* An error from the Wonder Blocks Data API.
|
|
39
|
+
*
|
|
40
|
+
* Errors of this type will have names of the format:
|
|
41
|
+
* `${kind}DataError`
|
|
42
|
+
*/
|
|
43
|
+
export declare class DataError extends KindError {
|
|
44
|
+
constructor(message: string, kind: typeof DataErrors[keyof typeof DataErrors], { metadata, cause }?: ErrorOptions);
|
|
45
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for data-error
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { KindError } from "@khanacademy/wonder-stuff-core";
|
|
9
|
+
import type { ErrorOptions } from "./types";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Error kinds for DataError.
|
|
13
|
+
*/
|
|
14
|
+
declare export var DataErrors: $ReadOnly<{
|
|
15
|
+
/**
|
|
16
|
+
* The kind of error is not known.
|
|
17
|
+
*/
|
|
18
|
+
Unknown: "Unknown",
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The error is internal to the executing code.
|
|
22
|
+
*/
|
|
23
|
+
Internal: "Internal",
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* There was a problem with the provided input.
|
|
27
|
+
*/
|
|
28
|
+
InvalidInput: "InvalidInput",
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* A network error occurred.
|
|
32
|
+
*/
|
|
33
|
+
Network: "Network",
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* There was a problem due to the state of the system not matching the
|
|
37
|
+
* requested operation or input.
|
|
38
|
+
*/
|
|
39
|
+
NotAllowed: "NotAllowed",
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Response could not be parsed.
|
|
43
|
+
*/
|
|
44
|
+
Parse: "Parse",
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* An error that occurred during SSR and was hydrated from cache
|
|
48
|
+
*/
|
|
49
|
+
Hydrated: "Hydrated",
|
|
50
|
+
...
|
|
51
|
+
}>;
|
|
52
|
+
/**
|
|
53
|
+
* An error from the Wonder Blocks Data API.
|
|
54
|
+
*
|
|
55
|
+
* Errors of this type will have names of the format:
|
|
56
|
+
* `${kind}DataError`
|
|
57
|
+
*/
|
|
58
|
+
declare export class DataError extends KindError {
|
|
59
|
+
constructor(
|
|
60
|
+
message: string,
|
|
61
|
+
kind: $ElementType<typeof DataErrors, $Keys<typeof DataErrors>>,
|
|
62
|
+
x?: ErrorOptions
|
|
63
|
+
): this;
|
|
64
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for get-gql-data-from-response
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Validate a GQL operation response and extract the data.
|
|
10
|
+
*/
|
|
11
|
+
declare export var getGqlDataFromResponse: <TData>(
|
|
12
|
+
response: Response
|
|
13
|
+
) => Promise<TData>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { GqlOperation, GqlContext } from "./gql-types";
|
|
2
|
+
/**
|
|
3
|
+
* Get an identifier for a given request.
|
|
4
|
+
*/
|
|
5
|
+
export declare const getGqlRequestId: <TData, TVariables extends Record<any, any>>(operation: GqlOperation<TData, TVariables>, variables: TVariables | null | undefined, context: GqlContext) => string;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for get-gql-request-id
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { GqlOperation, GqlContext } from "./gql-types";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Get an identifier for a given request.
|
|
12
|
+
*/
|
|
13
|
+
declare export var getGqlRequestId: <
|
|
14
|
+
TData,
|
|
15
|
+
TVariables: { [key: any]: any, ... }
|
|
16
|
+
>(
|
|
17
|
+
operation: GqlOperation<TData, TVariables>,
|
|
18
|
+
variables: TVariables | null | void,
|
|
19
|
+
context: GqlContext
|
|
20
|
+
) => string;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { KindError } from "@khanacademy/wonder-stuff-core";
|
|
2
|
+
import type { ErrorOptions } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Error kinds for GqlError.
|
|
5
|
+
*/
|
|
6
|
+
export declare const GqlErrors: Readonly<{
|
|
7
|
+
/**
|
|
8
|
+
* An internal framework error.
|
|
9
|
+
*/
|
|
10
|
+
Internal: "Internal";
|
|
11
|
+
/**
|
|
12
|
+
* Response does not have the correct structure for a GraphQL response.
|
|
13
|
+
*/
|
|
14
|
+
BadResponse: "BadResponse";
|
|
15
|
+
/**
|
|
16
|
+
* A valid GraphQL result with errors field in the payload.
|
|
17
|
+
*/
|
|
18
|
+
ErrorResult: "ErrorResult";
|
|
19
|
+
}>;
|
|
20
|
+
/**
|
|
21
|
+
* An error from the GQL API.
|
|
22
|
+
*
|
|
23
|
+
* Errors of this type will have names of the format:
|
|
24
|
+
* `${kind}GqlError`
|
|
25
|
+
*/
|
|
26
|
+
export declare class GqlError extends KindError {
|
|
27
|
+
constructor(message: string, kind: typeof GqlErrors[keyof typeof GqlErrors], { metadata, cause }?: ErrorOptions);
|
|
28
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for gql-error
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { KindError } from "@khanacademy/wonder-stuff-core";
|
|
9
|
+
import type { ErrorOptions } from "./types";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Error kinds for GqlError.
|
|
13
|
+
*/
|
|
14
|
+
declare export var GqlErrors: $ReadOnly<{
|
|
15
|
+
/**
|
|
16
|
+
* An internal framework error.
|
|
17
|
+
*/
|
|
18
|
+
Internal: "Internal",
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Response does not have the correct structure for a GraphQL response.
|
|
22
|
+
*/
|
|
23
|
+
BadResponse: "BadResponse",
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* A valid GraphQL result with errors field in the payload.
|
|
27
|
+
*/
|
|
28
|
+
ErrorResult: "ErrorResult",
|
|
29
|
+
...
|
|
30
|
+
}>;
|
|
31
|
+
/**
|
|
32
|
+
* An error from the GQL API.
|
|
33
|
+
*
|
|
34
|
+
* Errors of this type will have names of the format:
|
|
35
|
+
* `${kind}GqlError`
|
|
36
|
+
*/
|
|
37
|
+
declare export class GqlError extends KindError {
|
|
38
|
+
constructor(
|
|
39
|
+
message: string,
|
|
40
|
+
kind: $ElementType<typeof GqlErrors, $Keys<typeof GqlErrors>>,
|
|
41
|
+
x?: ErrorOptions
|
|
42
|
+
): this;
|
|
43
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for gql-router-context
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as React from "react";
|
|
9
|
+
import type { GqlRouterConfiguration } from "./gql-types";
|
|
10
|
+
declare export var GqlRouterContext: React.Context<GqlRouterConfiguration<any> | null | void>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Operation types.
|
|
3
|
+
*/
|
|
4
|
+
export type GqlOperationType = "mutation" | "query";
|
|
5
|
+
/**
|
|
6
|
+
* A GraphQL operation.
|
|
7
|
+
*/
|
|
8
|
+
export type GqlOperation<TData, // TVariables is not used to define a field on this type, but it is used
|
|
9
|
+
TVariables extends object = Empty> = {
|
|
10
|
+
type: GqlOperationType;
|
|
11
|
+
id: string;
|
|
12
|
+
[key: string]: unknown;
|
|
13
|
+
};
|
|
14
|
+
export type GqlContext = {
|
|
15
|
+
[key: string]: string;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Functions that make fetches of GQL operations.
|
|
19
|
+
*/
|
|
20
|
+
export type GqlFetchFn<TData, TVariables extends Record<any, any>, TContext extends GqlContext> = (operation: GqlOperation<TData, TVariables>, variables: TVariables | null | undefined, context: TContext) => Promise<Response>;
|
|
21
|
+
/**
|
|
22
|
+
* The configuration stored in the GqlRouterContext context.
|
|
23
|
+
*/
|
|
24
|
+
export type GqlRouterConfiguration<TContext extends GqlContext> = {
|
|
25
|
+
fetch: GqlFetchFn<any, any, any>;
|
|
26
|
+
defaultContext: TContext;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Options for configuring a GQL fetch.
|
|
30
|
+
*/
|
|
31
|
+
export type GqlFetchOptions<TVariables extends Record<any, any>, TContext extends GqlContext> = {
|
|
32
|
+
variables?: TVariables;
|
|
33
|
+
context?: Partial<TContext>;
|
|
34
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for gql-types
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Operation types.
|
|
10
|
+
*/
|
|
11
|
+
export type GqlOperationType = "mutation" | "query";
|
|
12
|
+
/**
|
|
13
|
+
* A GraphQL operation.
|
|
14
|
+
*/
|
|
15
|
+
export type GqlOperation<TData, TVariables: { [key: string]: any } = Empty> = {
|
|
16
|
+
type: GqlOperationType,
|
|
17
|
+
id: string,
|
|
18
|
+
[key: string]: mixed,
|
|
19
|
+
};
|
|
20
|
+
export type GqlContext = {
|
|
21
|
+
[key: string]: string,
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Functions that make fetches of GQL operations.
|
|
25
|
+
*/
|
|
26
|
+
export type GqlFetchFn<
|
|
27
|
+
TData,
|
|
28
|
+
TVariables: { [key: any]: any, ... },
|
|
29
|
+
TContext: GqlContext
|
|
30
|
+
> = (
|
|
31
|
+
operation: GqlOperation<TData, TVariables>,
|
|
32
|
+
variables: TVariables | null | void,
|
|
33
|
+
context: TContext
|
|
34
|
+
) => Promise<Response>;
|
|
35
|
+
/**
|
|
36
|
+
* The configuration stored in the GqlRouterContext context.
|
|
37
|
+
*/
|
|
38
|
+
export type GqlRouterConfiguration<TContext: GqlContext> = {
|
|
39
|
+
fetch: GqlFetchFn<any, any, any>,
|
|
40
|
+
defaultContext: TContext,
|
|
41
|
+
...
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Options for configuring a GQL fetch.
|
|
45
|
+
*/
|
|
46
|
+
export type GqlFetchOptions<
|
|
47
|
+
TVariables: { [key: any]: any, ... },
|
|
48
|
+
TContext: GqlContext
|
|
49
|
+
> = {
|
|
50
|
+
variables?: TVariables,
|
|
51
|
+
context?: $Rest<TContext, { ... }>,
|
|
52
|
+
...
|
|
53
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { DocumentNode, VariableDefinitionNode } from "./graphql-types";
|
|
2
|
+
export declare const DocumentTypes: Readonly<{
|
|
3
|
+
query: "query";
|
|
4
|
+
mutation: "mutation";
|
|
5
|
+
}>;
|
|
6
|
+
export type DocumentType = typeof DocumentTypes[keyof typeof DocumentTypes];
|
|
7
|
+
export interface IDocumentDefinition {
|
|
8
|
+
type: DocumentType;
|
|
9
|
+
name: string;
|
|
10
|
+
variables: ReadonlyArray<VariableDefinitionNode>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Parse a GraphQL document node to determine some info about it.
|
|
14
|
+
*
|
|
15
|
+
* This is based on:
|
|
16
|
+
* https://github.com/apollographql/react-apollo/blob/3bc993b2ea91704bd6a2667f42d1940656c071ff/src/parser.ts
|
|
17
|
+
*/
|
|
18
|
+
export declare function graphQLDocumentNodeParser(document: DocumentNode): IDocumentDefinition;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for graphql-document-node-parser
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { DocumentNode, VariableDefinitionNode } from "./graphql-types";
|
|
9
|
+
declare export var DocumentTypes: $ReadOnly<{
|
|
10
|
+
query: "query",
|
|
11
|
+
mutation: "mutation",
|
|
12
|
+
...
|
|
13
|
+
}>;
|
|
14
|
+
export type DocumentType = $ElementType<
|
|
15
|
+
typeof DocumentTypes,
|
|
16
|
+
$Keys<typeof DocumentTypes>
|
|
17
|
+
>;
|
|
18
|
+
export interface IDocumentDefinition {
|
|
19
|
+
type: DocumentType;
|
|
20
|
+
name: string;
|
|
21
|
+
variables: $ReadOnlyArray<VariableDefinitionNode>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Parse a GraphQL document node to determine some info about it.
|
|
25
|
+
*
|
|
26
|
+
* This is based on:
|
|
27
|
+
* https://github.com/apollographql/react-apollo/blob/3bc993b2ea91704bd6a2667f42d1940656c071ff/src/parser.ts
|
|
28
|
+
*/
|
|
29
|
+
declare export function graphQLDocumentNodeParser(
|
|
30
|
+
document: DocumentNode
|
|
31
|
+
): IDocumentDefinition;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface DefinitionNode {
|
|
2
|
+
readonly kind: string;
|
|
3
|
+
}
|
|
4
|
+
export type VariableDefinitionNode = {
|
|
5
|
+
readonly kind: "VariableDefinition";
|
|
6
|
+
};
|
|
7
|
+
export interface OperationDefinitionNode extends DefinitionNode {
|
|
8
|
+
readonly kind: "OperationDefinition";
|
|
9
|
+
readonly operation: string;
|
|
10
|
+
readonly variableDefinitions: ReadonlyArray<VariableDefinitionNode>;
|
|
11
|
+
readonly name?: {
|
|
12
|
+
readonly kind: unknown;
|
|
13
|
+
readonly value: string;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export type DocumentNode = {
|
|
17
|
+
readonly kind: "Document";
|
|
18
|
+
readonly definitions: ReadonlyArray<DefinitionNode>;
|
|
19
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for graphql-types
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export interface DefinitionNode {
|
|
9
|
+
+kind: string;
|
|
10
|
+
}
|
|
11
|
+
export type VariableDefinitionNode = {
|
|
12
|
+
+kind: "VariableDefinition",
|
|
13
|
+
...
|
|
14
|
+
};
|
|
15
|
+
export type OperationDefinitionNode = {
|
|
16
|
+
+kind: "OperationDefinition",
|
|
17
|
+
+operation: string,
|
|
18
|
+
+variableDefinitions: $ReadOnlyArray<VariableDefinitionNode>,
|
|
19
|
+
+name?: {
|
|
20
|
+
+kind: mixed,
|
|
21
|
+
+value: string,
|
|
22
|
+
...
|
|
23
|
+
},
|
|
24
|
+
...
|
|
25
|
+
} & DefinitionNode;
|
|
26
|
+
export type DocumentNode = {
|
|
27
|
+
+kind: "Document",
|
|
28
|
+
+definitions: $ReadOnlyArray<DefinitionNode>,
|
|
29
|
+
...
|
|
30
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ValidCacheData, CachedResponse, ResponseCache } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Initialize the hydration cache.
|
|
4
|
+
*
|
|
5
|
+
* @param {ResponseCache} source The cache content to use for initializing the
|
|
6
|
+
* cache.
|
|
7
|
+
* @throws {Error} If the cache is already initialized.
|
|
8
|
+
*/
|
|
9
|
+
export declare const initializeHydrationCache: (source: ResponseCache) => void;
|
|
10
|
+
/**
|
|
11
|
+
* Purge cached hydration responses that match the given predicate.
|
|
12
|
+
*
|
|
13
|
+
* @param {(id: string) => boolean} [predicate] The predicate to match against
|
|
14
|
+
* the cached hydration responses. If no predicate is provided, all cached
|
|
15
|
+
* hydration responses will be purged.
|
|
16
|
+
*/
|
|
17
|
+
export declare const purgeHydrationCache: (predicate?: ((key: string, cacheEntry?: Readonly<CachedResponse<ValidCacheData>> | null | undefined) => boolean) | undefined) => void;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for hydration-cache-api
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { ValidCacheData, CachedResponse, ResponseCache } from "./types";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Initialize the hydration cache.
|
|
12
|
+
* @param {ResponseCache} source The cache content to use for initializing the
|
|
13
|
+
* cache.
|
|
14
|
+
* @throws {Error} If the cache is already initialized.
|
|
15
|
+
*/
|
|
16
|
+
declare export var initializeHydrationCache: (source: ResponseCache) => void;
|
|
17
|
+
/**
|
|
18
|
+
* Purge cached hydration responses that match the given predicate.
|
|
19
|
+
* @param {(id: string) => boolean} [predicate] The predicate to match against
|
|
20
|
+
* the cached hydration responses. If no predicate is provided, all cached
|
|
21
|
+
* hydration responses will be purged.
|
|
22
|
+
*/
|
|
23
|
+
declare export var purgeHydrationCache: (
|
|
24
|
+
predicate?:
|
|
25
|
+
| ((
|
|
26
|
+
key: string,
|
|
27
|
+
cacheEntry?: $ReadOnly<CachedResponse<ValidCacheData>> | null | void
|
|
28
|
+
) => boolean)
|
|
29
|
+
| void
|
|
30
|
+
) => void;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { GqlContext } from "./gql-types";
|
|
2
|
+
/**
|
|
3
|
+
* Construct a complete GqlContext from current defaults and a partial context.
|
|
4
|
+
*
|
|
5
|
+
* Values in the partial context that are `undefined` will be ignored.
|
|
6
|
+
* Values in the partial context that are `null` will be deleted.
|
|
7
|
+
*/
|
|
8
|
+
export declare const mergeGqlContext: <TContext extends GqlContext>(defaultContext: TContext, overrides: Partial<TContext>) => TContext;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for merge-gql-context
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { GqlContext } from "./gql-types";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Construct a complete GqlContext from current defaults and a partial context.
|
|
12
|
+
*
|
|
13
|
+
* Values in the partial context that are `undefined` will be ignored.
|
|
14
|
+
* Values in the partial context that are `null` will be deleted.
|
|
15
|
+
*/
|
|
16
|
+
declare export var mergeGqlContext: <TContext: GqlContext>(
|
|
17
|
+
defaultContext: TContext,
|
|
18
|
+
overrides: $Rest<TContext, { ... }>
|
|
19
|
+
) => TContext;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Purge all caches managed by Wonder Blocks Data.
|
|
3
|
+
*
|
|
4
|
+
* This is a convenience method that purges the shared cache and the hydration
|
|
5
|
+
* cache. It is useful for testing purposes to avoid having to reason about
|
|
6
|
+
* which caches may have been used during a given test run.
|
|
7
|
+
*/
|
|
8
|
+
export declare const purgeCaches: () => void;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for purge-caches
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Purge all caches managed by Wonder Blocks Data.
|
|
10
|
+
*
|
|
11
|
+
* This is a convenience method that purges the shared cache and the hydration
|
|
12
|
+
* cache. It is useful for testing purposes to avoid having to reason about
|
|
13
|
+
* which caches may have been used during a given test run.
|
|
14
|
+
*/
|
|
15
|
+
declare export var purgeCaches: () => void;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ResponseCache } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Fetches all tracked data requests.
|
|
4
|
+
*
|
|
5
|
+
* This is for use with the `TrackData` component during server-side rendering.
|
|
6
|
+
*
|
|
7
|
+
* @throws {Error} If executed outside of server-side rendering.
|
|
8
|
+
* @returns {Promise<void>} A promise that resolves when all tracked requests
|
|
9
|
+
* have been fetched.
|
|
10
|
+
*/
|
|
11
|
+
export declare const fetchTrackedRequests: () => Promise<ResponseCache>;
|
|
12
|
+
/**
|
|
13
|
+
* Indicate if there are tracked requests waiting to be fetched.
|
|
14
|
+
*
|
|
15
|
+
* This is used in conjunction with `TrackData`.
|
|
16
|
+
*
|
|
17
|
+
* @throws {Error} If executed outside of server-side rendering.
|
|
18
|
+
* @returns {boolean} `true` if there are unfetched tracked requests;
|
|
19
|
+
* otherwise, `false`.
|
|
20
|
+
*/
|
|
21
|
+
export declare const hasTrackedRequestsToBeFetched: () => boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Abort all in-flight requests.
|
|
24
|
+
*
|
|
25
|
+
* This aborts all requests currently inflight via our default request
|
|
26
|
+
* fulfillment.
|
|
27
|
+
*/
|
|
28
|
+
export declare const abortInflightRequests: () => void;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for request-api
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { ResponseCache } from "./types";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Fetches all tracked data requests.
|
|
12
|
+
*
|
|
13
|
+
* This is for use with the `TrackData` component during server-side rendering.
|
|
14
|
+
* @throws {Error} If executed outside of server-side rendering.
|
|
15
|
+
* @returns {Promise<void>} A promise that resolves when all tracked requests
|
|
16
|
+
* have been fetched.
|
|
17
|
+
*/
|
|
18
|
+
declare export var fetchTrackedRequests: () => Promise<ResponseCache>;
|
|
19
|
+
/**
|
|
20
|
+
* Indicate if there are tracked requests waiting to be fetched.
|
|
21
|
+
*
|
|
22
|
+
* This is used in conjunction with `TrackData`.
|
|
23
|
+
* @throws {Error} If executed outside of server-side rendering.
|
|
24
|
+
* @returns {boolean} `true` if there are unfetched tracked requests;
|
|
25
|
+
* otherwise, `false`.
|
|
26
|
+
*/
|
|
27
|
+
declare export var hasTrackedRequestsToBeFetched: () => boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Abort all in-flight requests.
|
|
30
|
+
*
|
|
31
|
+
* This aborts all requests currently inflight via our default request
|
|
32
|
+
* fulfillment.
|
|
33
|
+
*/
|
|
34
|
+
declare export var abortInflightRequests: () => void;
|