@cedarjs/web 8.0.0-canary.3681 → 8.0.0-canary.3684
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 +6 -0
- package/dist/apollo/fragmentRegistry.d.ts.map +1 -1
- package/dist/components/cell/CellOperationVariablesContext.d.ts +14 -0
- package/dist/components/cell/CellOperationVariablesContext.d.ts.map +1 -0
- package/dist/components/cell/CellOperationVariablesContext.js +16 -0
- package/dist/components/cell/createCell.d.ts.map +1 -1
- package/dist/components/cell/createCell.js +6 -2
- package/dist/components/cell/createFragmentCell.d.ts +3 -1
- package/dist/components/cell/createFragmentCell.d.ts.map +1 -1
- package/dist/components/cell/createFragmentCell.js +4 -1
- package/dist/components/cell/createSuspendingCell.d.ts.map +1 -1
- package/dist/components/cell/createSuspendingCell.js +7 -2
- package/package.json +6 -6
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { OperationVariables } from '@apollo/client';
|
|
1
2
|
import type { FragmentRegistryAPI } from '@apollo/client/cache';
|
|
2
3
|
import { useFragment as useApolloFragment } from '@apollo/client/react';
|
|
3
4
|
import type { DocumentNode } from 'graphql';
|
|
@@ -10,6 +11,11 @@ export interface FragmentHookOptions {
|
|
|
10
11
|
* identify works.
|
|
11
12
|
*/
|
|
12
13
|
from: Record<string, unknown>;
|
|
14
|
+
/**
|
|
15
|
+
* The variables of the operation the fragment is spread in. Needed when
|
|
16
|
+
* the fragment uses operation variables, like `comments(first: $count)`
|
|
17
|
+
*/
|
|
18
|
+
variables?: OperationVariables;
|
|
13
19
|
}
|
|
14
20
|
export interface FragmentHookResult<TData = any> {
|
|
15
21
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fragmentRegistry.d.ts","sourceRoot":"","sources":["../../src/apollo/fragmentRegistry.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fragmentRegistry.d.ts","sourceRoot":"","sources":["../../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;AAED;;;;;;;IAOI;AACJ,eAAO,MAAM,gBAAgB,EAAE,mBAA8C,CAAA;AAE7E;;GAEG;AACH,eAAO,MAAM,iBAAiB,GAAI,WAAW,YAAY,EAAE,6BAE1D,CAAA;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,gBAAgB,GAC3B,UAAU,YAAY,KACrB,sBAqBF,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { OperationVariables } from '@apollo/client';
|
|
3
|
+
interface ProviderProps {
|
|
4
|
+
variables: OperationVariables | undefined;
|
|
5
|
+
children?: React.ReactNode;
|
|
6
|
+
}
|
|
7
|
+
export declare const CellOperationVariablesProvider: ({ variables, children, }: ProviderProps) => React.JSX.Element;
|
|
8
|
+
/**
|
|
9
|
+
* The variables of the nearest query Cell's operation, or `undefined` when
|
|
10
|
+
* not rendered inside a query Cell.
|
|
11
|
+
*/
|
|
12
|
+
export declare function useCellOperationVariables(): OperationVariables | undefined;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=CellOperationVariablesContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CellOperationVariablesContext.d.ts","sourceRoot":"","sources":["../../../src/components/cell/CellOperationVariablesContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAoC,MAAM,OAAO,CAAA;AAExD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAqBxD,UAAU,aAAa;IACrB,SAAS,EAAE,kBAAkB,GAAG,SAAS,CAAA;IACzC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;CAC3B;AAED,eAAO,MAAM,8BAA8B,GAAI,0BAG5C,aAAa,sBAMf,CAAA;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,mCAExC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import React, { createContext, useContext } from "react";
|
|
3
|
+
const CellOperationVariablesContext = createContext(void 0);
|
|
4
|
+
const CellOperationVariablesProvider = ({
|
|
5
|
+
variables,
|
|
6
|
+
children
|
|
7
|
+
}) => {
|
|
8
|
+
return /* @__PURE__ */ jsx(CellOperationVariablesContext.Provider, { value: variables, children });
|
|
9
|
+
};
|
|
10
|
+
function useCellOperationVariables() {
|
|
11
|
+
return useContext(CellOperationVariablesContext);
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
CellOperationVariablesProvider,
|
|
15
|
+
useCellOperationVariables
|
|
16
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createCell.d.ts","sourceRoot":"","sources":["../../../src/components/cell/createCell.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"createCell.d.ts","sourceRoot":"","sources":["../../../src/components/cell/createCell.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AASxD,OAAO,KAAK,EAAE,eAAe,EAAc,MAAM,gBAAgB,CAAA;AAKjE,wBAAgB,UAAU,CACxB,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACzC,aAAa,SAAS,kBAAkB,GAAG,kBAAkB,EAC7D,SAAS,GAAG,GAAG,EAEf,eAAe,EAAE,eAAe,CAAC,SAAS,EAAE,aAAa,EAAE,SAAS,CAAC,GACpE,KAAK,CAAC,EAAE,CAAC,SAAS,CAAC,CAoCrB"}
|
|
@@ -5,6 +5,7 @@ import { useQuery } from "@apollo/client/react";
|
|
|
5
5
|
import { fragmentRegistry } from "../../apollo/fragmentRegistry.js";
|
|
6
6
|
import { getOperationName } from "../../graphql.js";
|
|
7
7
|
import { useCellCacheContext } from "./CellCacheContext.js";
|
|
8
|
+
import { CellOperationVariablesProvider } from "./CellOperationVariablesContext.js";
|
|
8
9
|
import { createFragmentCell } from "./createFragmentCell.js";
|
|
9
10
|
import { createSuspendingCell } from "./createSuspendingCell.js";
|
|
10
11
|
import { isDataEmpty } from "./isCellEmpty.js";
|
|
@@ -64,6 +65,7 @@ function createNonSuspendingCell({
|
|
|
64
65
|
data,
|
|
65
66
|
...queryResult
|
|
66
67
|
} = useQuery(query, options);
|
|
68
|
+
const operationVariables = queryResult.variables;
|
|
67
69
|
if (globalThis.__REDWOOD__PRERENDERING) {
|
|
68
70
|
const { queryCache } = useCellCacheContext();
|
|
69
71
|
if (!skipped) {
|
|
@@ -124,7 +126,8 @@ function createNonSuspendingCell({
|
|
|
124
126
|
updating: loading,
|
|
125
127
|
queryResult
|
|
126
128
|
};
|
|
127
|
-
|
|
129
|
+
const element = /* @__PURE__ */ jsx(Empty, { ...emptyProps });
|
|
130
|
+
return /* @__PURE__ */ jsx(CellOperationVariablesProvider, { variables: operationVariables, children: element });
|
|
128
131
|
} else {
|
|
129
132
|
const successProps = {
|
|
130
133
|
...props,
|
|
@@ -132,7 +135,8 @@ function createNonSuspendingCell({
|
|
|
132
135
|
updating: loading,
|
|
133
136
|
queryResult
|
|
134
137
|
};
|
|
135
|
-
|
|
138
|
+
const element = /* @__PURE__ */ jsx(Success, { ...successProps });
|
|
139
|
+
return /* @__PURE__ */ jsx(CellOperationVariablesProvider, { variables: operationVariables, children: element });
|
|
136
140
|
}
|
|
137
141
|
} else if (loading) {
|
|
138
142
|
const loadingProps = { ...props, queryResult };
|
|
@@ -13,7 +13,9 @@ import type { CreateCellProps } from './cellTypes.js';
|
|
|
13
13
|
*
|
|
14
14
|
* When the GraphQL client supports it (Apollo does), the fragment data is
|
|
15
15
|
* read from the client's cache, so the Cell re-renders when other queries or
|
|
16
|
-
* mutations update the underlying entity.
|
|
16
|
+
* mutations update the underlying entity. The cache read uses the variables
|
|
17
|
+
* of the nearest query Cell above, so fragments can use that query's
|
|
18
|
+
* variables. If the cache read is incomplete,
|
|
17
19
|
* the passed-in object itself is used as the data snapshot.
|
|
18
20
|
*/
|
|
19
21
|
export declare function createFragmentCell<CellProps extends Record<string, unknown>, CellVariables extends OperationVariables = OperationVariables, GQLResult = any>({ FRAGMENT, afterQuery, isEmpty, Empty, Success, displayName, }: CreateCellProps<CellProps, CellVariables, GQLResult>): React.FC<CellProps>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createFragmentCell.d.ts","sourceRoot":"","sources":["../../../src/components/cell/createFragmentCell.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"createFragmentCell.d.ts","sourceRoot":"","sources":["../../../src/components/cell/createFragmentCell.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAOxD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AA6ErD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACzC,aAAa,SAAS,kBAAkB,GAAG,kBAAkB,EAC7D,SAAS,GAAG,GAAG,EACf,EACA,QAAQ,EACR,UAA2B,EAC3B,OAAqB,EACrB,KAAK,EACL,OAAO,EACP,WAAoB,GACrB,EAAE,eAAe,CAAC,SAAS,EAAE,aAAa,EAAE,SAAS,CAAC,GAAG,KAAK,CAAC,EAAE,CAAC,SAAS,CAAC,CAwF5E"}
|
|
@@ -2,6 +2,7 @@ import { jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import React from "react";
|
|
3
3
|
import { Kind } from "graphql";
|
|
4
4
|
import { fragmentRegistry, useFragment } from "../../apollo/fragmentRegistry.js";
|
|
5
|
+
import { useCellOperationVariables } from "./CellOperationVariablesContext.js";
|
|
5
6
|
import { isDataEmpty } from "./isCellEmpty.js";
|
|
6
7
|
function getFragmentDefinition(fragment, displayName) {
|
|
7
8
|
const fragmentDefinition = fragment.definitions.find(
|
|
@@ -52,10 +53,12 @@ function createFragmentCell({
|
|
|
52
53
|
function NamedCell(props) {
|
|
53
54
|
const { children: _, [propName]: rawSlice, ...rest } = props;
|
|
54
55
|
const dataRef = isDataRef(rawSlice) ? rawSlice : void 0;
|
|
56
|
+
const operationVariables = useCellOperationVariables();
|
|
55
57
|
const fragmentResult = useFragment({
|
|
56
58
|
fragment,
|
|
57
59
|
fragmentName,
|
|
58
|
-
from: dataRef ?? {}
|
|
60
|
+
from: dataRef ?? {},
|
|
61
|
+
variables: operationVariables
|
|
59
62
|
});
|
|
60
63
|
if (!(propName in props)) {
|
|
61
64
|
throw new Error(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createSuspendingCell.d.ts","sourceRoot":"","sources":["../../../src/components/cell/createSuspendingCell.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAA;AAEvC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"createSuspendingCell.d.ts","sourceRoot":"","sources":["../../../src/components/cell/createSuspendingCell.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAA;AAEvC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAaxD,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,kBAAkB,GAAG,kBAAkB,EAC7D,SAAS,GAAG,GAAG,EAEf,eAAe,EAAE,eAAe,CAAC,MAAM,EAAE,aAAa,EAAE,SAAS,CAAC,GACjE,KAAK,CAAC,EAAE,CAAC,SAAS,CAAC,CAsOrB"}
|
|
@@ -6,7 +6,9 @@ import {
|
|
|
6
6
|
useBackgroundQuery,
|
|
7
7
|
useReadQuery
|
|
8
8
|
} from "@apollo/client/react";
|
|
9
|
+
import { unwrapQueryRef } from "@apollo/client/react/internal";
|
|
9
10
|
import { CellErrorBoundary } from "./CellErrorBoundary.js";
|
|
11
|
+
import { CellOperationVariablesProvider } from "./CellOperationVariablesContext.js";
|
|
10
12
|
import { isDataEmpty } from "./isCellEmpty.js";
|
|
11
13
|
function createSuspendingCell(createCellProps) {
|
|
12
14
|
const {
|
|
@@ -45,6 +47,7 @@ function createSuspendingCell(createCellProps) {
|
|
|
45
47
|
const { queryRef, suspenseQueryResult, userProps } = props;
|
|
46
48
|
const { data, networkStatus } = useReadQuery(queryRef);
|
|
47
49
|
const afterQueryData = afterQuery(data);
|
|
50
|
+
const operationVariables = unwrapQueryRef(queryRef)?.observable.variables;
|
|
48
51
|
const queryResultWithNetworkStatus = {
|
|
49
52
|
...suspenseQueryResult,
|
|
50
53
|
networkStatus
|
|
@@ -55,14 +58,16 @@ function createSuspendingCell(createCellProps) {
|
|
|
55
58
|
...afterQueryData,
|
|
56
59
|
queryResult: queryResultWithNetworkStatus
|
|
57
60
|
};
|
|
58
|
-
|
|
61
|
+
const emptyElement = /* @__PURE__ */ jsx(Empty, { ...emptyProps });
|
|
62
|
+
return /* @__PURE__ */ jsx(CellOperationVariablesProvider, { variables: operationVariables, children: emptyElement });
|
|
59
63
|
}
|
|
60
64
|
const successProps = {
|
|
61
65
|
...afterQueryData,
|
|
62
66
|
...userProps,
|
|
63
67
|
queryResult: queryResultWithNetworkStatus
|
|
64
68
|
};
|
|
65
|
-
|
|
69
|
+
const successElement = /* @__PURE__ */ jsx(Success, { ...successProps });
|
|
70
|
+
return /* @__PURE__ */ jsx(CellOperationVariablesProvider, { variables: operationVariables, children: successElement });
|
|
66
71
|
}
|
|
67
72
|
SuspendingSuccess.displayName = displayName;
|
|
68
73
|
return (props) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/web",
|
|
3
|
-
"version": "8.0.0-canary.
|
|
3
|
+
"version": "8.0.0-canary.3684",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/cedarjs/cedar.git",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
},
|
|
83
83
|
"dependencies": {
|
|
84
84
|
"@apollo/client": "4.3.8",
|
|
85
|
-
"@cedarjs/server-store": "8.0.0-canary.
|
|
85
|
+
"@cedarjs/server-store": "8.0.0-canary.3684",
|
|
86
86
|
"@dr.pogodin/react-helmet": "2.0.4",
|
|
87
87
|
"@whatwg-node/fetch": "0.12.1",
|
|
88
88
|
"apollo-upload-client": "19.0.0",
|
|
@@ -98,9 +98,9 @@
|
|
|
98
98
|
"devDependencies": {
|
|
99
99
|
"@apollo/client-react-streaming": "0.14.5",
|
|
100
100
|
"@arethetypeswrong/cli": "0.18.5",
|
|
101
|
-
"@cedarjs/auth": "8.0.0-canary.
|
|
102
|
-
"@cedarjs/framework-tools": "8.0.0-canary.
|
|
103
|
-
"@cedarjs/internal": "8.0.0-canary.
|
|
101
|
+
"@cedarjs/auth": "8.0.0-canary.3684",
|
|
102
|
+
"@cedarjs/framework-tools": "8.0.0-canary.3684",
|
|
103
|
+
"@cedarjs/internal": "8.0.0-canary.3684",
|
|
104
104
|
"@testing-library/dom": "10.4.2",
|
|
105
105
|
"@testing-library/jest-dom": "6.9.1",
|
|
106
106
|
"@testing-library/react": "16.3.3",
|
|
@@ -118,7 +118,7 @@
|
|
|
118
118
|
"vitest": "5.1.0"
|
|
119
119
|
},
|
|
120
120
|
"peerDependencies": {
|
|
121
|
-
"@cedarjs/auth": "8.0.0-canary.
|
|
121
|
+
"@cedarjs/auth": "8.0.0-canary.3684",
|
|
122
122
|
"react": "19.3.1",
|
|
123
123
|
"react-dom": "19.3.1"
|
|
124
124
|
},
|