@cedarjs/internal 6.0.3-next.227 → 6.0.3-next.296
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphqlCodeGen.d.ts","sourceRoot":"","sources":["../../src/generate/graphqlCodeGen.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"graphqlCodeGen.d.ts","sourceRoot":"","sources":["../../src/generate/graphqlCodeGen.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AAoB9D,KAAK,aAAa,GAAG;IACnB,YAAY,EAAE,MAAM,EAAE,CAAA;IACtB,MAAM,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,EAAE,CAAA;CAC9C,CAAA;AAED,eAAO,MAAM,yBAAyB,QAAa,OAAO,CAAC,aAAa,CAiFvE,CAAA;AAED,eAAO,MAAM,yBAAyB,QAAa,OAAO,CAAC,aAAa,CA2DvE,CAAA;AAyFD,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM;SACD,MAAM;GAQ5D;AAqPD,eAAO,MAAM,iBAAiB,4RAe7B,CAAA"}
|
|
@@ -14,6 +14,7 @@ import { Kind } from "graphql";
|
|
|
14
14
|
import {
|
|
15
15
|
getPaths,
|
|
16
16
|
getConfig,
|
|
17
|
+
getParsedScalars,
|
|
17
18
|
resolveGeneratedPrismaClient
|
|
18
19
|
} from "@cedarjs/project-config";
|
|
19
20
|
import { getPackageManager } from "@cedarjs/project-config/packageManager";
|
|
@@ -114,7 +115,10 @@ const generateTypeDefGraphQLWeb = async () => {
|
|
|
114
115
|
{
|
|
115
116
|
name: "add",
|
|
116
117
|
options: {
|
|
117
|
-
content:
|
|
118
|
+
content: [
|
|
119
|
+
`import { Prisma } from "$api/src/lib/db"`,
|
|
120
|
+
...getApolloScalarDeclarations()
|
|
121
|
+
],
|
|
118
122
|
placement: "prepend"
|
|
119
123
|
},
|
|
120
124
|
codegenPlugin: addPlugin
|
|
@@ -147,14 +151,45 @@ const generateTypeDefGraphQLWeb = async () => {
|
|
|
147
151
|
};
|
|
148
152
|
}
|
|
149
153
|
};
|
|
154
|
+
function isRecord(value) {
|
|
155
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
156
|
+
}
|
|
157
|
+
function mergeScalars(cedarScalars, userScalars) {
|
|
158
|
+
if (userScalars === void 0 || userScalars === null) {
|
|
159
|
+
return cedarScalars;
|
|
160
|
+
}
|
|
161
|
+
if (isRecord(cedarScalars) && isRecord(userScalars)) {
|
|
162
|
+
return { ...cedarScalars, ...userScalars };
|
|
163
|
+
}
|
|
164
|
+
return userScalars;
|
|
165
|
+
}
|
|
166
|
+
function getApolloScalarDeclarations() {
|
|
167
|
+
const declarations = [];
|
|
168
|
+
if (getParsedScalars().DateTime === "Date") {
|
|
169
|
+
declarations.push(
|
|
170
|
+
[
|
|
171
|
+
"declare module '@apollo/client' {",
|
|
172
|
+
" namespace ApolloCache {",
|
|
173
|
+
" interface Scalars {",
|
|
174
|
+
" DateTime: { serialized: string; parsed: Date }",
|
|
175
|
+
" }",
|
|
176
|
+
" }",
|
|
177
|
+
"}"
|
|
178
|
+
].join("\n")
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
return declarations;
|
|
182
|
+
}
|
|
150
183
|
async function runCodegenGraphQL(documents, extraPlugins, filename, side) {
|
|
151
184
|
const userCodegenConfig = await loadCodegenConfig({
|
|
152
185
|
configFilePath: getPaths().base
|
|
153
186
|
});
|
|
154
187
|
const pluginConfig = await getPluginConfig(side);
|
|
188
|
+
const { scalars: userScalars, ...userPluginConfig } = userCodegenConfig?.config?.config ?? {};
|
|
155
189
|
const mergedConfig = {
|
|
156
190
|
...pluginConfig,
|
|
157
|
-
...
|
|
191
|
+
...userPluginConfig,
|
|
192
|
+
scalars: mergeScalars(pluginConfig.scalars, userScalars)
|
|
158
193
|
};
|
|
159
194
|
const options = getCodegenOptions(documents, mergedConfig, extraPlugins);
|
|
160
195
|
const output = await codegen(options);
|
|
@@ -268,8 +303,8 @@ async function getPluginConfig(side) {
|
|
|
268
303
|
const scalars = {
|
|
269
304
|
// We need these, otherwise these scalars are mapped to any
|
|
270
305
|
BigInt: "number",
|
|
271
|
-
// @Note: DateTime fields can be valid Date-strings, or the Date object in the api side. They're
|
|
272
|
-
DateTime: side === 1 /* WEB */ ? "string" : "Date | string",
|
|
306
|
+
// @Note: DateTime fields can be valid Date-strings, or the Date object in the api side. They're strings on the web side, unless `graphql.parsedScalars.DateTime` is set. Then they are Date objects when the web side reads them, and Apollo Client accepts a Date or a string when they're sent.
|
|
307
|
+
DateTime: side === 1 /* WEB */ ? getParsedScalars().DateTime === "Date" ? { input: "Date | string", output: "Date" } : "string" : "Date | string",
|
|
273
308
|
Date: side === 1 /* WEB */ ? "string" : "Date | string",
|
|
274
309
|
JSON: "Prisma.JsonValue",
|
|
275
310
|
JSONObject: "Prisma.JsonObject",
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { GraphQLSchema } from 'graphql';
|
|
2
|
+
import type { ParsedScalarsConfig } from '@cedarjs/project-config';
|
|
3
|
+
/**
|
|
4
|
+
* What `CedarApolloProvider` needs to make Apollo Client's cache parse the
|
|
5
|
+
* scalars in `graphql.parsedScalars`. The `typePolicies` and `inputObjects`
|
|
6
|
+
* are passed to `InMemoryCache` as they are.
|
|
7
|
+
*/
|
|
8
|
+
export interface ParsedScalarsCacheConfig {
|
|
9
|
+
/**
|
|
10
|
+
* The scalars to parse, and the type each is parsed into
|
|
11
|
+
*/
|
|
12
|
+
scalars: ParsedScalarsConfig;
|
|
13
|
+
/**
|
|
14
|
+
* The fields in the schema that hold a parsed scalar
|
|
15
|
+
*/
|
|
16
|
+
typePolicies: Record<string, {
|
|
17
|
+
fields: Record<string, {
|
|
18
|
+
scalar: string;
|
|
19
|
+
}>;
|
|
20
|
+
}>;
|
|
21
|
+
/**
|
|
22
|
+
* The input objects that hold a parsed scalar, directly or through another
|
|
23
|
+
* input object
|
|
24
|
+
*/
|
|
25
|
+
inputObjects: Record<string, {
|
|
26
|
+
fields: Record<string, string>;
|
|
27
|
+
}>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Finds every field in the schema that holds one of the scalars in
|
|
31
|
+
* `parsedScalars`, in the shape Apollo Client's `InMemoryCache` takes, so that
|
|
32
|
+
* the cache parses those fields when it reads a response and serializes them
|
|
33
|
+
* in a query's variables.
|
|
34
|
+
*/
|
|
35
|
+
export declare function getParsedScalarsCacheConfig(schema: GraphQLSchema, parsedScalars: ParsedScalarsConfig): ParsedScalarsCacheConfig;
|
|
36
|
+
/**
|
|
37
|
+
* Reads the project's `graphql.parsedScalars` setting and its generated
|
|
38
|
+
* GraphQL schema, and returns the cache config for them. Returns `undefined`
|
|
39
|
+
* when no scalar is set to be parsed, or when the schema hasn't been generated.
|
|
40
|
+
*/
|
|
41
|
+
export declare function loadParsedScalarsCacheConfig(): ParsedScalarsCacheConfig | undefined;
|
|
42
|
+
//# sourceMappingURL=parsedScalars.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parsedScalars.d.ts","sourceRoot":"","sources":["../../src/generate/parsedScalars.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAe,MAAM,SAAS,CAAA;AASzD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAA;AAGlE;;;;GAIG;AACH,MAAM,WAAW,wBAAwB;IACvC;;OAEG;IACH,OAAO,EAAE,mBAAmB,CAAA;IAC5B;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE;YAAE,MAAM,EAAE,MAAM,CAAA;SAAE,CAAC,CAAA;KAAE,CAAC,CAAA;IAC5E;;;OAGG;IACH,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAAE,CAAC,CAAA;CACjE;AA0BD;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,aAAa,EACrB,aAAa,EAAE,mBAAmB,GACjC,wBAAwB,CA0E1B;AAED;;;;GAIG;AACH,wBAAgB,4BAA4B,IAC1C,wBAAwB,GAAG,SAAS,CAwBrC"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { GraphQLFileLoader } from "@graphql-tools/graphql-file-loader";
|
|
3
|
+
import { loadSchemaSync } from "@graphql-tools/load";
|
|
4
|
+
import {
|
|
5
|
+
getNamedType,
|
|
6
|
+
isInputObjectType,
|
|
7
|
+
isListType,
|
|
8
|
+
isNonNullType,
|
|
9
|
+
isObjectType
|
|
10
|
+
} from "graphql";
|
|
11
|
+
import { getParsedScalars, getPaths } from "@cedarjs/project-config";
|
|
12
|
+
function scalarTypeName(type, names) {
|
|
13
|
+
if (isNonNullType(type)) {
|
|
14
|
+
return scalarTypeName(type.ofType, names);
|
|
15
|
+
}
|
|
16
|
+
if (isListType(type)) {
|
|
17
|
+
const inner = scalarTypeName(type.ofType, names);
|
|
18
|
+
return inner === void 0 ? void 0 : `[${inner}]`;
|
|
19
|
+
}
|
|
20
|
+
const name = getNamedType(type).name;
|
|
21
|
+
return names.has(name) ? name : void 0;
|
|
22
|
+
}
|
|
23
|
+
function getParsedScalarsCacheConfig(schema, parsedScalars) {
|
|
24
|
+
const scalarNames = new Set(Object.keys(parsedScalars));
|
|
25
|
+
const typePolicies = {};
|
|
26
|
+
const inputObjects = {};
|
|
27
|
+
if (scalarNames.size === 0) {
|
|
28
|
+
return { scalars: parsedScalars, typePolicies, inputObjects };
|
|
29
|
+
}
|
|
30
|
+
const types = Object.values(schema.getTypeMap()).filter(
|
|
31
|
+
(type) => !type.name.startsWith("__")
|
|
32
|
+
);
|
|
33
|
+
for (const type of types) {
|
|
34
|
+
if (!isObjectType(type)) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
for (const field of Object.values(type.getFields())) {
|
|
38
|
+
const scalar = scalarTypeName(field.type, scalarNames);
|
|
39
|
+
if (scalar) {
|
|
40
|
+
typePolicies[type.name] ??= { fields: {} };
|
|
41
|
+
typePolicies[type.name].fields[field.name] = { scalar };
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const inputTypes = types.filter(isInputObjectType);
|
|
46
|
+
let inputObjectNames = /* @__PURE__ */ new Set();
|
|
47
|
+
let grew = true;
|
|
48
|
+
while (grew) {
|
|
49
|
+
const names2 = /* @__PURE__ */ new Set([...scalarNames, ...inputObjectNames]);
|
|
50
|
+
const next = new Set(inputObjectNames);
|
|
51
|
+
for (const type of inputTypes) {
|
|
52
|
+
const holdsScalar = Object.values(type.getFields()).some(
|
|
53
|
+
(field) => scalarTypeName(field.type, names2) !== void 0
|
|
54
|
+
);
|
|
55
|
+
if (holdsScalar) {
|
|
56
|
+
next.add(type.name);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
grew = next.size > inputObjectNames.size;
|
|
60
|
+
inputObjectNames = next;
|
|
61
|
+
}
|
|
62
|
+
const names = /* @__PURE__ */ new Set([...scalarNames, ...inputObjectNames]);
|
|
63
|
+
for (const type of inputTypes) {
|
|
64
|
+
if (!inputObjectNames.has(type.name)) {
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const fields = {};
|
|
68
|
+
for (const field of Object.values(type.getFields())) {
|
|
69
|
+
const fieldType = scalarTypeName(field.type, names);
|
|
70
|
+
if (fieldType) {
|
|
71
|
+
fields[field.name] = fieldType;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
inputObjects[type.name] = { fields };
|
|
75
|
+
}
|
|
76
|
+
return { scalars: parsedScalars, typePolicies, inputObjects };
|
|
77
|
+
}
|
|
78
|
+
function loadParsedScalarsCacheConfig() {
|
|
79
|
+
const parsedScalars = getParsedScalars();
|
|
80
|
+
if (Object.keys(parsedScalars).length === 0) {
|
|
81
|
+
return void 0;
|
|
82
|
+
}
|
|
83
|
+
const schemaPath = getPaths().generated.schema;
|
|
84
|
+
if (!fs.existsSync(schemaPath)) {
|
|
85
|
+
return void 0;
|
|
86
|
+
}
|
|
87
|
+
const schema = loadSchemaSync(schemaPath, {
|
|
88
|
+
loaders: [new GraphQLFileLoader()],
|
|
89
|
+
sort: true
|
|
90
|
+
});
|
|
91
|
+
return getParsedScalarsCacheConfig(schema, parsedScalars);
|
|
92
|
+
}
|
|
93
|
+
export {
|
|
94
|
+
getParsedScalarsCacheConfig,
|
|
95
|
+
loadParsedScalarsCacheConfig
|
|
96
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/internal",
|
|
3
|
-
"version": "6.0.3-next.
|
|
3
|
+
"version": "6.0.3-next.296",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/cedarjs/cedar.git",
|
|
@@ -87,6 +87,12 @@
|
|
|
87
87
|
"types": "./dist/generate/gqlormSchema.d.ts",
|
|
88
88
|
"default": "./dist/generate/gqlormSchema.js"
|
|
89
89
|
}
|
|
90
|
+
},
|
|
91
|
+
"./dist/generate/parsedScalars.js": {
|
|
92
|
+
"default": {
|
|
93
|
+
"types": "./dist/generate/parsedScalars.d.ts",
|
|
94
|
+
"default": "./dist/generate/parsedScalars.js"
|
|
95
|
+
}
|
|
90
96
|
}
|
|
91
97
|
},
|
|
92
98
|
"types": "dist/index.d.ts",
|
|
@@ -112,16 +118,16 @@
|
|
|
112
118
|
},
|
|
113
119
|
"dependencies": {
|
|
114
120
|
"@babel/core": "^7.26.10",
|
|
115
|
-
"@babel/parser": "7.29.
|
|
121
|
+
"@babel/parser": "7.29.9",
|
|
116
122
|
"@babel/traverse": "7.29.8",
|
|
117
|
-
"@cedarjs/api": "6.0.3-next.
|
|
118
|
-
"@cedarjs/babel-config": "6.0.3-next.
|
|
119
|
-
"@cedarjs/cli-helpers": "6.0.3-next.
|
|
120
|
-
"@cedarjs/graphql-server": "6.0.3-next.
|
|
121
|
-
"@cedarjs/project-config": "6.0.3-next.
|
|
122
|
-
"@cedarjs/router": "6.0.3-next.
|
|
123
|
-
"@cedarjs/structure": "6.0.3-next.
|
|
124
|
-
"@cedarjs/utils": "6.0.3-next.
|
|
123
|
+
"@cedarjs/api": "6.0.3-next.296",
|
|
124
|
+
"@cedarjs/babel-config": "6.0.3-next.296",
|
|
125
|
+
"@cedarjs/cli-helpers": "6.0.3-next.296",
|
|
126
|
+
"@cedarjs/graphql-server": "6.0.3-next.296",
|
|
127
|
+
"@cedarjs/project-config": "6.0.3-next.296",
|
|
128
|
+
"@cedarjs/router": "6.0.3-next.296",
|
|
129
|
+
"@cedarjs/structure": "6.0.3-next.296",
|
|
130
|
+
"@cedarjs/utils": "6.0.3-next.296",
|
|
125
131
|
"@graphql-codegen/add": "6.0.1",
|
|
126
132
|
"@graphql-codegen/cli": "6.3.1",
|
|
127
133
|
"@graphql-codegen/client-preset": "5.3.0",
|
|
@@ -140,7 +146,7 @@
|
|
|
140
146
|
"@prisma/dmmf": "7.10.0",
|
|
141
147
|
"@prisma/internals": "7.10.0",
|
|
142
148
|
"@sdl-codegen/node": "2.0.1",
|
|
143
|
-
"ansis": "4.
|
|
149
|
+
"ansis": "4.4.0",
|
|
144
150
|
"chokidar": "3.6.0",
|
|
145
151
|
"esbuild": "0.28.2",
|
|
146
152
|
"execa": "5.1.1",
|
|
@@ -148,8 +154,8 @@
|
|
|
148
154
|
"graphql": "16.14.2",
|
|
149
155
|
"kill-port": "1.6.1",
|
|
150
156
|
"magic-string": "0.30.21",
|
|
151
|
-
"oxc-parser": "0.
|
|
152
|
-
"prettier": "3.9.
|
|
157
|
+
"oxc-parser": "0.151.0",
|
|
158
|
+
"prettier": "3.9.8",
|
|
153
159
|
"rimraf": "6.1.3",
|
|
154
160
|
"source-map": "0.8.0",
|
|
155
161
|
"termi-link": "1.1.0",
|
|
@@ -159,12 +165,12 @@
|
|
|
159
165
|
"vite-tsconfig-paths": "^6.1.1"
|
|
160
166
|
},
|
|
161
167
|
"devDependencies": {
|
|
162
|
-
"@cedarjs/framework-tools": "6.0.3-next.
|
|
168
|
+
"@cedarjs/framework-tools": "6.0.3-next.296",
|
|
163
169
|
"@jridgewell/trace-mapping": "0.3.31",
|
|
164
|
-
"@oxc-project/types": "^0.
|
|
170
|
+
"@oxc-project/types": "^0.151.0",
|
|
165
171
|
"concurrently": "9.2.4",
|
|
166
172
|
"graphql-tag": "2.12.7",
|
|
167
|
-
"memfs": "4.
|
|
173
|
+
"memfs": "4.79.0",
|
|
168
174
|
"publint": "0.3.24",
|
|
169
175
|
"ts-dedent": "2.3.0",
|
|
170
176
|
"vitest": "4.1.11"
|