@cedarjs/web 8.0.0-canary.3583 → 8.0.0-canary.3588

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.
@@ -135,7 +135,7 @@ export interface CreateCellProps<CellProps, CellVariables extends OperationVaria
135
135
  * A GraphQL fragment that declares this Cell's data requirements. Fragment
136
136
  * Cells don't fire their own query. Instead a parent Cell spreads the
137
137
  * fragment in its `QUERY` and passes the fetched data object down via a
138
- * prop named after the fragment (`AuthorCell_author` -> `author`). The
138
+ * prop named after the fragment (`AuthorCellFragment on User` -> `user`). The
139
139
  * fragment is automatically registered with the GraphQL client's fragment
140
140
  * registry, so parent queries can spread it by name.
141
141
  *
@@ -7,7 +7,7 @@ import type { CreateCellProps } from './cellTypes.js';
7
7
  *
8
8
  * Fragment Cells don't fire queries of their own. A parent Cell spreads the
9
9
  * fragment in its QUERY and passes the matching slice of the query result
10
- * down via a prop named after the fragment (`AuthorCell_author` -> `author`).
10
+ * down via a prop named after the fragment (see `getFragmentPropName`).
11
11
  * `Success` receives the data as that same prop. The data is read
12
12
  * synchronously, so fragment Cells never render `Loading`.
13
13
  *
@@ -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;AAMxD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAqDrD;;;;;;;;;;;;;;GAcG;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,CAiF5E"}
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;AAMxD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AA6ErD;;;;;;;;;;;;;;GAcG;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,CAiF5E"}
@@ -8,17 +8,22 @@ function getFragmentDefinition(fragment, displayName) {
8
8
  );
9
9
  if (!fragmentDefinition) {
10
10
  throw new Error(
11
- `The FRAGMENT export in ${displayName} must contain a GraphQL fragment definition, like \`fragment AuthorCell_author on User { fullName }\``
11
+ `The FRAGMENT export in ${displayName} must contain a GraphQL fragment definition, like \`fragment AuthorCellFragment on User { fullName }\``
12
12
  );
13
13
  }
14
14
  return fragmentDefinition;
15
15
  }
16
- function getFragmentPropName(fragmentDefinition) {
16
+ function getFragmentPropName(fragmentDefinition, cellName) {
17
17
  const fragmentName = fragmentDefinition.name.value;
18
18
  const underscoreIndex = fragmentName.lastIndexOf("_");
19
19
  if (underscoreIndex > 0 && underscoreIndex < fragmentName.length - 1) {
20
20
  return fragmentName.slice(underscoreIndex + 1);
21
21
  }
22
+ const cellFragmentPrefix = cellName + "Fragment";
23
+ const propNameSuffix = fragmentName.slice(cellFragmentPrefix.length);
24
+ if (fragmentName.startsWith(cellFragmentPrefix) && /^[A-Z]/.test(propNameSuffix)) {
25
+ return propNameSuffix.charAt(0).toLowerCase() + propNameSuffix.slice(1);
26
+ }
22
27
  const typename = fragmentDefinition.typeCondition.name.value;
23
28
  return typename.charAt(0).toLowerCase() + typename.slice(1);
24
29
  }
@@ -41,7 +46,7 @@ function createFragmentCell({
41
46
  const fragment = FRAGMENT;
42
47
  const fragmentDefinition = getFragmentDefinition(fragment, displayName);
43
48
  const fragmentName = fragmentDefinition.name.value;
44
- const propName = getFragmentPropName(fragmentDefinition);
49
+ const propName = getFragmentPropName(fragmentDefinition, displayName);
45
50
  fragmentRegistry.register(fragment);
46
51
  function NamedCell(props) {
47
52
  const { children: _, [propName]: rawSlice, ...rest } = props;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/web",
3
- "version": "8.0.0-canary.3583",
3
+ "version": "8.0.0-canary.3588",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/cedarjs/cedar.git",
@@ -83,7 +83,7 @@
83
83
  },
84
84
  "dependencies": {
85
85
  "@apollo/client": "4.3.5",
86
- "@cedarjs/server-store": "8.0.0-canary.3583",
86
+ "@cedarjs/server-store": "8.0.0-canary.3588",
87
87
  "@dr.pogodin/react-helmet": "2.0.4",
88
88
  "@whatwg-node/fetch": "0.12.1",
89
89
  "apollo-upload-client": "19.0.0",
@@ -99,9 +99,9 @@
99
99
  "devDependencies": {
100
100
  "@apollo/client-react-streaming": "0.14.5",
101
101
  "@arethetypeswrong/cli": "0.18.5",
102
- "@cedarjs/auth": "8.0.0-canary.3583",
103
- "@cedarjs/framework-tools": "8.0.0-canary.3583",
104
- "@cedarjs/internal": "8.0.0-canary.3583",
102
+ "@cedarjs/auth": "8.0.0-canary.3588",
103
+ "@cedarjs/framework-tools": "8.0.0-canary.3588",
104
+ "@cedarjs/internal": "8.0.0-canary.3588",
105
105
  "@testing-library/dom": "10.4.2",
106
106
  "@testing-library/jest-dom": "6.9.1",
107
107
  "@testing-library/react": "16.3.3",
@@ -119,7 +119,7 @@
119
119
  "vitest": "5.0.5"
120
120
  },
121
121
  "peerDependencies": {
122
- "@cedarjs/auth": "8.0.0-canary.3583",
122
+ "@cedarjs/auth": "8.0.0-canary.3588",
123
123
  "react": "19.3.1",
124
124
  "react-dom": "19.3.1"
125
125
  },