@cedarjs/web 6.0.0-canary.2851 → 6.0.0-canary.2853
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/components/cell/cellTypes.d.ts +32 -7
- package/dist/components/cell/cellTypes.d.ts.map +1 -1
- package/dist/components/cell/createCell.js +32 -25
- package/dist/components/cell/createSuspendingCell.d.ts.map +1 -1
- package/dist/components/cell/createSuspendingCell.js +15 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/package.json +6 -6
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ComponentProps, JSXElementConstructor } from 'react';
|
|
2
2
|
import type { ApolloClient, NetworkStatus, OperationVariables } from '@apollo/client';
|
|
3
|
-
import type { QueryRef, useBackgroundQuery, useQuery } from '@apollo/client/react';
|
|
3
|
+
import type { QueryRef, SkipToken, useBackgroundQuery, useQuery } from '@apollo/client/react';
|
|
4
4
|
import type { DocumentNode } from 'graphql';
|
|
5
5
|
import type { A, L, O, U } from 'ts-toolbelt';
|
|
6
6
|
/**
|
|
@@ -74,6 +74,32 @@ export type CellSuccessProps<TData = any, TVariables extends OperationVariables
|
|
|
74
74
|
export type DataObject = {
|
|
75
75
|
[key: string]: unknown;
|
|
76
76
|
};
|
|
77
|
+
/**
|
|
78
|
+
* What `beforeQuery` returns is handed straight to the GraphQL client's query
|
|
79
|
+
* hook, so any of that hook's options can be set here.
|
|
80
|
+
*/
|
|
81
|
+
export type CellBeforeQueryOptions<CellVariables> = {
|
|
82
|
+
variables: CellVariables;
|
|
83
|
+
} & Omit<useQuery.Options<DataObject, OperationVariables>, 'variables'>;
|
|
84
|
+
/**
|
|
85
|
+
* `beforeQuery` can return `skipToken` instead of an options object to keep the
|
|
86
|
+
* query from being executed at all. A skipped Cell renders nothing -- none of
|
|
87
|
+
* `Loading`, `Empty`, `Failure` or `Success` are rendered.
|
|
88
|
+
*
|
|
89
|
+
* @see {@link https://www.apollographql.com/docs/react/api/react/hooks#skiptoken}
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* import { skipToken } from '@apollo/client/react'
|
|
94
|
+
*
|
|
95
|
+
* export const beforeQuery = ({ id }) => {
|
|
96
|
+
* const otherId = useStore((state) => state.getOther(id))
|
|
97
|
+
*
|
|
98
|
+
* return otherId ? { variables: { id, otherId } } : skipToken
|
|
99
|
+
* }
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
export type CellBeforeQueryResult<CellVariables> = CellBeforeQueryOptions<CellVariables> | SkipToken;
|
|
77
103
|
/**
|
|
78
104
|
* The main interface.
|
|
79
105
|
*/
|
|
@@ -98,12 +124,11 @@ export interface CreateCellProps<CellProps, CellVariables> {
|
|
|
98
124
|
FRAGMENT?: DocumentNode;
|
|
99
125
|
/**
|
|
100
126
|
* Parse `props` into query variables. Most of the time `props` are appropriate variables as is.
|
|
127
|
+
*
|
|
128
|
+
* Any other option the GraphQL client's query hook accepts can be returned
|
|
129
|
+
* here as well. Return `skipToken` to not execute the query at all.
|
|
101
130
|
*/
|
|
102
|
-
beforeQuery?: ((props: CellProps) =>
|
|
103
|
-
variables: CellVariables;
|
|
104
|
-
}) | (() => {
|
|
105
|
-
variables: CellVariables;
|
|
106
|
-
});
|
|
131
|
+
beforeQuery?: ((props: CellProps) => CellBeforeQueryResult<CellVariables>) | (() => CellBeforeQueryResult<CellVariables>);
|
|
107
132
|
/**
|
|
108
133
|
* Sanitize the data returned from the query.
|
|
109
134
|
*/
|
|
@@ -157,7 +182,7 @@ export type SuspendingSuccessProps = React.PropsWithChildren<Record<string, unkn
|
|
|
157
182
|
userProps: Record<string, any>;
|
|
158
183
|
};
|
|
159
184
|
export type NonSuspenseCellQueryResult<TVariables extends OperationVariables = any, TData = any> = Partial<Omit<useQuery.Result<TData, TVariables>, 'loading' | 'error' | 'data'>>;
|
|
160
|
-
export interface SuspenseCellQueryResult<_TData = any, _TVariables extends OperationVariables = any> extends useBackgroundQuery.Result {
|
|
185
|
+
export interface SuspenseCellQueryResult<_TData = any, _TVariables extends OperationVariables = any> extends useBackgroundQuery.Result<DataObject> {
|
|
161
186
|
client: ApolloClient;
|
|
162
187
|
networkStatus?: NetworkStatus;
|
|
163
188
|
called: boolean;
|
|
@@ -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,EACnB,MAAM,gBAAgB,CAAA;AACvB,OAAO,KAAK,EACV,QAAQ,EACR,kBAAkB,EAClB,QAAQ,EACT,MAAM,sBAAsB,CAAA;AAC7B,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;CACrC,GACG,UAAU,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,OAAO,GAChD,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACvB,UAAU,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,GACpC,YAAY,SAAS,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,GACxC,OAAO,GACP,YAAY,CAAA;AAElB;;GAEG;AACH,MAAM,MAAM,SAAS,CACnB,WAAW,SAAS,MAAM,GAAG,CAAC,iBAAiB,GAAG,qBAAqB,CAAC,GAAG,CAAC,EAC5E,SAAS,EACT,Q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AAa,CAAC,EAAE,aAAa,CAAA;IAC7B,MAAM,EAAE,OAAO,CAAA;CAChB"}
|
|
@@ -51,7 +51,9 @@ function createNonSuspendingCell({
|
|
|
51
51
|
function NamedCell(props) {
|
|
52
52
|
const { children: _, ...variables } = props;
|
|
53
53
|
const options = beforeQuery(variables);
|
|
54
|
-
const
|
|
54
|
+
const queryOptions = typeof options === "symbol" ? void 0 : options;
|
|
55
|
+
const skipped = !queryOptions || queryOptions.skip === true;
|
|
56
|
+
const query = typeof cellQuery === "function" ? cellQuery(queryOptions ?? {}) : cellQuery;
|
|
55
57
|
let {
|
|
56
58
|
// eslint-disable-next-line prefer-const
|
|
57
59
|
error,
|
|
@@ -61,34 +63,39 @@ function createNonSuspendingCell({
|
|
|
61
63
|
} = useQuery(query, options);
|
|
62
64
|
if (globalThis.__REDWOOD__PRERENDERING) {
|
|
63
65
|
const { queryCache } = useCellCacheContext();
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const cellName = displayName === "Cell" ? "the cell" : displayName;
|
|
71
|
-
throw new Error(
|
|
72
|
-
`The gql query in ${cellName} is missing an operation name. Something like FindBlogPostQuery in \`query FindBlogPostQuery($id: Int!)\``
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
const queryInfo = queryCache[cacheKey];
|
|
76
|
-
if (queryInfo?.renderLoading) {
|
|
77
|
-
loading = true;
|
|
78
|
-
} else {
|
|
79
|
-
if (queryInfo?.hasProcessed) {
|
|
80
|
-
loading = false;
|
|
81
|
-
data = queryInfo.data;
|
|
82
|
-
queryResult = { variables };
|
|
66
|
+
if (!skipped) {
|
|
67
|
+
const operationName = getOperationName(query);
|
|
68
|
+
const transformedQuery = fragmentRegistry.transform(query);
|
|
69
|
+
let cacheKey;
|
|
70
|
+
if (operationName) {
|
|
71
|
+
cacheKey = operationName + "_" + JSON.stringify(variables);
|
|
83
72
|
} else {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
73
|
+
const cellName = displayName === "Cell" ? "the cell" : displayName;
|
|
74
|
+
throw new Error(
|
|
75
|
+
`The gql query in ${cellName} is missing an operation name. Something like FindBlogPostQuery in \`query FindBlogPostQuery($id: Int!)\``
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
const queryInfo = queryCache[cacheKey];
|
|
79
|
+
if (queryInfo?.renderLoading) {
|
|
80
|
+
loading = true;
|
|
81
|
+
} else {
|
|
82
|
+
if (queryInfo?.hasProcessed) {
|
|
83
|
+
loading = false;
|
|
84
|
+
data = queryInfo.data;
|
|
85
|
+
queryResult = { variables };
|
|
86
|
+
} else {
|
|
87
|
+
queryCache[cacheKey] ||= {
|
|
88
|
+
query: transformedQuery,
|
|
89
|
+
variables: queryOptions.variables,
|
|
90
|
+
hasProcessed: false
|
|
91
|
+
};
|
|
92
|
+
}
|
|
89
93
|
}
|
|
90
94
|
}
|
|
91
95
|
}
|
|
96
|
+
if (skipped) {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
92
99
|
if (error) {
|
|
93
100
|
if (Failure) {
|
|
94
101
|
return /* @__PURE__ */ React.createElement(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createSuspendingCell.d.ts","sourceRoot":"","sources":["../../../src/components/cell/createSuspendingCell.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAA;AAavC,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"createSuspendingCell.d.ts","sourceRoot":"","sources":["../../../src/components/cell/createSuspendingCell.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAA;AAavC,OAAO,KAAK,EAEV,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,CAyMrB"}
|
|
@@ -10,6 +10,10 @@ import { isDataEmpty } from "./isCellEmpty.js";
|
|
|
10
10
|
function createSuspendingCell(createCellProps) {
|
|
11
11
|
const {
|
|
12
12
|
QUERY,
|
|
13
|
+
// Unlike in createCell this is destructured from a variable rather than
|
|
14
|
+
// from an annotated parameter, so the default's return type has to be
|
|
15
|
+
// spelled out. Without it the inferred object literal type widens the
|
|
16
|
+
// union and options like `skip` are no longer visible on it
|
|
13
17
|
beforeQuery = (props) => ({
|
|
14
18
|
// By default, we assume that the props are the gql-variables.
|
|
15
19
|
variables: props,
|
|
@@ -67,9 +71,18 @@ function createSuspendingCell(createCellProps) {
|
|
|
67
71
|
return (props) => {
|
|
68
72
|
const { children: _, ...variables } = props;
|
|
69
73
|
const options = beforeQuery(variables);
|
|
70
|
-
const
|
|
71
|
-
const
|
|
74
|
+
const queryOptions = typeof options === "symbol" ? void 0 : options;
|
|
75
|
+
const skipped = !queryOptions || queryOptions.skip === true;
|
|
76
|
+
const query = typeof cellQuery === "function" ? cellQuery(queryOptions ?? {}) : cellQuery;
|
|
77
|
+
const backgroundQueryOptions = options;
|
|
78
|
+
const [queryRef, other] = useBackgroundQuery(
|
|
79
|
+
query,
|
|
80
|
+
backgroundQueryOptions
|
|
81
|
+
);
|
|
72
82
|
const client = useApolloClient();
|
|
83
|
+
if (skipped || !queryRef) {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
73
86
|
const suspenseQueryResult = {
|
|
74
87
|
client,
|
|
75
88
|
...other,
|
package/dist/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export type { FragmentHookOptions, FragmentHookResult, } from './apollo/fragment
|
|
|
8
8
|
export * from './components/cell/CellCacheContext.js';
|
|
9
9
|
export { createCell } from './components/cell/createCell.js';
|
|
10
10
|
export { createFragmentCell } from './components/cell/createFragmentCell.js';
|
|
11
|
-
export type { CellProps, CellFailureProps, CellLoadingProps, CellSuccessProps, CellSuccessData, } from './components/cell/cellTypes.js';
|
|
11
|
+
export type { CellProps, CellFailureProps, CellLoadingProps, CellSuccessProps, CellSuccessData, CellBeforeQueryOptions, CellBeforeQueryResult, } from './components/cell/cellTypes.js';
|
|
12
12
|
export * from './graphql.js';
|
|
13
13
|
export * from './components/RedwoodProvider.js';
|
|
14
14
|
export * from './components/MetaTags.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,8BAA8B,CAAA;AACrC,OAAO,aAAa,CAAA;AAEpB,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAA;AAEvE,OAAO,EACL,mBAAmB,EACnB,cAAc,GACf,MAAM,qCAAqC,CAAA;AAC5C,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAC7E,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAA;AAC1D,YAAY,EACV,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,8BAA8B,CAAA;AAErC,cAAc,uCAAuC,CAAA;AAErD,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAA;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAA;AAE5E,YAAY,EACV,SAAS,EACT,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,8BAA8B,CAAA;AACrC,OAAO,aAAa,CAAA;AAEpB,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAA;AAEvE,OAAO,EACL,mBAAmB,EACnB,cAAc,GACf,MAAM,qCAAqC,CAAA;AAC5C,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAC7E,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAA;AAC1D,YAAY,EACV,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,8BAA8B,CAAA;AAErC,cAAc,uCAAuC,CAAA;AAErD,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAA;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAA;AAE5E,YAAY,EACV,SAAS,EACT,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,gCAAgC,CAAA;AAEvC,cAAc,cAAc,CAAA;AAE5B,cAAc,iCAAiC,CAAA;AAE/C,cAAc,0BAA0B,CAAA;AACxC,cAAc,0BAA0B,CAAA;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAA;AACjD,OAAO,EAAE,MAAM,IAAI,IAAI,EAAE,MAAM,EAAE,CAAA;AAEjC,cAAc,0BAA0B,CAAA;AACxC,cAAc,uBAAuB,CAAA;AAErC,cAAc,8BAA8B,CAAA;AAE5C,YAAY,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/web",
|
|
3
|
-
"version": "6.0.0-canary.
|
|
3
|
+
"version": "6.0.0-canary.2853",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/cedarjs/cedar.git",
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
},
|
|
82
82
|
"dependencies": {
|
|
83
83
|
"@apollo/client": "4.2.7",
|
|
84
|
-
"@cedarjs/server-store": "6.0.0-canary.
|
|
84
|
+
"@cedarjs/server-store": "6.0.0-canary.2853",
|
|
85
85
|
"@dr.pogodin/react-helmet": "2.0.4",
|
|
86
86
|
"@whatwg-node/fetch": "0.10.13",
|
|
87
87
|
"apollo-upload-client": "19.0.0",
|
|
@@ -101,9 +101,9 @@
|
|
|
101
101
|
"@babel/core": "^7.26.10",
|
|
102
102
|
"@babel/plugin-transform-runtime": "7.29.7",
|
|
103
103
|
"@babel/runtime": "7.29.7",
|
|
104
|
-
"@cedarjs/auth": "6.0.0-canary.
|
|
105
|
-
"@cedarjs/framework-tools": "6.0.0-canary.
|
|
106
|
-
"@cedarjs/internal": "6.0.0-canary.
|
|
104
|
+
"@cedarjs/auth": "6.0.0-canary.2853",
|
|
105
|
+
"@cedarjs/framework-tools": "6.0.0-canary.2853",
|
|
106
|
+
"@cedarjs/internal": "6.0.0-canary.2853",
|
|
107
107
|
"@rollup/plugin-babel": "6.1.0",
|
|
108
108
|
"@testing-library/dom": "10.4.1",
|
|
109
109
|
"@testing-library/jest-dom": "6.9.1",
|
|
@@ -121,7 +121,7 @@
|
|
|
121
121
|
"vitest": "4.1.10"
|
|
122
122
|
},
|
|
123
123
|
"peerDependencies": {
|
|
124
|
-
"@cedarjs/auth": "6.0.0-canary.
|
|
124
|
+
"@cedarjs/auth": "6.0.0-canary.2853",
|
|
125
125
|
"react": "19.2.3",
|
|
126
126
|
"react-dom": "19.2.3"
|
|
127
127
|
},
|