@cedarjs/internal 6.0.0-canary.2645 → 6.0.0-canary.2647
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/ast.d.ts +1 -0
- package/dist/ast.d.ts.map +1 -1
- package/dist/ast.js +21 -0
- package/dist/cjs/ast.d.ts +1 -0
- package/dist/cjs/ast.d.ts.map +1 -1
- package/dist/cjs/ast.js +22 -0
- package/dist/cjs/generate/templates/mirror-cell-fragment.d.ts.template +18 -0
- package/dist/cjs/generate/typeDefinitions.d.ts.map +1 -1
- package/dist/cjs/generate/typeDefinitions.js +9 -0
- package/dist/cjs/gql.d.ts +20 -0
- package/dist/cjs/gql.d.ts.map +1 -1
- package/dist/cjs/gql.js +26 -0
- package/dist/generate/templates/mirror-cell-fragment.d.ts.template +18 -0
- package/dist/generate/typeDefinitions.d.ts.map +1 -1
- package/dist/generate/typeDefinitions.js +15 -1
- package/dist/gql.d.ts +20 -0
- package/dist/gql.d.ts.map +1 -1
- package/dist/gql.js +24 -0
- package/package.json +9 -9
package/dist/ast.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export declare const getNamedExports: (ast: types.Node) => NamedExports[];
|
|
|
17
17
|
*/
|
|
18
18
|
export declare const getGqlQueries: (ast: types.Node) => string[];
|
|
19
19
|
export declare const getCellGqlQuery: (ast: types.Node) => undefined;
|
|
20
|
+
export declare const getCellGqlFragment: (ast: types.Node) => undefined;
|
|
20
21
|
export declare const hasDefaultExport: (ast: types.Node) => boolean;
|
|
21
22
|
export declare const getDefaultExportLocation: (ast: types.Node) => {
|
|
22
23
|
line: number;
|
package/dist/ast.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ast.d.ts","sourceRoot":"","sources":["../src/ast.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAmBnC,eAAO,MAAM,SAAS,GAAI,UAAU,MAAM,KAAG,KAAK,CAAC,IAyBlD,CAAA;AAED,UAAU,YAAY;IACpB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,WAAW,GAAG,UAAU,GAAG,UAAU,GAAG,OAAO,CAAA;IACrD,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM,CAAA;QACZ,MAAM,EAAE,MAAM,CAAA;KACf,CAAA;CACF;AACD;;GAEG;AACH,eAAO,MAAM,eAAe,GAAI,KAAK,KAAK,CAAC,IAAI,KAAG,YAAY,EA4D7D,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,aAAa,GAAI,KAAK,KAAK,CAAC,IAAI,aAY5C,CAAA;AAED,eAAO,MAAM,eAAe,GAAI,KAAK,KAAK,CAAC,IAAI,cA8B9C,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,KAAK,KAAK,CAAC,IAAI,KAAG,OASlD,CAAA;AAED,eAAO,MAAM,wBAAwB,GACnC,KAAK,KAAK,CAAC,IAAI,KACd;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,IA0CrC,CAAA"}
|
|
1
|
+
{"version":3,"file":"ast.d.ts","sourceRoot":"","sources":["../src/ast.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAmBnC,eAAO,MAAM,SAAS,GAAI,UAAU,MAAM,KAAG,KAAK,CAAC,IAyBlD,CAAA;AAED,UAAU,YAAY;IACpB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,WAAW,GAAG,UAAU,GAAG,UAAU,GAAG,OAAO,CAAA;IACrD,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM,CAAA;QACZ,MAAM,EAAE,MAAM,CAAA;KACf,CAAA;CACF;AACD;;GAEG;AACH,eAAO,MAAM,eAAe,GAAI,KAAK,KAAK,CAAC,IAAI,KAAG,YAAY,EA4D7D,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,aAAa,GAAI,KAAK,KAAK,CAAC,IAAI,aAY5C,CAAA;AAED,eAAO,MAAM,eAAe,GAAI,KAAK,KAAK,CAAC,IAAI,cA8B9C,CAAA;AAED,eAAO,MAAM,kBAAkB,GAAI,KAAK,KAAK,CAAC,IAAI,cA8BjD,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,KAAK,KAAK,CAAC,IAAI,KAAG,OASlD,CAAA;AAED,eAAO,MAAM,wBAAwB,GACnC,KAAK,KAAK,CAAC,IAAI,KACd;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,IA0CrC,CAAA"}
|
package/dist/ast.js
CHANGED
|
@@ -115,6 +115,26 @@ const getCellGqlQuery = (ast) => {
|
|
|
115
115
|
});
|
|
116
116
|
return cellQuery;
|
|
117
117
|
};
|
|
118
|
+
const getCellGqlFragment = (ast) => {
|
|
119
|
+
let cellFragment = void 0;
|
|
120
|
+
traverse(ast, {
|
|
121
|
+
ExportNamedDeclaration({ node }) {
|
|
122
|
+
if (node.exportKind === "value" && types.isVariableDeclaration(node.declaration)) {
|
|
123
|
+
const exportedFragmentNode = node.declaration.declarations.find(
|
|
124
|
+
(d) => {
|
|
125
|
+
return types.isIdentifier(d.id) && d.id.name === "FRAGMENT" && types.isTaggedTemplateExpression(d.init);
|
|
126
|
+
}
|
|
127
|
+
);
|
|
128
|
+
if (exportedFragmentNode) {
|
|
129
|
+
const templateExpression = exportedFragmentNode.init;
|
|
130
|
+
cellFragment = templateExpression.quasi.quasis[0].value.raw;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
return cellFragment;
|
|
137
|
+
};
|
|
118
138
|
const hasDefaultExport = (ast) => {
|
|
119
139
|
let exported = false;
|
|
120
140
|
traverse(ast, {
|
|
@@ -154,6 +174,7 @@ const getDefaultExportLocation = (ast) => {
|
|
|
154
174
|
};
|
|
155
175
|
export {
|
|
156
176
|
fileToAst,
|
|
177
|
+
getCellGqlFragment,
|
|
157
178
|
getCellGqlQuery,
|
|
158
179
|
getDefaultExportLocation,
|
|
159
180
|
getGqlQueries,
|
package/dist/cjs/ast.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export declare const getNamedExports: (ast: types.Node) => NamedExports[];
|
|
|
17
17
|
*/
|
|
18
18
|
export declare const getGqlQueries: (ast: types.Node) => string[];
|
|
19
19
|
export declare const getCellGqlQuery: (ast: types.Node) => undefined;
|
|
20
|
+
export declare const getCellGqlFragment: (ast: types.Node) => undefined;
|
|
20
21
|
export declare const hasDefaultExport: (ast: types.Node) => boolean;
|
|
21
22
|
export declare const getDefaultExportLocation: (ast: types.Node) => {
|
|
22
23
|
line: number;
|
package/dist/cjs/ast.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ast.d.ts","sourceRoot":"","sources":["../../src/ast.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAmBnC,eAAO,MAAM,SAAS,GAAI,UAAU,MAAM,KAAG,KAAK,CAAC,IAyBlD,CAAA;AAED,UAAU,YAAY;IACpB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,WAAW,GAAG,UAAU,GAAG,UAAU,GAAG,OAAO,CAAA;IACrD,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM,CAAA;QACZ,MAAM,EAAE,MAAM,CAAA;KACf,CAAA;CACF;AACD;;GAEG;AACH,eAAO,MAAM,eAAe,GAAI,KAAK,KAAK,CAAC,IAAI,KAAG,YAAY,EA4D7D,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,aAAa,GAAI,KAAK,KAAK,CAAC,IAAI,aAY5C,CAAA;AAED,eAAO,MAAM,eAAe,GAAI,KAAK,KAAK,CAAC,IAAI,cA8B9C,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,KAAK,KAAK,CAAC,IAAI,KAAG,OASlD,CAAA;AAED,eAAO,MAAM,wBAAwB,GACnC,KAAK,KAAK,CAAC,IAAI,KACd;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,IA0CrC,CAAA"}
|
|
1
|
+
{"version":3,"file":"ast.d.ts","sourceRoot":"","sources":["../../src/ast.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAmBnC,eAAO,MAAM,SAAS,GAAI,UAAU,MAAM,KAAG,KAAK,CAAC,IAyBlD,CAAA;AAED,UAAU,YAAY;IACpB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,WAAW,GAAG,UAAU,GAAG,UAAU,GAAG,OAAO,CAAA;IACrD,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM,CAAA;QACZ,MAAM,EAAE,MAAM,CAAA;KACf,CAAA;CACF;AACD;;GAEG;AACH,eAAO,MAAM,eAAe,GAAI,KAAK,KAAK,CAAC,IAAI,KAAG,YAAY,EA4D7D,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,aAAa,GAAI,KAAK,KAAK,CAAC,IAAI,aAY5C,CAAA;AAED,eAAO,MAAM,eAAe,GAAI,KAAK,KAAK,CAAC,IAAI,cA8B9C,CAAA;AAED,eAAO,MAAM,kBAAkB,GAAI,KAAK,KAAK,CAAC,IAAI,cA8BjD,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,KAAK,KAAK,CAAC,IAAI,KAAG,OASlD,CAAA;AAED,eAAO,MAAM,wBAAwB,GACnC,KAAK,KAAK,CAAC,IAAI,KACd;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,IA0CrC,CAAA"}
|
package/dist/cjs/ast.js
CHANGED
|
@@ -29,6 +29,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
29
29
|
var ast_exports = {};
|
|
30
30
|
__export(ast_exports, {
|
|
31
31
|
fileToAst: () => fileToAst,
|
|
32
|
+
getCellGqlFragment: () => getCellGqlFragment,
|
|
32
33
|
getCellGqlQuery: () => getCellGqlQuery,
|
|
33
34
|
getDefaultExportLocation: () => getDefaultExportLocation,
|
|
34
35
|
getGqlQueries: () => getGqlQueries,
|
|
@@ -153,6 +154,26 @@ const getCellGqlQuery = (ast) => {
|
|
|
153
154
|
});
|
|
154
155
|
return cellQuery;
|
|
155
156
|
};
|
|
157
|
+
const getCellGqlFragment = (ast) => {
|
|
158
|
+
let cellFragment = void 0;
|
|
159
|
+
traverse(ast, {
|
|
160
|
+
ExportNamedDeclaration({ node }) {
|
|
161
|
+
if (node.exportKind === "value" && import_core.types.isVariableDeclaration(node.declaration)) {
|
|
162
|
+
const exportedFragmentNode = node.declaration.declarations.find(
|
|
163
|
+
(d) => {
|
|
164
|
+
return import_core.types.isIdentifier(d.id) && d.id.name === "FRAGMENT" && import_core.types.isTaggedTemplateExpression(d.init);
|
|
165
|
+
}
|
|
166
|
+
);
|
|
167
|
+
if (exportedFragmentNode) {
|
|
168
|
+
const templateExpression = exportedFragmentNode.init;
|
|
169
|
+
cellFragment = templateExpression.quasi.quasis[0].value.raw;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
return cellFragment;
|
|
176
|
+
};
|
|
156
177
|
const hasDefaultExport = (ast) => {
|
|
157
178
|
let exported = false;
|
|
158
179
|
traverse(ast, {
|
|
@@ -193,6 +214,7 @@ const getDefaultExportLocation = (ast) => {
|
|
|
193
214
|
// Annotate the CommonJS export names for ESM import in node:
|
|
194
215
|
0 && (module.exports = {
|
|
195
216
|
fileToAst,
|
|
217
|
+
getCellGqlFragment,
|
|
196
218
|
getCellGqlQuery,
|
|
197
219
|
getDefaultExportLocation,
|
|
198
220
|
getGqlQueries,
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as Cell from './${name}.js'
|
|
2
|
+
import type { ${fragmentType} } from 'types/graphql'
|
|
3
|
+
|
|
4
|
+
type SuccessType = typeof Cell.Success
|
|
5
|
+
|
|
6
|
+
export * from './${name}.js'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* ${fragmentPropName} is the slice of a parent Cell's query result that
|
|
10
|
+
* matches this Cell's FRAGMENT. The parent spreads the fragment in its QUERY
|
|
11
|
+
* and passes the fetched data object down, e.g.
|
|
12
|
+
* <Cell ${fragmentPropName}={data.someField} />
|
|
13
|
+
*/
|
|
14
|
+
type FragmentCellInputs = { ${fragmentPropName}: ${fragmentType} } & Record<string, unknown>
|
|
15
|
+
|
|
16
|
+
export default function (props: FragmentCellInputs): ReturnType<SuccessType>
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typeDefinitions.d.ts","sourceRoot":"","sources":["../../../src/generate/typeDefinitions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"typeDefinitions.d.ts","sourceRoot":"","sources":["../../../src/generate/typeDefinitions.ts"],"names":[],"mappings":"AA8CA;;;GAGG;AACH,eAAO,MAAM,gBAAgB;;;;;;EA0B5B,CAAA;AAED,eAAO,MAAM,mCAAmC,gBAK/C,CAAA;AAED,eAAO,MAAM,kCAAkC,GAC7C,GAAG,MAAM,EACT,mDAAsB,aASvB,CAAA;AAED,eAAO,MAAM,kCAAkC,GAC7C,GAAG,MAAM,EACT,mDAAsB,WAoDvB,CAAA;AAED,eAAO,MAAM,mBAAmB,gBAG/B,CAAA;AAED,eAAO,MAAM,iBAAiB,GAAI,GAAG,MAAM,EAAE,mDAAsB,aAQlE,CAAA;AAED,eAAO,MAAM,kBAAkB,GAAI,GAAG,MAAM,EAAE,mDAAsB,WAiFnE,CAAA;AAiBD,eAAO,MAAM,2BAA2B,gBAmEvC,CAAA;AAED,eAAO,MAAM,0BAA0B,gBA8CtC,CAAA;AAED,eAAO,MAAM,0BAA0B,gBAEtC,CAAA;AAED,eAAO,MAAM,qBAAqB,gBAEjC,CAAA;AAED,eAAO,MAAM,wBAAwB,gBAEpC,CAAA;AAED,eAAO,MAAM,wBAAwB,gBAKpC,CAAA;AAED,eAAO,MAAM,0BAA0B,gBAEtC,CAAA;AAED,eAAO,MAAM,4BAA4B,gBAExC,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,gCAAgC,gBAW5C,CAAA"}
|
|
@@ -155,6 +155,9 @@ const generateMirrorCell = (p, rwjsPaths = (0, import_project_config.getPaths)()
|
|
|
155
155
|
const { name } = import_path.default.parse(p);
|
|
156
156
|
const fileContents = (0, import_ast.fileToAst)(p);
|
|
157
157
|
const cellQuery = (0, import_ast.getCellGqlQuery)(fileContents);
|
|
158
|
+
const cellFragment = cellQuery ? void 0 : (0, import_ast.getCellGqlFragment)(fileContents);
|
|
159
|
+
const cellFragmentName = cellFragment ? (0, import_gql.parseGqlFragmentName)(cellFragment) : void 0;
|
|
160
|
+
const cellFragmentPropName = cellFragment ? (0, import_gql.parseGqlFragmentPropName)(cellFragment) : void 0;
|
|
158
161
|
if (cellQuery) {
|
|
159
162
|
const gqlDoc = (0, import_gql.parseGqlQueryToAst)(cellQuery)[0];
|
|
160
163
|
(0, import_templates.writeTemplate)("templates/mirror-cell.d.ts.template", typeDefPath, {
|
|
@@ -162,6 +165,12 @@ const generateMirrorCell = (p, rwjsPaths = (0, import_project_config.getPaths)()
|
|
|
162
165
|
queryResultType: `${gqlDoc?.name}`,
|
|
163
166
|
queryVariablesType: `${gqlDoc?.name}Variables`
|
|
164
167
|
});
|
|
168
|
+
} else if (cellFragmentName && cellFragmentPropName) {
|
|
169
|
+
(0, import_templates.writeTemplate)("templates/mirror-cell-fragment.d.ts.template", typeDefPath, {
|
|
170
|
+
name,
|
|
171
|
+
fragmentType: cellFragmentName,
|
|
172
|
+
fragmentPropName: cellFragmentPropName
|
|
173
|
+
});
|
|
165
174
|
} else {
|
|
166
175
|
(0, import_templates.writeTemplate)("templates/mirror-cell.d.ts.template", typeDefPath, {
|
|
167
176
|
name,
|
package/dist/cjs/gql.d.ts
CHANGED
|
@@ -9,6 +9,26 @@ interface Field {
|
|
|
9
9
|
}
|
|
10
10
|
export declare const parseGqlQueryToAst: (gqlQuery: string) => Operation[];
|
|
11
11
|
export declare const parseDocumentAST: (document: DocumentNode) => Operation[];
|
|
12
|
+
/**
|
|
13
|
+
* Returns the name of the first fragment definition in the given GraphQL
|
|
14
|
+
* source, e.g. `AuthorCell_author` for
|
|
15
|
+
* `fragment AuthorCell_author on User { fullName }`
|
|
16
|
+
*/
|
|
17
|
+
export declare const parseGqlFragmentName: (gqlFragment: string) => string | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Derives a fragment Cell's data prop name from its fragment: the prop the
|
|
20
|
+
* parent Cell passes the fragment data in with, and the prop `Success`
|
|
21
|
+
* receives the data as.
|
|
22
|
+
*
|
|
23
|
+
* For a fragment named with an underscore, like `AuthorCell_author`, the part
|
|
24
|
+
* after the last underscore is used (`author`). Otherwise the type the
|
|
25
|
+
* fragment is defined on is used, camelCased (`on User` -> `user`).
|
|
26
|
+
*
|
|
27
|
+
* Keep this in sync with getFragmentPropName in
|
|
28
|
+
* packages/web/src/components/cell/createFragmentCell.tsx, which is what the
|
|
29
|
+
* fragment Cell runtime uses.
|
|
30
|
+
*/
|
|
31
|
+
export declare const parseGqlFragmentPropName: (gqlFragment: string) => string | undefined;
|
|
12
32
|
export declare const listQueryTypeFieldsInProject: () => Promise<string[]>;
|
|
13
33
|
export {};
|
|
14
34
|
//# sourceMappingURL=gql.d.ts.map
|
package/dist/cjs/gql.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gql.d.ts","sourceRoot":"","sources":["../../src/gql.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,YAAY,
|
|
1
|
+
{"version":3,"file":"gql.d.ts","sourceRoot":"","sources":["../../src/gql.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,YAAY,EAKZ,iBAAiB,EAClB,MAAM,SAAS,CAAA;AAMhB,UAAU,SAAS;IACjB,SAAS,EAAE,iBAAiB,CAAA;IAC5B,IAAI,EAAE,MAAM,GAAG,SAAS,CAAA;IACxB,MAAM,EAAE,CAAC,MAAM,GAAG,KAAK,CAAC,EAAE,CAAA;CAC3B;AAED,UAAU,KAAK;IACb,MAAM,EAAE,CAAC,MAAM,GAAG,KAAK,CAAC,EAAE,CAAA;CAC3B;AAED,eAAO,MAAM,kBAAkB,GAAI,UAAU,MAAM,gBAGlD,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,UAAU,YAAY,gBAoBtD,CAAA;AAyCD;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,GAAI,aAAa,MAAM,uBAEvD,CAAA;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,wBAAwB,GAAI,aAAa,MAAM,uBAiB3D,CAAA;AAED,eAAO,MAAM,4BAA4B,yBA8BxC,CAAA"}
|
package/dist/cjs/gql.js
CHANGED
|
@@ -20,6 +20,8 @@ var gql_exports = {};
|
|
|
20
20
|
__export(gql_exports, {
|
|
21
21
|
listQueryTypeFieldsInProject: () => listQueryTypeFieldsInProject,
|
|
22
22
|
parseDocumentAST: () => parseDocumentAST,
|
|
23
|
+
parseGqlFragmentName: () => parseGqlFragmentName,
|
|
24
|
+
parseGqlFragmentPropName: () => parseGqlFragmentPropName,
|
|
23
25
|
parseGqlQueryToAst: () => parseGqlQueryToAst
|
|
24
26
|
});
|
|
25
27
|
module.exports = __toCommonJS(gql_exports);
|
|
@@ -73,6 +75,28 @@ const getFields = (field) => {
|
|
|
73
75
|
return obj;
|
|
74
76
|
}
|
|
75
77
|
};
|
|
78
|
+
const parseGqlFragmentDefinition = (gqlFragment) => {
|
|
79
|
+
const ast = (0, import_graphql.parse)(gqlFragment);
|
|
80
|
+
return ast.definitions.find(
|
|
81
|
+
(definition) => definition.kind === import_graphql.Kind.FRAGMENT_DEFINITION
|
|
82
|
+
);
|
|
83
|
+
};
|
|
84
|
+
const parseGqlFragmentName = (gqlFragment) => {
|
|
85
|
+
return parseGqlFragmentDefinition(gqlFragment)?.name.value;
|
|
86
|
+
};
|
|
87
|
+
const parseGqlFragmentPropName = (gqlFragment) => {
|
|
88
|
+
const fragmentDefinition = parseGqlFragmentDefinition(gqlFragment);
|
|
89
|
+
if (!fragmentDefinition) {
|
|
90
|
+
return void 0;
|
|
91
|
+
}
|
|
92
|
+
const fragmentName = fragmentDefinition.name.value;
|
|
93
|
+
const underscoreIndex = fragmentName.lastIndexOf("_");
|
|
94
|
+
if (underscoreIndex > 0 && underscoreIndex < fragmentName.length - 1) {
|
|
95
|
+
return fragmentName.slice(underscoreIndex + 1);
|
|
96
|
+
}
|
|
97
|
+
const typename = fragmentDefinition.typeCondition.name.value;
|
|
98
|
+
return typename.charAt(0).toLowerCase() + typename.slice(1);
|
|
99
|
+
};
|
|
76
100
|
const listQueryTypeFieldsInProject = async () => {
|
|
77
101
|
try {
|
|
78
102
|
const schemaPointerMap = {
|
|
@@ -104,5 +128,7 @@ const listQueryTypeFieldsInProject = async () => {
|
|
|
104
128
|
0 && (module.exports = {
|
|
105
129
|
listQueryTypeFieldsInProject,
|
|
106
130
|
parseDocumentAST,
|
|
131
|
+
parseGqlFragmentName,
|
|
132
|
+
parseGqlFragmentPropName,
|
|
107
133
|
parseGqlQueryToAst
|
|
108
134
|
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as Cell from './${name}.js'
|
|
2
|
+
import type { ${fragmentType} } from 'types/graphql'
|
|
3
|
+
|
|
4
|
+
type SuccessType = typeof Cell.Success
|
|
5
|
+
|
|
6
|
+
export * from './${name}.js'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* ${fragmentPropName} is the slice of a parent Cell's query result that
|
|
10
|
+
* matches this Cell's FRAGMENT. The parent spreads the fragment in its QUERY
|
|
11
|
+
* and passes the fetched data object down, e.g.
|
|
12
|
+
* <Cell ${fragmentPropName}={data.someField} />
|
|
13
|
+
*/
|
|
14
|
+
type FragmentCellInputs = { ${fragmentPropName}: ${fragmentType} } & Record<string, unknown>
|
|
15
|
+
|
|
16
|
+
export default function (props: FragmentCellInputs): ReturnType<SuccessType>
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typeDefinitions.d.ts","sourceRoot":"","sources":["../../src/generate/typeDefinitions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"typeDefinitions.d.ts","sourceRoot":"","sources":["../../src/generate/typeDefinitions.ts"],"names":[],"mappings":"AA8CA;;;GAGG;AACH,eAAO,MAAM,gBAAgB;;;;;;EA0B5B,CAAA;AAED,eAAO,MAAM,mCAAmC,gBAK/C,CAAA;AAED,eAAO,MAAM,kCAAkC,GAC7C,GAAG,MAAM,EACT,mDAAsB,aASvB,CAAA;AAED,eAAO,MAAM,kCAAkC,GAC7C,GAAG,MAAM,EACT,mDAAsB,WAoDvB,CAAA;AAED,eAAO,MAAM,mBAAmB,gBAG/B,CAAA;AAED,eAAO,MAAM,iBAAiB,GAAI,GAAG,MAAM,EAAE,mDAAsB,aAQlE,CAAA;AAED,eAAO,MAAM,kBAAkB,GAAI,GAAG,MAAM,EAAE,mDAAsB,WAiFnE,CAAA;AAiBD,eAAO,MAAM,2BAA2B,gBAmEvC,CAAA;AAED,eAAO,MAAM,0BAA0B,gBA8CtC,CAAA;AAED,eAAO,MAAM,0BAA0B,gBAEtC,CAAA;AAED,eAAO,MAAM,qBAAqB,gBAEjC,CAAA;AAED,eAAO,MAAM,wBAAwB,gBAEpC,CAAA;AAED,eAAO,MAAM,wBAAwB,gBAKpC,CAAA;AAED,eAAO,MAAM,0BAA0B,gBAEtC,CAAA;AAED,eAAO,MAAM,4BAA4B,gBAExC,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,gCAAgC,gBAW5C,CAAA"}
|
|
@@ -3,13 +3,18 @@ import path from "path";
|
|
|
3
3
|
import { SourceMapGenerator } from "source-map";
|
|
4
4
|
import { getPaths, processPagesDir } from "@cedarjs/project-config";
|
|
5
5
|
import {
|
|
6
|
+
getCellGqlFragment,
|
|
6
7
|
getCellGqlQuery,
|
|
7
8
|
fileToAst,
|
|
8
9
|
getDefaultExportLocation,
|
|
9
10
|
getNamedExports
|
|
10
11
|
} from "../ast.js";
|
|
11
12
|
import { findCells, findDirectoryNamedModules } from "../files.js";
|
|
12
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
parseGqlFragmentName,
|
|
15
|
+
parseGqlFragmentPropName,
|
|
16
|
+
parseGqlQueryToAst
|
|
17
|
+
} from "../gql.js";
|
|
13
18
|
import { getJsxElements } from "../jsx.js";
|
|
14
19
|
import {
|
|
15
20
|
generateTypeDefGraphQLApi,
|
|
@@ -115,6 +120,9 @@ const generateMirrorCell = (p, rwjsPaths = getPaths()) => {
|
|
|
115
120
|
const { name } = path.parse(p);
|
|
116
121
|
const fileContents = fileToAst(p);
|
|
117
122
|
const cellQuery = getCellGqlQuery(fileContents);
|
|
123
|
+
const cellFragment = cellQuery ? void 0 : getCellGqlFragment(fileContents);
|
|
124
|
+
const cellFragmentName = cellFragment ? parseGqlFragmentName(cellFragment) : void 0;
|
|
125
|
+
const cellFragmentPropName = cellFragment ? parseGqlFragmentPropName(cellFragment) : void 0;
|
|
118
126
|
if (cellQuery) {
|
|
119
127
|
const gqlDoc = parseGqlQueryToAst(cellQuery)[0];
|
|
120
128
|
writeTemplate("templates/mirror-cell.d.ts.template", typeDefPath, {
|
|
@@ -122,6 +130,12 @@ const generateMirrorCell = (p, rwjsPaths = getPaths()) => {
|
|
|
122
130
|
queryResultType: `${gqlDoc?.name}`,
|
|
123
131
|
queryVariablesType: `${gqlDoc?.name}Variables`
|
|
124
132
|
});
|
|
133
|
+
} else if (cellFragmentName && cellFragmentPropName) {
|
|
134
|
+
writeTemplate("templates/mirror-cell-fragment.d.ts.template", typeDefPath, {
|
|
135
|
+
name,
|
|
136
|
+
fragmentType: cellFragmentName,
|
|
137
|
+
fragmentPropName: cellFragmentPropName
|
|
138
|
+
});
|
|
125
139
|
} else {
|
|
126
140
|
writeTemplate("templates/mirror-cell.d.ts.template", typeDefPath, {
|
|
127
141
|
name,
|
package/dist/gql.d.ts
CHANGED
|
@@ -9,6 +9,26 @@ interface Field {
|
|
|
9
9
|
}
|
|
10
10
|
export declare const parseGqlQueryToAst: (gqlQuery: string) => Operation[];
|
|
11
11
|
export declare const parseDocumentAST: (document: DocumentNode) => Operation[];
|
|
12
|
+
/**
|
|
13
|
+
* Returns the name of the first fragment definition in the given GraphQL
|
|
14
|
+
* source, e.g. `AuthorCell_author` for
|
|
15
|
+
* `fragment AuthorCell_author on User { fullName }`
|
|
16
|
+
*/
|
|
17
|
+
export declare const parseGqlFragmentName: (gqlFragment: string) => string | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Derives a fragment Cell's data prop name from its fragment: the prop the
|
|
20
|
+
* parent Cell passes the fragment data in with, and the prop `Success`
|
|
21
|
+
* receives the data as.
|
|
22
|
+
*
|
|
23
|
+
* For a fragment named with an underscore, like `AuthorCell_author`, the part
|
|
24
|
+
* after the last underscore is used (`author`). Otherwise the type the
|
|
25
|
+
* fragment is defined on is used, camelCased (`on User` -> `user`).
|
|
26
|
+
*
|
|
27
|
+
* Keep this in sync with getFragmentPropName in
|
|
28
|
+
* packages/web/src/components/cell/createFragmentCell.tsx, which is what the
|
|
29
|
+
* fragment Cell runtime uses.
|
|
30
|
+
*/
|
|
31
|
+
export declare const parseGqlFragmentPropName: (gqlFragment: string) => string | undefined;
|
|
12
32
|
export declare const listQueryTypeFieldsInProject: () => Promise<string[]>;
|
|
13
33
|
export {};
|
|
14
34
|
//# sourceMappingURL=gql.d.ts.map
|
package/dist/gql.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gql.d.ts","sourceRoot":"","sources":["../src/gql.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,YAAY,
|
|
1
|
+
{"version":3,"file":"gql.d.ts","sourceRoot":"","sources":["../src/gql.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,YAAY,EAKZ,iBAAiB,EAClB,MAAM,SAAS,CAAA;AAMhB,UAAU,SAAS;IACjB,SAAS,EAAE,iBAAiB,CAAA;IAC5B,IAAI,EAAE,MAAM,GAAG,SAAS,CAAA;IACxB,MAAM,EAAE,CAAC,MAAM,GAAG,KAAK,CAAC,EAAE,CAAA;CAC3B;AAED,UAAU,KAAK;IACb,MAAM,EAAE,CAAC,MAAM,GAAG,KAAK,CAAC,EAAE,CAAA;CAC3B;AAED,eAAO,MAAM,kBAAkB,GAAI,UAAU,MAAM,gBAGlD,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,UAAU,YAAY,gBAoBtD,CAAA;AAyCD;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,GAAI,aAAa,MAAM,uBAEvD,CAAA;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,wBAAwB,GAAI,aAAa,MAAM,uBAiB3D,CAAA;AAED,eAAO,MAAM,4BAA4B,yBA8BxC,CAAA"}
|
package/dist/gql.js
CHANGED
|
@@ -48,6 +48,28 @@ const getFields = (field) => {
|
|
|
48
48
|
return obj;
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
|
+
const parseGqlFragmentDefinition = (gqlFragment) => {
|
|
52
|
+
const ast = parse(gqlFragment);
|
|
53
|
+
return ast.definitions.find(
|
|
54
|
+
(definition) => definition.kind === Kind.FRAGMENT_DEFINITION
|
|
55
|
+
);
|
|
56
|
+
};
|
|
57
|
+
const parseGqlFragmentName = (gqlFragment) => {
|
|
58
|
+
return parseGqlFragmentDefinition(gqlFragment)?.name.value;
|
|
59
|
+
};
|
|
60
|
+
const parseGqlFragmentPropName = (gqlFragment) => {
|
|
61
|
+
const fragmentDefinition = parseGqlFragmentDefinition(gqlFragment);
|
|
62
|
+
if (!fragmentDefinition) {
|
|
63
|
+
return void 0;
|
|
64
|
+
}
|
|
65
|
+
const fragmentName = fragmentDefinition.name.value;
|
|
66
|
+
const underscoreIndex = fragmentName.lastIndexOf("_");
|
|
67
|
+
if (underscoreIndex > 0 && underscoreIndex < fragmentName.length - 1) {
|
|
68
|
+
return fragmentName.slice(underscoreIndex + 1);
|
|
69
|
+
}
|
|
70
|
+
const typename = fragmentDefinition.typeCondition.name.value;
|
|
71
|
+
return typename.charAt(0).toLowerCase() + typename.slice(1);
|
|
72
|
+
};
|
|
51
73
|
const listQueryTypeFieldsInProject = async () => {
|
|
52
74
|
try {
|
|
53
75
|
const schemaPointerMap = {
|
|
@@ -78,5 +100,7 @@ const listQueryTypeFieldsInProject = async () => {
|
|
|
78
100
|
export {
|
|
79
101
|
listQueryTypeFieldsInProject,
|
|
80
102
|
parseDocumentAST,
|
|
103
|
+
parseGqlFragmentName,
|
|
104
|
+
parseGqlFragmentPropName,
|
|
81
105
|
parseGqlQueryToAst
|
|
82
106
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/internal",
|
|
3
|
-
"version": "6.0.0-canary.
|
|
3
|
+
"version": "6.0.0-canary.2647",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/cedarjs/cedar.git",
|
|
@@ -169,13 +169,13 @@
|
|
|
169
169
|
"@babel/plugin-transform-react-jsx": "7.29.7",
|
|
170
170
|
"@babel/plugin-transform-typescript": "^7.26.8",
|
|
171
171
|
"@babel/traverse": "7.29.7",
|
|
172
|
-
"@cedarjs/babel-config": "6.0.0-canary.
|
|
173
|
-
"@cedarjs/cli-helpers": "6.0.0-canary.
|
|
174
|
-
"@cedarjs/graphql-server": "6.0.0-canary.
|
|
175
|
-
"@cedarjs/project-config": "6.0.0-canary.
|
|
176
|
-
"@cedarjs/router": "6.0.0-canary.
|
|
177
|
-
"@cedarjs/structure": "6.0.0-canary.
|
|
178
|
-
"@cedarjs/utils": "6.0.0-canary.
|
|
172
|
+
"@cedarjs/babel-config": "6.0.0-canary.2647",
|
|
173
|
+
"@cedarjs/cli-helpers": "6.0.0-canary.2647",
|
|
174
|
+
"@cedarjs/graphql-server": "6.0.0-canary.2647",
|
|
175
|
+
"@cedarjs/project-config": "6.0.0-canary.2647",
|
|
176
|
+
"@cedarjs/router": "6.0.0-canary.2647",
|
|
177
|
+
"@cedarjs/structure": "6.0.0-canary.2647",
|
|
178
|
+
"@cedarjs/utils": "6.0.0-canary.2647",
|
|
179
179
|
"@graphql-codegen/add": "6.0.1",
|
|
180
180
|
"@graphql-codegen/cli": "6.3.1",
|
|
181
181
|
"@graphql-codegen/client-preset": "5.3.0",
|
|
@@ -218,7 +218,7 @@
|
|
|
218
218
|
},
|
|
219
219
|
"devDependencies": {
|
|
220
220
|
"@arethetypeswrong/cli": "0.18.5",
|
|
221
|
-
"@cedarjs/framework-tools": "6.0.0-canary.
|
|
221
|
+
"@cedarjs/framework-tools": "6.0.0-canary.2647",
|
|
222
222
|
"concurrently": "9.2.1",
|
|
223
223
|
"graphql-tag": "2.12.6",
|
|
224
224
|
"publint": "0.3.21",
|