@cedarjs/web 5.0.4-next.167 → 5.0.4
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/dist/apollo/fragmentRegistry.d.ts +0 -25
- package/dist/apollo/fragmentRegistry.d.ts.map +1 -1
- package/dist/apollo/fragmentRegistry.js +1 -19
- package/dist/apollo/index.d.ts +70 -50
- package/dist/apollo/index.d.ts.map +1 -1
- package/dist/apollo/index.js +184 -2
- package/dist/apollo/suspense.d.ts +7 -16
- package/dist/apollo/suspense.d.ts.map +1 -1
- package/dist/apollo/suspense.js +26 -9
- package/dist/apollo/typeOverride.d.ts +21 -0
- package/dist/apollo/typeOverride.d.ts.map +1 -0
- package/dist/bundled/apollo-upload-client.js +1 -2899
- package/dist/cjs/apollo/fragmentRegistry.d.ts +43 -0
- package/dist/cjs/apollo/fragmentRegistry.d.ts.map +1 -0
- package/dist/cjs/apollo/fragmentRegistry.js +75 -0
- package/dist/cjs/apollo/index.d.ts +76 -0
- package/dist/cjs/apollo/index.d.ts.map +1 -0
- package/dist/cjs/apollo/index.js +218 -0
- package/dist/cjs/apollo/links.d.ts +27 -0
- package/dist/cjs/apollo/links.d.ts.map +1 -0
- package/dist/cjs/apollo/links.js +122 -0
- package/dist/cjs/apollo/sseLink.d.ts +29 -0
- package/dist/cjs/apollo/sseLink.d.ts.map +1 -0
- package/dist/cjs/apollo/sseLink.js +120 -0
- package/dist/{apollo/apolloLinkTypes.d.ts → cjs/apollo/suspense.d.ts} +22 -22
- package/dist/cjs/apollo/suspense.d.ts.map +1 -0
- package/dist/cjs/apollo/suspense.js +127 -0
- package/dist/cjs/apollo/typeOverride.d.ts +21 -0
- package/dist/cjs/apollo/typeOverride.d.ts.map +1 -0
- package/dist/cjs/apollo/typeOverride.js +16 -0
- package/dist/cjs/apollo/useCache.d.ts +22 -0
- package/dist/cjs/apollo/useCache.d.ts.map +1 -0
- package/dist/cjs/apollo/useCache.js +49 -0
- package/dist/cjs/bins/cedar.d.ts +9 -0
- package/dist/cjs/bins/cedar.d.ts.map +1 -0
- package/dist/cjs/bins/cedar.js +36 -0
- package/dist/cjs/bins/cfw.d.ts +3 -0
- package/dist/cjs/bins/cfw.d.ts.map +1 -0
- package/dist/cjs/bins/cfw.js +36 -0
- package/dist/cjs/bins/cross-env.d.ts +3 -0
- package/dist/cjs/bins/cross-env.d.ts.map +1 -0
- package/dist/cjs/bins/cross-env.js +30 -0
- package/dist/cjs/bins/msw.d.ts +3 -0
- package/dist/cjs/bins/msw.d.ts.map +1 -0
- package/dist/cjs/bins/msw.js +28 -0
- package/dist/cjs/bins/redwood.d.ts +9 -0
- package/dist/cjs/bins/redwood.d.ts.map +1 -0
- package/dist/cjs/bins/redwood.js +36 -0
- package/dist/cjs/bins/storybook.d.ts +3 -0
- package/dist/cjs/bins/storybook.d.ts.map +1 -0
- package/dist/cjs/bins/storybook.js +49 -0
- package/dist/cjs/bins/tsc.d.ts +3 -0
- package/dist/cjs/bins/tsc.d.ts.map +1 -0
- package/dist/cjs/bins/tsc.js +30 -0
- package/dist/cjs/bundled/apollo-upload-client.d.ts +3 -0
- package/dist/cjs/bundled/apollo-upload-client.d.ts.map +1 -0
- package/dist/cjs/bundled/apollo-upload-client.js +2925 -0
- package/dist/cjs/components/DevFatalErrorPage.d.ts +21 -0
- package/dist/cjs/components/DevFatalErrorPage.d.ts.map +1 -0
- package/dist/cjs/components/DevFatalErrorPage.js +552 -0
- package/dist/cjs/components/FatalErrorBoundary.d.ts +24 -0
- package/dist/cjs/components/FatalErrorBoundary.d.ts.map +1 -0
- package/dist/cjs/components/FatalErrorBoundary.js +63 -0
- package/dist/cjs/components/FetchConfigProvider.d.ts +25 -0
- package/dist/cjs/components/FetchConfigProvider.d.ts.map +1 -0
- package/dist/cjs/components/FetchConfigProvider.js +80 -0
- package/dist/cjs/components/GraphQLHooksProvider.d.ts +45 -0
- package/dist/cjs/components/GraphQLHooksProvider.d.ts.map +1 -0
- package/dist/cjs/components/GraphQLHooksProvider.js +135 -0
- package/dist/cjs/components/MetaTags.d.ts +52 -0
- package/dist/cjs/components/MetaTags.d.ts.map +1 -0
- package/dist/cjs/components/MetaTags.js +68 -0
- package/dist/cjs/components/Metadata.d.ts +9 -0
- package/dist/cjs/components/Metadata.d.ts.map +1 -0
- package/dist/cjs/components/Metadata.js +94 -0
- package/dist/cjs/components/PortalHead.d.ts +4 -0
- package/dist/cjs/components/PortalHead.d.ts.map +1 -0
- package/dist/cjs/components/PortalHead.js +59 -0
- package/dist/cjs/components/RedwoodProvider.d.ts +9 -0
- package/dist/cjs/components/RedwoodProvider.d.ts.map +1 -0
- package/dist/cjs/components/RedwoodProvider.js +57 -0
- package/dist/cjs/components/ServerInject.d.ts +26 -0
- package/dist/cjs/components/ServerInject.d.ts.map +1 -0
- package/dist/cjs/components/ServerInject.js +75 -0
- package/dist/cjs/components/cell/CellCacheContext.d.ts +20 -0
- package/dist/cjs/components/cell/CellCacheContext.d.ts.map +1 -0
- package/dist/cjs/components/cell/CellCacheContext.js +53 -0
- package/dist/cjs/components/cell/CellErrorBoundary.d.ts +25 -0
- package/dist/cjs/components/cell/CellErrorBoundary.d.ts.map +1 -0
- package/dist/cjs/components/cell/CellErrorBoundary.js +66 -0
- package/dist/cjs/components/cell/cellTypes.d.ts +152 -0
- package/dist/cjs/components/cell/cellTypes.d.ts.map +1 -0
- package/dist/cjs/components/cell/cellTypes.js +16 -0
- package/dist/cjs/components/cell/createCell.d.ts +10 -0
- package/dist/cjs/components/cell/createCell.d.ts.map +1 -0
- package/dist/cjs/components/cell/createCell.js +165 -0
- package/dist/cjs/components/cell/createCell.test.js +351 -0
- package/dist/cjs/components/cell/createServerCell.d.ts +15 -0
- package/dist/cjs/components/cell/createServerCell.d.ts.map +1 -0
- package/dist/cjs/components/cell/createServerCell.js +91 -0
- package/dist/cjs/components/cell/createSuspendingCell.d.ts +11 -0
- package/dist/cjs/components/cell/createSuspendingCell.d.ts.map +1 -0
- package/dist/cjs/components/cell/createSuspendingCell.js +152 -0
- package/dist/cjs/components/cell/createSuspendingCell.test.js +115 -0
- package/dist/cjs/components/cell/isCellEmpty.d.ts +41 -0
- package/dist/cjs/components/cell/isCellEmpty.d.ts.map +1 -0
- package/dist/cjs/components/cell/isCellEmpty.js +35 -0
- package/dist/cjs/components/htmlTags.d.ts +52 -0
- package/dist/cjs/components/htmlTags.d.ts.map +1 -0
- package/dist/cjs/components/htmlTags.js +88 -0
- package/dist/cjs/config.d.ts +2 -0
- package/dist/cjs/config.d.ts.map +1 -0
- package/dist/cjs/config.js +6 -0
- package/dist/cjs/global.web-auto-imports.d.ts +30 -0
- package/dist/cjs/global.web-auto-imports.d.ts.map +1 -0
- package/dist/cjs/global.web-auto-imports.js +16 -0
- package/dist/cjs/graphql.d.ts +23 -0
- package/dist/cjs/graphql.d.ts.map +1 -0
- package/dist/cjs/graphql.js +36 -0
- package/dist/cjs/index.d.ts +19 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +69 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/routeHooks.types.d.ts +12 -0
- package/dist/cjs/routeHooks.types.d.ts.map +1 -0
- package/dist/cjs/routeHooks.types.js +16 -0
- package/dist/cjs/server/MiddlewareRequest.d.ts +28 -0
- package/dist/cjs/server/MiddlewareRequest.d.ts.map +1 -0
- package/dist/cjs/server/MiddlewareRequest.js +71 -0
- package/dist/cjs/server/MiddlewareResponse.d.ts +44 -0
- package/dist/cjs/server/MiddlewareResponse.d.ts.map +1 -0
- package/dist/cjs/server/MiddlewareResponse.js +130 -0
- package/dist/cjs/server/middleware.d.ts +17 -0
- package/dist/cjs/server/middleware.d.ts.map +1 -0
- package/dist/cjs/server/middleware.js +24 -0
- package/dist/cjs/server/request.d.ts +2 -0
- package/dist/cjs/server/request.d.ts.map +1 -0
- package/dist/cjs/server/request.js +34 -0
- package/dist/cjs/streamUtils/useDocumentReady.d.ts +11 -0
- package/dist/cjs/streamUtils/useDocumentReady.d.ts.map +1 -0
- package/dist/cjs/streamUtils/useDocumentReady.js +41 -0
- package/dist/cjs/toast/index.d.ts +3 -0
- package/dist/cjs/toast/index.d.ts.map +1 -0
- package/dist/cjs/toast/index.js +41 -0
- package/dist/components/FetchConfigProvider.d.ts +2 -3
- package/dist/components/FetchConfigProvider.d.ts.map +1 -1
- package/dist/components/GraphQLHooksProvider.d.ts +45 -0
- package/dist/components/GraphQLHooksProvider.d.ts.map +1 -0
- package/dist/components/GraphQLHooksProvider.js +94 -0
- package/dist/components/cell/CellErrorBoundary.d.ts +2 -3
- package/dist/components/cell/CellErrorBoundary.d.ts.map +1 -1
- package/dist/components/cell/cellTypes.d.ts +4 -17
- package/dist/components/cell/cellTypes.d.ts.map +1 -1
- package/dist/components/cell/createCell.d.ts +7 -1
- package/dist/components/cell/createCell.d.ts.map +1 -1
- package/dist/components/cell/createCell.js +3 -22
- package/dist/components/cell/createCell.test.js +328 -0
- package/dist/components/cell/createSuspendingCell.d.ts.map +1 -1
- package/dist/components/cell/createSuspendingCell.js +3 -12
- package/dist/components/cell/createSuspendingCell.test.js +92 -0
- package/dist/global.web-auto-imports.d.ts +16 -0
- package/dist/global.web-auto-imports.d.ts.map +1 -1
- package/dist/index.d.ts +2 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -5
- package/dist/package.json +1 -0
- package/package.json +106 -48
- package/dist/apollo/ApolloProviderWithFetchConfig.d.ts +0 -15
- package/dist/apollo/ApolloProviderWithFetchConfig.d.ts.map +0 -1
- package/dist/apollo/ApolloProviderWithFetchConfig.js +0 -134
- package/dist/apollo/CedarApolloProvider.d.ts +0 -14
- package/dist/apollo/CedarApolloProvider.d.ts.map +0 -1
- package/dist/apollo/CedarApolloProvider.js +0 -35
- package/dist/apollo/ErrorBoundary.d.ts +0 -13
- package/dist/apollo/ErrorBoundary.d.ts.map +0 -1
- package/dist/apollo/ErrorBoundary.js +0 -13
- package/dist/apollo/apolloLinkTypes.d.ts.map +0 -1
- package/dist/bins/cedar.js +0 -14
- package/dist/bins/cfw.js +0 -14
- package/dist/bins/cross-env.js +0 -8
- package/dist/bins/msw.js +0 -6
- package/dist/bins/redwood.js +0 -14
- package/dist/bins/storybook.js +0 -27
- package/dist/bins/tsc.js +0 -8
- package/dist/components/cell/createFragmentCell.d.ts +0 -19
- package/dist/components/cell/createFragmentCell.d.ts.map +0 -1
- package/dist/components/cell/createFragmentCell.js +0 -73
- /package/dist/apollo/{apolloLinkTypes.js → typeOverride.js} +0 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { OperationVariables, useBackgroundQuery as apolloUseBackgroundQuery, useReadQuery as apolloUseReadQuery } from '@apollo/client';
|
|
3
|
+
import type { TypedDocumentNode } from '@graphql-typed-document-node/core';
|
|
4
|
+
import type { DocumentNode } from 'graphql';
|
|
5
|
+
export type { TypedDocumentNode };
|
|
6
|
+
/**
|
|
7
|
+
* @NOTE
|
|
8
|
+
* The types QueryOperationResult, MutationOperationResult, SubscriptionOperationResult, and SuspenseQueryOperationResult
|
|
9
|
+
* are overridden in packages/web/src/apollo/typeOverride.ts. This was originally so that you could bring your own gql client.
|
|
10
|
+
*
|
|
11
|
+
* The default (empty) types are defined in packages/web/src/global.web-auto-imports.ts
|
|
12
|
+
*
|
|
13
|
+
* Do not import types for hooks directly from Apollo here, unless it is an Apollo specific hook.
|
|
14
|
+
*/
|
|
15
|
+
type DefaultUseQueryType = <TData = any, TVariables extends OperationVariables = GraphQLOperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: GraphQLQueryHookOptions<TData, TVariables>) => QueryOperationResult<TData, TVariables>;
|
|
16
|
+
type DefaultUseMutationType = <TData = any, TVariables = GraphQLOperationVariables>(mutation: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: GraphQLMutationHookOptions<TData, TVariables>) => MutationOperationResult<TData, TVariables>;
|
|
17
|
+
type DefaultUseSubscriptionType = <TData = any, TVariables extends OperationVariables = GraphQLOperationVariables>(subscription: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: GraphQLSubscriptionHookOptions<TData, TVariables>) => SubscriptionOperationResult<TData, TVariables>;
|
|
18
|
+
type DefaultUseSuspenseType = <TData = any, TVariables extends OperationVariables = GraphQLOperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: GraphQLSuspenseQueryHookOptions<TData, TVariables>) => SuspenseQueryOperationResult<TData, TVariables>;
|
|
19
|
+
export interface GraphQLHooks<TuseQuery = DefaultUseQueryType, TuseMutation = DefaultUseMutationType, TuseSubscription = DefaultUseSubscriptionType, TuseSuspenseQuery = DefaultUseSuspenseType> {
|
|
20
|
+
useQuery: TuseQuery;
|
|
21
|
+
useMutation: TuseMutation;
|
|
22
|
+
useSubscription: TuseSubscription;
|
|
23
|
+
useSuspenseQuery: TuseSuspenseQuery;
|
|
24
|
+
useBackgroundQuery: typeof apolloUseBackgroundQuery;
|
|
25
|
+
useReadQuery: typeof apolloUseReadQuery;
|
|
26
|
+
}
|
|
27
|
+
export declare const GraphQLHooksContext: React.Context<GraphQLHooks<DefaultUseQueryType, DefaultUseMutationType, DefaultUseSubscriptionType, DefaultUseSuspenseType>>;
|
|
28
|
+
interface GraphQlHooksProviderProps<TuseQuery = DefaultUseQueryType, TuseMutation = DefaultUseMutationType, TuseSubscription = DefaultUseSubscriptionType, TuseSuspenseQuery = DefaultUseSuspenseType> extends GraphQLHooks<TuseQuery, TuseMutation, TuseSubscription, TuseSuspenseQuery> {
|
|
29
|
+
children: React.ReactNode;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* GraphQLHooksProvider stores standard `useQuery` and `useMutation` hooks for Redwood
|
|
33
|
+
* that can be mapped to your GraphQL library of choice's own `useQuery`
|
|
34
|
+
* and `useMutation` implementation.
|
|
35
|
+
*
|
|
36
|
+
* @todo Let the user pass in the additional type for options.
|
|
37
|
+
*/
|
|
38
|
+
export declare const GraphQLHooksProvider: <TuseQuery extends DefaultUseQueryType, TuseMutation extends DefaultUseMutationType>({ useQuery, useMutation, useSubscription, useSuspenseQuery, useBackgroundQuery, useReadQuery, children, }: GraphQlHooksProviderProps<TuseQuery, TuseMutation>) => React.JSX.Element;
|
|
39
|
+
export declare function useQuery<TData = any, TVariables extends OperationVariables = GraphQLOperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: GraphQLQueryHookOptions<TData, TVariables>): QueryOperationResult<TData, TVariables>;
|
|
40
|
+
export declare function useMutation<TData = any, TVariables = GraphQLOperationVariables>(mutation: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: GraphQLMutationHookOptions<TData, TVariables>): MutationOperationResult<TData, TVariables>;
|
|
41
|
+
export declare function useSubscription<TData = any, TVariables extends OperationVariables = GraphQLOperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: GraphQLSubscriptionHookOptions<TData, TVariables>): SubscriptionOperationResult<TData, TVariables>;
|
|
42
|
+
export declare function useSuspenseQuery<TData = any, TVariables extends OperationVariables = GraphQLOperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: GraphQLSuspenseQueryHookOptions<TData, TVariables>): SuspenseQueryOperationResult<TData, TVariables>;
|
|
43
|
+
export declare const useBackgroundQuery: typeof apolloUseBackgroundQuery<any>;
|
|
44
|
+
export declare const useReadQuery: typeof apolloUseReadQuery;
|
|
45
|
+
//# sourceMappingURL=GraphQLHooksProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GraphQLHooksProvider.d.ts","sourceRoot":"","sources":["../../src/components/GraphQLHooksProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EACV,kBAAkB,EAClB,kBAAkB,IAAI,wBAAwB,EAC9C,YAAY,IAAI,kBAAkB,EACnC,MAAM,gBAAgB,CAAA;AACvB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAA;AAC1E,OAAO,KAAK,E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E,UAAU,CAAC,GACtD,uBAAuB,CAAC,KAAK,EAAE,UAAU,CAAC,CAK5C;AAED,wBAAgB,eAAe,CAC7B,KAAK,GAAG,GAAG,EACX,UAAU,SAAS,kBAAkB,GAAG,yBAAyB,EAEjE,KAAK,EAAE,YAAY,GAAG,iBAAiB,CAAC,KAAK,EAAE,UAAU,CAAC,EAC1D,OAAO,CAAC,EAAE,8BAA8B,CAAC,KAAK,EAAE,UAAU,CAAC,GAC1D,2BAA2B,CAAC,KAAK,EAAE,UAAU,CAAC,CAKhD;AAED,wBAAgB,gBAAgB,CAC9B,KAAK,GAAG,GAAG,EACX,UAAU,SAAS,kBAAkB,GAAG,yBAAyB,EAEjE,KAAK,EAAE,YAAY,GAAG,iBAAiB,CAAC,KAAK,EAAE,UAAU,CAAC,EAC1D,OAAO,CAAC,EAAE,+BAA+B,CAAC,KAAK,EAAE,UAAU,CAAC,GAC3D,4BAA4B,CAAC,KAAK,EAAE,UAAU,CAAC,CAKjD;AAED,eAAO,MAAM,kBAAkB,EAAE,OAAO,wBAAwB,CAAC,GAAG,CAOnE,CAAA;AAED,eAAO,MAAM,YAAY,EAAE,OAAO,kBAEjC,CAAA"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
const GraphQLHooksContext = React.createContext({
|
|
3
|
+
useQuery: () => {
|
|
4
|
+
throw new Error(
|
|
5
|
+
"You must register a useQuery hook via the `GraphQLHooksProvider`"
|
|
6
|
+
);
|
|
7
|
+
},
|
|
8
|
+
useMutation: () => {
|
|
9
|
+
throw new Error(
|
|
10
|
+
"You must register a useMutation hook via the `GraphQLHooksProvider`"
|
|
11
|
+
);
|
|
12
|
+
},
|
|
13
|
+
useSubscription: () => {
|
|
14
|
+
throw new Error(
|
|
15
|
+
"You must register a useSubscription hook via the `GraphQLHooksProvider`"
|
|
16
|
+
);
|
|
17
|
+
},
|
|
18
|
+
useSuspenseQuery: () => {
|
|
19
|
+
throw new Error(
|
|
20
|
+
"You must register a useSuspenseQuery hook via the `GraphQLHooksProvider`."
|
|
21
|
+
);
|
|
22
|
+
},
|
|
23
|
+
// These are apollo specific hooks!
|
|
24
|
+
useBackgroundQuery: () => {
|
|
25
|
+
throw new Error(
|
|
26
|
+
"You must register a useBackgroundQuery hook via the `GraphQLHooksProvider`."
|
|
27
|
+
);
|
|
28
|
+
},
|
|
29
|
+
useReadQuery: () => {
|
|
30
|
+
throw new Error(
|
|
31
|
+
"You must register a useReadQuery hook via the `GraphQLHooksProvider`."
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
const GraphQLHooksProvider = ({
|
|
36
|
+
useQuery: useQuery2,
|
|
37
|
+
useMutation: useMutation2,
|
|
38
|
+
useSubscription: useSubscription2,
|
|
39
|
+
useSuspenseQuery: useSuspenseQuery2,
|
|
40
|
+
useBackgroundQuery: useBackgroundQuery2,
|
|
41
|
+
useReadQuery: useReadQuery2,
|
|
42
|
+
children
|
|
43
|
+
}) => {
|
|
44
|
+
return /* @__PURE__ */ React.createElement(
|
|
45
|
+
GraphQLHooksContext.Provider,
|
|
46
|
+
{
|
|
47
|
+
value: {
|
|
48
|
+
useQuery: useQuery2,
|
|
49
|
+
useMutation: useMutation2,
|
|
50
|
+
useSubscription: useSubscription2,
|
|
51
|
+
useSuspenseQuery: useSuspenseQuery2,
|
|
52
|
+
useBackgroundQuery: useBackgroundQuery2,
|
|
53
|
+
useReadQuery: useReadQuery2
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
children
|
|
57
|
+
);
|
|
58
|
+
};
|
|
59
|
+
function useQuery(query, options) {
|
|
60
|
+
return React.useContext(GraphQLHooksContext).useQuery(
|
|
61
|
+
query,
|
|
62
|
+
options
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
function useMutation(mutation, options) {
|
|
66
|
+
return React.useContext(GraphQLHooksContext).useMutation(
|
|
67
|
+
mutation,
|
|
68
|
+
options
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
function useSubscription(query, options) {
|
|
72
|
+
return React.useContext(GraphQLHooksContext).useSubscription(query, options);
|
|
73
|
+
}
|
|
74
|
+
function useSuspenseQuery(query, options) {
|
|
75
|
+
return React.useContext(GraphQLHooksContext).useSuspenseQuery(query, options);
|
|
76
|
+
}
|
|
77
|
+
const useBackgroundQuery = (...args) => {
|
|
78
|
+
return React.useContext(GraphQLHooksContext).useBackgroundQuery(
|
|
79
|
+
...args
|
|
80
|
+
);
|
|
81
|
+
};
|
|
82
|
+
const useReadQuery = (...args) => {
|
|
83
|
+
return React.useContext(GraphQLHooksContext).useReadQuery(...args);
|
|
84
|
+
};
|
|
85
|
+
export {
|
|
86
|
+
GraphQLHooksContext,
|
|
87
|
+
GraphQLHooksProvider,
|
|
88
|
+
useBackgroundQuery,
|
|
89
|
+
useMutation,
|
|
90
|
+
useQuery,
|
|
91
|
+
useReadQuery,
|
|
92
|
+
useSubscription,
|
|
93
|
+
useSuspenseQuery
|
|
94
|
+
};
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type { QueryResult } from '@apollo/client';
|
|
3
2
|
import type { CellFailureProps } from './cellTypes.js';
|
|
4
3
|
export type FallbackProps = {
|
|
5
|
-
error:
|
|
4
|
+
error: QueryOperationResult['error'];
|
|
6
5
|
resetErrorBoundary: () => void;
|
|
7
6
|
};
|
|
8
7
|
export type CellErrorBoundaryProps = {
|
|
@@ -11,7 +10,7 @@ export type CellErrorBoundaryProps = {
|
|
|
11
10
|
};
|
|
12
11
|
interface ErrState {
|
|
13
12
|
hasError: boolean;
|
|
14
|
-
error?:
|
|
13
|
+
error?: QueryOperationResult['error'];
|
|
15
14
|
}
|
|
16
15
|
export declare class CellErrorBoundary extends React.Component<CellErrorBoundaryProps, ErrState> {
|
|
17
16
|
constructor(props: CellErrorBoundaryProps);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CellErrorBoundary.d.ts","sourceRoot":"","sources":["../../../src/components/cell/CellErrorBoundary.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"CellErrorBoundary.d.ts","sourceRoot":"","sources":["../../../src/components/cell/CellErrorBoundary.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAEtD,MAAM,MAAM,aAAa,GAAG;IAC1B,KAAK,EAAE,oBAAoB,CAAC,OAAO,CAAC,CAAA;IACpC,kBAAkB,EAAE,MAAM,IAAI,CAAA;CAC/B,CAAA;AAED,MAAM,MAAM,sBAAsB,GAAG;IAGnC,cAAc,EAAE,CACd,OAAO,EAAE,aAAa,KACnB,KAAK,CAAC,YAAY,CAAC,gBAAgB,CAAC,CAAA;IACzC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAC1B,CAAA;AAED,UAAU,QAAQ;IAChB,QAAQ,EAAE,OAAO,CAAA;IACjB,KAAK,CAAC,EAAE,oBAAoB,CAAC,OAAO,CAAC,CAAA;CACtC;AAED,qBAAa,iBAAkB,SAAQ,KAAK,CAAC,SAAS,CACpD,sBAAsB,EACtB,QAAQ,CACT;gBACa,KAAK,EAAE,sBAAsB;IAKzC,MAAM,CAAC,wBAAwB,CAAC,KAAK,EAAE,KAAK;;;;IAI5C,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS;IAQ1D,MAAM;CAgBP"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ComponentProps, JSXElementConstructor } from 'react';
|
|
2
|
-
import type { ApolloClient, NetworkStatus, OperationVariables, QueryRef,
|
|
2
|
+
import type { ApolloClient, NetworkStatus, OperationVariables, QueryRef, UseBackgroundQueryResult } from '@apollo/client';
|
|
3
3
|
import type { DocumentNode } from 'graphql';
|
|
4
4
|
import type { A, L, O, U } from 'ts-toolbelt';
|
|
5
5
|
/**
|
|
@@ -27,7 +27,7 @@ export type CellLoadingProps<TVariables extends OperationVariables = any> = {
|
|
|
27
27
|
} & InputVarProps<TVariables>;
|
|
28
28
|
export type CellFailureProps<TVariables extends OperationVariables = any> = {
|
|
29
29
|
queryResult?: NonSuspenseCellQueryResult<TVariables, any> | SuspenseCellQueryResult;
|
|
30
|
-
error?:
|
|
30
|
+
error?: QueryOperationResult['error'] | Error;
|
|
31
31
|
/**
|
|
32
32
|
* @see {@link https://www.apollographql.com/docs/apollo-server/data/errors/#error-codes}
|
|
33
33
|
*/
|
|
@@ -80,21 +80,8 @@ export interface CreateCellProps<CellProps, CellVariables> {
|
|
|
80
80
|
/**
|
|
81
81
|
* The GraphQL syntax tree to execute or function to call that returns it.
|
|
82
82
|
* If `QUERY` is a function, it's called with the result of `beforeQuery`.
|
|
83
|
-
*
|
|
84
|
-
* Either `QUERY` or `FRAGMENT` must be provided.
|
|
85
|
-
*/
|
|
86
|
-
QUERY?: DocumentNode | ((variables: Record<string, unknown>) => DocumentNode);
|
|
87
|
-
/**
|
|
88
|
-
* A GraphQL fragment that declares this Cell's data requirements. Fragment
|
|
89
|
-
* Cells don't fire their own query. Instead a parent Cell spreads the
|
|
90
|
-
* fragment in its `QUERY` and passes the fetched data object down via a
|
|
91
|
-
* prop named after the fragment (`AuthorCell_author` -> `author`). The
|
|
92
|
-
* fragment is automatically registered with the GraphQL client's fragment
|
|
93
|
-
* registry, so parent queries can spread it by name.
|
|
94
|
-
*
|
|
95
|
-
* Either `QUERY` or `FRAGMENT` must be provided.
|
|
96
83
|
*/
|
|
97
|
-
|
|
84
|
+
QUERY: DocumentNode | ((variables: Record<string, unknown>) => DocumentNode);
|
|
98
85
|
/**
|
|
99
86
|
* Parse `props` into query variables. Most of the time `props` are appropriate variables as is.
|
|
100
87
|
*/
|
|
@@ -155,7 +142,7 @@ export type SuspendingSuccessProps = React.PropsWithChildren<Record<string, unkn
|
|
|
155
142
|
suspenseQueryResult: SuspenseCellQueryResult<DataObject, any>;
|
|
156
143
|
userProps: Record<string, any>;
|
|
157
144
|
};
|
|
158
|
-
export type NonSuspenseCellQueryResult<TVariables extends OperationVariables = any, TData = any> = Partial<Omit<
|
|
145
|
+
export type NonSuspenseCellQueryResult<TVariables extends OperationVariables = any, TData = any> = Partial<Omit<QueryOperationResult<TData, TVariables>, 'loading' | 'error' | 'data'>>;
|
|
159
146
|
export interface SuspenseCellQueryResult<_TData = any, _TVariables extends OperationVariables = any> extends UseBackgroundQueryResult {
|
|
160
147
|
client: ApolloClient<any>;
|
|
161
148
|
networkStatus?: NetworkStatus;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cellTypes.d.ts","sourceRoot":"","sources":["../../../src/components/cell/cellTypes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,OAAO,CAAA;AAElE,OAAO,KAAK,EACV,YAAY,EACZ,aAAa,EACb,kBAAkB,EAClB,QAAQ,EACR,
|
|
1
|
+
{"version":3,"file":"cellTypes.d.ts","sourceRoot":"","sources":["../../../src/components/cell/cellTypes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,OAAO,CAAA;AAElE,OAAO,KAAK,EACV,YAAY,EACZ,aAAa,EACb,kBAAkB,EAClB,QAAQ,EACR,wBAAwB,EACzB,MAAM,gBAAgB,CAAA;AACvB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAC3C,OAAO,KAAK,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,aAAa,CAAA;AAE7C;;;;;;;;;GASG;AACH,KAAK,kBAAkB,CAAC,IAAI,EAAE,YAAY,IAAI,IAAI,SAAS;IACzD,WAAW,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAA;CAC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C7D,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CAC/B,CAAA;AAED,MAAM,MAAM,0BAA0B,CACpC,UAAU,SAAS,kBAAkB,GAAG,GAAG,EAC3C,KAAK,GAAG,GAAG,IACT,OAAO,CACT,IAAI,CAAC,oBAAoB,CAAC,KAAK,EAAE,UAAU,CAAC,EAAE,SAAS,GAAG,OAAO,GAAG,MAAM,CAAC,CAC5E,CAAA;AAID,MAAM,WAAW,uBAAuB,CACtC,MAAM,GAAG,GAAG,EACZ,WAAW,SAAS,kBAAkB,GAAG,GAAG,CAC5C,SAAQ,wBAAwB;IAChC,MAAM,EAAE,YAAY,CAAC,GAAG,CAAC,CAAA;IAEzB,aAAa,CAAC,EAAE,aAAa,CAAA;IAC7B,MAAM,EAAE,OAAO,CAAA;CAChB"}
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { CreateCellProps } from './cellTypes.js';
|
|
3
|
-
|
|
3
|
+
import { createSuspendingCell } from './createSuspendingCell.js';
|
|
4
|
+
export declare const createCell: typeof createSuspendingCell | typeof createNonSuspendingCell;
|
|
5
|
+
/**
|
|
6
|
+
* Creates a Cell out of a GraphQL query and components that track to its lifecycle.
|
|
7
|
+
*/
|
|
8
|
+
declare function createNonSuspendingCell<CellProps extends Record<string, unknown>, CellVariables extends Record<string, unknown>>({ QUERY, beforeQuery, afterQuery, isEmpty, Loading, Failure, Empty, Success, displayName, }: CreateCellProps<CellProps, CellVariables>): React.FC<CellProps>;
|
|
9
|
+
export {};
|
|
4
10
|
//# sourceMappingURL=createCell.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createCell.d.ts","sourceRoot":"","sources":["../../../src/components/cell/createCell.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"createCell.d.ts","sourceRoot":"","sources":["../../../src/components/cell/createCell.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAUzB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AACrD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AAIhE,eAAO,MAAM,UAAU,8DAEI,CAAA;AAE3B;;GAEG;AACH,iBAAS,uBAAuB,CAC9B,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACzC,aAAa,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7C,EACA,KAAK,EACL,WAWE,EACF,UAA2B,EAC3B,OAAqB,EACrB,OAA+B,EAC/B,OAAO,EACP,KAAK,EACL,OAAO,EACP,WAAoB,GACrB,EAAE,eAAe,CAAC,SAAS,EAAE,aAAa,CAAC,GAAG,KAAK,CAAC,EAAE,CAAC,SAAS,CAAC,CAuIjE"}
|
|
@@ -1,24 +1,11 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { useQuery } from "@apollo/client/react/hooks/hooks.cjs";
|
|
3
2
|
import { fragmentRegistry } from "../../apollo/fragmentRegistry.js";
|
|
4
3
|
import { getOperationName } from "../../graphql.js";
|
|
4
|
+
import { useQuery } from "../GraphQLHooksProvider.js";
|
|
5
5
|
import { useCellCacheContext } from "./CellCacheContext.js";
|
|
6
|
-
import { createFragmentCell } from "./createFragmentCell.js";
|
|
7
6
|
import { createSuspendingCell } from "./createSuspendingCell.js";
|
|
8
7
|
import { isDataEmpty } from "./isCellEmpty.js";
|
|
9
|
-
|
|
10
|
-
if (createCellProps.FRAGMENT) {
|
|
11
|
-
if (!createCellProps.QUERY) {
|
|
12
|
-
return createFragmentCell(createCellProps);
|
|
13
|
-
}
|
|
14
|
-
fragmentRegistry.register(createCellProps.FRAGMENT);
|
|
15
|
-
}
|
|
16
|
-
if (RWJS_ENV.RWJS_EXP_STREAMING_SSR) {
|
|
17
|
-
const suspendingCellProps = createCellProps;
|
|
18
|
-
return createSuspendingCell(suspendingCellProps);
|
|
19
|
-
}
|
|
20
|
-
return createNonSuspendingCell(createCellProps);
|
|
21
|
-
}
|
|
8
|
+
const createCell = RWJS_ENV.RWJS_EXP_STREAMING_SSR ? createSuspendingCell : createNonSuspendingCell;
|
|
22
9
|
function createNonSuspendingCell({
|
|
23
10
|
QUERY,
|
|
24
11
|
beforeQuery = (props) => ({
|
|
@@ -41,16 +28,10 @@ function createNonSuspendingCell({
|
|
|
41
28
|
Success,
|
|
42
29
|
displayName = "Cell"
|
|
43
30
|
}) {
|
|
44
|
-
if (!QUERY) {
|
|
45
|
-
throw new Error(
|
|
46
|
-
`Can't create a Cell (${displayName}) without a QUERY or FRAGMENT export`
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
const cellQuery = QUERY;
|
|
50
31
|
function NamedCell(props) {
|
|
51
32
|
const { children: _, ...variables } = props;
|
|
52
33
|
const options = beforeQuery(variables);
|
|
53
|
-
const query = typeof
|
|
34
|
+
const query = typeof QUERY === "function" ? QUERY(options) : QUERY;
|
|
54
35
|
let {
|
|
55
36
|
// eslint-disable-next-line prefer-const
|
|
56
37
|
error,
|
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render, screen } from "@testing-library/react";
|
|
3
|
+
import { vi, describe, beforeAll, test, expect } from "vitest";
|
|
4
|
+
import { GraphQLHooksProvider } from "../GraphQLHooksProvider.js";
|
|
5
|
+
import { createCell } from "./createCell.js";
|
|
6
|
+
describe("createCell", () => {
|
|
7
|
+
beforeAll(() => {
|
|
8
|
+
globalThis.RWJS_ENV = {
|
|
9
|
+
RWJS_EXP_STREAMING_SSR: false
|
|
10
|
+
};
|
|
11
|
+
});
|
|
12
|
+
test("Renders a static Success component", () => {
|
|
13
|
+
const TestCell = createCell({
|
|
14
|
+
// @ts-expect-error - Purposefully using a plain string here.
|
|
15
|
+
QUERY: "query TestQuery { answer }",
|
|
16
|
+
Success: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Great success!")
|
|
17
|
+
});
|
|
18
|
+
const myUseQueryHook = () => ({ data: {} });
|
|
19
|
+
render(
|
|
20
|
+
/* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, null))
|
|
21
|
+
);
|
|
22
|
+
screen.getByText(/^Great success!$/);
|
|
23
|
+
});
|
|
24
|
+
test("Renders Success with data", () => {
|
|
25
|
+
const TestCell = createCell({
|
|
26
|
+
// @ts-expect-error - Purposefully using a plain string here.
|
|
27
|
+
QUERY: "query TestQuery { answer }",
|
|
28
|
+
Success: ({ answer }) => /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("dl", null, /* @__PURE__ */ React.createElement("dt", null, "What's the meaning of life?"), /* @__PURE__ */ React.createElement("dd", null, answer)))
|
|
29
|
+
});
|
|
30
|
+
const myUseQueryHook = () => {
|
|
31
|
+
return { data: { answer: 42 } };
|
|
32
|
+
};
|
|
33
|
+
render(
|
|
34
|
+
/* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, null))
|
|
35
|
+
);
|
|
36
|
+
screen.getByText(/^What's the meaning of life\?$/);
|
|
37
|
+
screen.getByText(/^42$/);
|
|
38
|
+
});
|
|
39
|
+
test("Renders Success if any of the fields have data (i.e. not just the first)", () => {
|
|
40
|
+
const TestCell = createCell({
|
|
41
|
+
// @ts-expect-error - Purposefully using a plain string here.
|
|
42
|
+
QUERY: "query TestQuery { users { name } posts { title } }",
|
|
43
|
+
Empty: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "No users or posts"),
|
|
44
|
+
Success: ({ users, posts }) => /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", null, users.length > 0 ? /* @__PURE__ */ React.createElement("ul", null, users.map(({ name }) => /* @__PURE__ */ React.createElement("li", { key: name }, name))) : "no users"), /* @__PURE__ */ React.createElement("div", null, posts.length > 0 ? /* @__PURE__ */ React.createElement("ul", null, posts.map(({ title }) => /* @__PURE__ */ React.createElement("li", { key: title }, title))) : "no posts"))
|
|
45
|
+
});
|
|
46
|
+
const myUseQueryHook = () => {
|
|
47
|
+
return {
|
|
48
|
+
data: {
|
|
49
|
+
users: [],
|
|
50
|
+
posts: [{ title: "bazinga" }, { title: "kittens" }]
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
render(
|
|
55
|
+
/* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, null))
|
|
56
|
+
);
|
|
57
|
+
screen.getByText(/bazinga/);
|
|
58
|
+
screen.getByText(/kittens/);
|
|
59
|
+
});
|
|
60
|
+
test("Renders default Loading when there is no data", () => {
|
|
61
|
+
const TestCell = createCell({
|
|
62
|
+
// @ts-expect-error - Purposefully using a plain string here.
|
|
63
|
+
QUERY: "query TestQuery { answer }",
|
|
64
|
+
Success: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Great success!")
|
|
65
|
+
});
|
|
66
|
+
const myUseQueryHook = () => ({ loading: true });
|
|
67
|
+
render(
|
|
68
|
+
/* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, null))
|
|
69
|
+
);
|
|
70
|
+
screen.getByText(/^Loading...$/);
|
|
71
|
+
});
|
|
72
|
+
test("Renders custom Loading when there is no data", () => {
|
|
73
|
+
const TestCell = createCell({
|
|
74
|
+
// @ts-expect-error - Purposefully using a plain string here.
|
|
75
|
+
QUERY: "query TestQuery { answer }",
|
|
76
|
+
Success: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Great success!"),
|
|
77
|
+
Loading: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Fetching answer...")
|
|
78
|
+
});
|
|
79
|
+
const myUseQueryHook = () => ({ loading: true });
|
|
80
|
+
render(
|
|
81
|
+
/* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, null))
|
|
82
|
+
);
|
|
83
|
+
screen.getByText(/^Fetching answer...$/);
|
|
84
|
+
});
|
|
85
|
+
test("Renders Success even when `loading` is true if there is data", () => {
|
|
86
|
+
const TestCell = createCell({
|
|
87
|
+
// @ts-expect-error - Purposefully using a plain string here.
|
|
88
|
+
QUERY: "query TestQuery { answer }",
|
|
89
|
+
Success: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Great success!"),
|
|
90
|
+
Loading: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Fetching answer...")
|
|
91
|
+
});
|
|
92
|
+
const myUseQueryHook = () => ({ loading: true, data: {} });
|
|
93
|
+
render(
|
|
94
|
+
/* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, null))
|
|
95
|
+
);
|
|
96
|
+
screen.getByText(/^Great success!$/);
|
|
97
|
+
});
|
|
98
|
+
test("Renders Empty if available, and data field is null", () => {
|
|
99
|
+
const TestCell = createCell({
|
|
100
|
+
// @ts-expect-error - Purposefully using a plain string here.
|
|
101
|
+
QUERY: "query TestQuery { answer }",
|
|
102
|
+
Success: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Great success!"),
|
|
103
|
+
Empty: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "No one knows")
|
|
104
|
+
});
|
|
105
|
+
const myUseQueryHook = () => ({ loading: true, data: { answer: null } });
|
|
106
|
+
render(
|
|
107
|
+
/* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, null))
|
|
108
|
+
);
|
|
109
|
+
screen.getByText(/^No one knows$/);
|
|
110
|
+
});
|
|
111
|
+
test("Renders Empty if available, and data field is an empty array", () => {
|
|
112
|
+
const TestCell = createCell({
|
|
113
|
+
// @ts-expect-error - Purposefully using a plain string here.
|
|
114
|
+
QUERY: "query TestQuery { answers }",
|
|
115
|
+
Success: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Great success!"),
|
|
116
|
+
Empty: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "No one knows")
|
|
117
|
+
});
|
|
118
|
+
const myUseQueryHook = () => ({ loading: true, data: { answers: [] } });
|
|
119
|
+
render(
|
|
120
|
+
/* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, null))
|
|
121
|
+
);
|
|
122
|
+
screen.getByText(/^No one knows$/);
|
|
123
|
+
});
|
|
124
|
+
test("Renders Success even if data is empty when no Empty is available", () => {
|
|
125
|
+
const TestCell = createCell({
|
|
126
|
+
// @ts-expect-error - Purposefully using a plain string here.
|
|
127
|
+
QUERY: "query TestQuery { answer }",
|
|
128
|
+
Success: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Empty success")
|
|
129
|
+
});
|
|
130
|
+
const myUseQueryHook = () => ({ loading: true, data: { answer: null } });
|
|
131
|
+
render(
|
|
132
|
+
/* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, null))
|
|
133
|
+
);
|
|
134
|
+
screen.getByText(/^Empty success$/);
|
|
135
|
+
});
|
|
136
|
+
test("Allows passing children to Success", () => {
|
|
137
|
+
const TestCell = createCell({
|
|
138
|
+
// @ts-expect-error - Purposefully using a plain string here.
|
|
139
|
+
QUERY: "query TestQuery { answer }",
|
|
140
|
+
Success: ({ children }) => /* @__PURE__ */ React.createElement(React.Fragment, null, "Look at my beautiful ", children)
|
|
141
|
+
});
|
|
142
|
+
const myUseQueryHook = () => ({ data: {} });
|
|
143
|
+
render(
|
|
144
|
+
/* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, null, /* @__PURE__ */ React.createElement("div", null, "\u{1F986}")))
|
|
145
|
+
);
|
|
146
|
+
screen.getByText(/^Look at my beautiful$/);
|
|
147
|
+
screen.getByText(/^🦆$/);
|
|
148
|
+
});
|
|
149
|
+
test("Cell props are passed to the query as variables", () => {
|
|
150
|
+
const TestCell = createCell({
|
|
151
|
+
// @ts-expect-error - Purposefully using a plain string here.
|
|
152
|
+
QUERY: `query Greet($name: String!) {
|
|
153
|
+
greet(name: $name) {
|
|
154
|
+
greeting
|
|
155
|
+
}
|
|
156
|
+
}`,
|
|
157
|
+
Success: ({ greeting }) => /* @__PURE__ */ React.createElement("p", null, greeting)
|
|
158
|
+
});
|
|
159
|
+
const myUseQueryHook = (_query, options) => {
|
|
160
|
+
return { data: { greeting: `Hello ${options.variables.name}!` } };
|
|
161
|
+
};
|
|
162
|
+
render(
|
|
163
|
+
/* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, { name: "Bob" }))
|
|
164
|
+
);
|
|
165
|
+
screen.getByText(/^Hello Bob!$/);
|
|
166
|
+
});
|
|
167
|
+
test("Allows QUERY to be a function", () => {
|
|
168
|
+
const TestCell = createCell({
|
|
169
|
+
// @ts-expect-error - Purposefully using a plain string here.
|
|
170
|
+
QUERY: ({ variables }) => {
|
|
171
|
+
if (variables.character === "BEAST") {
|
|
172
|
+
return "query BeastQuery { name }";
|
|
173
|
+
}
|
|
174
|
+
return "query HeroQuery { name }";
|
|
175
|
+
},
|
|
176
|
+
Success: ({ name }) => /* @__PURE__ */ React.createElement("p", null, "Call me ", name)
|
|
177
|
+
});
|
|
178
|
+
const myUseQueryHook = (query) => {
|
|
179
|
+
if (query.includes("BeastQuery")) {
|
|
180
|
+
return { data: { name: "Boogeyman" } };
|
|
181
|
+
} else if (query.includes("HeroQuery")) {
|
|
182
|
+
return { data: { name: "Lara Croft" } };
|
|
183
|
+
}
|
|
184
|
+
return { data: { name: "John Doe" } };
|
|
185
|
+
};
|
|
186
|
+
render(
|
|
187
|
+
/* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, { character: "BEAST" }), /* @__PURE__ */ React.createElement(TestCell, { character: "HERO" }))
|
|
188
|
+
);
|
|
189
|
+
screen.getByText(/^Call me Boogeyman$/);
|
|
190
|
+
screen.getByText(/^Call me Lara Croft$/);
|
|
191
|
+
});
|
|
192
|
+
test("Renders Failure when there is an error", () => {
|
|
193
|
+
const TestCell = createCell({
|
|
194
|
+
// @ts-expect-error - Purposefully using a plain string here.
|
|
195
|
+
QUERY: "query TestQuery { answer }",
|
|
196
|
+
Failure: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Sad face :("),
|
|
197
|
+
Success: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Great success!"),
|
|
198
|
+
Loading: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Fetching answer...")
|
|
199
|
+
});
|
|
200
|
+
const myUseQueryHook = () => ({ error: true });
|
|
201
|
+
render(
|
|
202
|
+
/* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, null))
|
|
203
|
+
);
|
|
204
|
+
screen.getByText(/^Sad face :\($/);
|
|
205
|
+
});
|
|
206
|
+
test("Passes error to Failure component", () => {
|
|
207
|
+
const TestCell = createCell({
|
|
208
|
+
// @ts-expect-error - Purposefully using a plain string here.
|
|
209
|
+
QUERY: "query TestQuery { answer }",
|
|
210
|
+
Failure: ({ error }) => /* @__PURE__ */ React.createElement(React.Fragment, null, JSON.stringify(error)),
|
|
211
|
+
Success: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Great success!"),
|
|
212
|
+
Loading: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Fetching answer...")
|
|
213
|
+
});
|
|
214
|
+
const myUseQueryHook = () => ({ error: { msg: "System malfunction" } });
|
|
215
|
+
render(
|
|
216
|
+
/* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, null))
|
|
217
|
+
);
|
|
218
|
+
screen.getByText(/^{"msg":"System malfunction"}$/);
|
|
219
|
+
});
|
|
220
|
+
test("Passes error and errorCode to Failure component", () => {
|
|
221
|
+
const TestCell = createCell({
|
|
222
|
+
// @ts-expect-error - Purposefully using a plain string here.
|
|
223
|
+
QUERY: "query TestQuery { answer }",
|
|
224
|
+
Failure: ({ error, errorCode }) => /* @__PURE__ */ React.createElement(React.Fragment, null, JSON.stringify(error), ",code:", errorCode),
|
|
225
|
+
Success: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Great success!"),
|
|
226
|
+
Loading: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Fetching answer...")
|
|
227
|
+
});
|
|
228
|
+
const myUseQueryHook = () => ({
|
|
229
|
+
error: { msg: "System malfunction" },
|
|
230
|
+
errorCode: "SIMON_SAYS_NO"
|
|
231
|
+
});
|
|
232
|
+
render(
|
|
233
|
+
/* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, null))
|
|
234
|
+
);
|
|
235
|
+
screen.getByText(/^{"msg":"System malfunction"},code:SIMON_SAYS_NO$/);
|
|
236
|
+
});
|
|
237
|
+
test("Passes children to Failure", () => {
|
|
238
|
+
const TestCell = createCell({
|
|
239
|
+
// @ts-expect-error - Purposefully using a plain string here.
|
|
240
|
+
QUERY: "query TestQuery { answer }",
|
|
241
|
+
Failure: ({ children }) => /* @__PURE__ */ React.createElement(React.Fragment, null, "I'm a failure ", children)
|
|
242
|
+
});
|
|
243
|
+
const myUseQueryHook = () => ({ error: {} });
|
|
244
|
+
render(
|
|
245
|
+
/* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, null, /* @__PURE__ */ React.createElement("div", null, "Child")))
|
|
246
|
+
);
|
|
247
|
+
screen.getByText(/^I'm a failure$/);
|
|
248
|
+
screen.getByText(/^Child$/);
|
|
249
|
+
});
|
|
250
|
+
test("Throws an error when there is an error if no Failure component exists", () => {
|
|
251
|
+
const TestCell = createCell({
|
|
252
|
+
// @ts-expect-error - Purposefully using a plain string here.
|
|
253
|
+
QUERY: "query TestQuery { answer }",
|
|
254
|
+
Success: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Great success!"),
|
|
255
|
+
Loading: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Fetching answer...")
|
|
256
|
+
});
|
|
257
|
+
const myUseQueryHook = () => ({ error: { message: "200 GraphQL" } });
|
|
258
|
+
const err = console.error;
|
|
259
|
+
console.error = vi.fn();
|
|
260
|
+
let error;
|
|
261
|
+
try {
|
|
262
|
+
render(
|
|
263
|
+
/* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, null))
|
|
264
|
+
);
|
|
265
|
+
} catch (e) {
|
|
266
|
+
error = e;
|
|
267
|
+
}
|
|
268
|
+
expect(error.message).toEqual("200 GraphQL");
|
|
269
|
+
console.error = err;
|
|
270
|
+
});
|
|
271
|
+
test("Allows overriding of default isDataEmpty", () => {
|
|
272
|
+
const TestCell = createCell({
|
|
273
|
+
// @ts-expect-error - Purposefully using a plain string here.
|
|
274
|
+
QUERY: "query TestQuery { answer }",
|
|
275
|
+
Success: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Great success!"),
|
|
276
|
+
Empty: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Got nothing"),
|
|
277
|
+
isEmpty: () => true
|
|
278
|
+
});
|
|
279
|
+
const myUseQueryHook = () => ({
|
|
280
|
+
data: {},
|
|
281
|
+
loading: false
|
|
282
|
+
});
|
|
283
|
+
render(
|
|
284
|
+
/* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, null))
|
|
285
|
+
);
|
|
286
|
+
screen.getByText(/^Got nothing$/);
|
|
287
|
+
});
|
|
288
|
+
test("Allows mixing isDataEmpty with custom logic", () => {
|
|
289
|
+
const TestCell = createCell({
|
|
290
|
+
// @ts-expect-error - Purposefully using a plain string here.
|
|
291
|
+
QUERY: "query TestQuery { answer }",
|
|
292
|
+
Success: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Great success!"),
|
|
293
|
+
Empty: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Got nothing"),
|
|
294
|
+
isEmpty: (data, { isDataEmpty }) => isDataEmpty(data) || data.answer === "0"
|
|
295
|
+
});
|
|
296
|
+
const myUseQueryHook = () => ({
|
|
297
|
+
data: { answer: "0" },
|
|
298
|
+
loading: false
|
|
299
|
+
});
|
|
300
|
+
render(
|
|
301
|
+
/* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, null))
|
|
302
|
+
);
|
|
303
|
+
screen.getByText(/^Got nothing$/);
|
|
304
|
+
});
|
|
305
|
+
test("Allows overriding variables in beforeQuery", () => {
|
|
306
|
+
const TestCell = createCell({
|
|
307
|
+
// @ts-expect-error - Purposefully using a plain string here.
|
|
308
|
+
QUERY: `query Greet($name: String!) {
|
|
309
|
+
greet(name: $name) {
|
|
310
|
+
greeting
|
|
311
|
+
}
|
|
312
|
+
}`,
|
|
313
|
+
Success: ({ greeting }) => /* @__PURE__ */ React.createElement("p", null, greeting),
|
|
314
|
+
beforeQuery: () => ({
|
|
315
|
+
variables: {
|
|
316
|
+
name: "Bob"
|
|
317
|
+
}
|
|
318
|
+
})
|
|
319
|
+
});
|
|
320
|
+
const myUseQueryHook = (_query, options) => {
|
|
321
|
+
return { data: { greeting: `Hello ${options.variables.name}!` } };
|
|
322
|
+
};
|
|
323
|
+
render(
|
|
324
|
+
/* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, null))
|
|
325
|
+
);
|
|
326
|
+
screen.getByText(/^Hello Bob!$/);
|
|
327
|
+
});
|
|
328
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createSuspendingCell.d.ts","sourceRoot":"","sources":["../../../src/components/cell/createSuspendingCell.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"createSuspendingCell.d.ts","sourceRoot":"","sources":["../../../src/components/cell/createSuspendingCell.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAA;AAYvC,OAAO,KAAK,EACV,eAAe,EAIhB,MAAM,gBAAgB,CAAA;AAGvB,KAAK,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AACrC;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,SAAS,SAAS,MAAM,EACxB,aAAa,SAAS,MAAM,EAE5B,eAAe,EAAE,eAAe,CAAC,MAAM,EAAE,aAAa,CAAC,GACtD,KAAK,CAAC,EAAE,CAAC,SAAS,CAAC,CAqIrB"}
|