joist-graphql-codegen 2.3.0-next.41 → 2.3.0-next.43
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/build/_virtual/_rolldown/runtime.cjs +23 -0
- package/build/generateEnumDetailResolvers.cjs +40 -0
- package/build/generateEnumDetailResolvers.cjs.map +1 -0
- package/build/generateEnumDetailResolvers.d.cts +8 -0
- package/build/generateEnumDetailResolvers.d.cts.map +1 -0
- package/build/generateEnumDetailResolvers.d.mts +8 -0
- package/build/generateEnumDetailResolvers.d.mts.map +1 -0
- package/build/generateEnumDetailResolvers.js +23 -23
- package/build/generateEnumDetailResolvers.js.map +1 -1
- package/build/generateEnumsGraphql.cjs +29 -0
- package/build/generateEnumsGraphql.cjs.map +1 -0
- package/build/generateEnumsGraphql.d.cts +8 -0
- package/build/generateEnumsGraphql.d.cts.map +1 -0
- package/build/generateEnumsGraphql.d.mts +8 -0
- package/build/generateEnumsGraphql.d.mts.map +1 -0
- package/build/generateEnumsGraphql.js +24 -27
- package/build/generateEnumsGraphql.js.map +1 -1
- package/build/generateGraphqlCodegen.cjs +54 -0
- package/build/generateGraphqlCodegen.cjs.map +1 -0
- package/build/generateGraphqlCodegen.d.cts +8 -0
- package/build/generateGraphqlCodegen.d.cts.map +1 -0
- package/build/generateGraphqlCodegen.d.mts +8 -0
- package/build/generateGraphqlCodegen.d.mts.map +1 -0
- package/build/generateGraphqlCodegen.js +28 -30
- package/build/generateGraphqlCodegen.js.map +1 -1
- package/build/generateGraphqlSchemaFiles.cjs +491 -0
- package/build/generateGraphqlSchemaFiles.cjs.map +1 -0
- package/build/{generateGraphqlSchemaFiles.d.ts → generateGraphqlSchemaFiles.d.cts} +6 -2
- package/build/generateGraphqlSchemaFiles.d.cts.map +1 -0
- package/build/generateGraphqlSchemaFiles.d.mts +15 -0
- package/build/generateGraphqlSchemaFiles.d.mts.map +1 -0
- package/build/generateGraphqlSchemaFiles.js +444 -286
- package/build/generateGraphqlSchemaFiles.js.map +1 -1
- package/build/generateObjectResolvers.cjs +70 -0
- package/build/generateObjectResolvers.cjs.map +1 -0
- package/build/{generateObjectResolvers.d.ts → generateObjectResolvers.d.cts} +5 -1
- package/build/generateObjectResolvers.d.cts.map +1 -0
- package/build/generateObjectResolvers.d.mts +17 -0
- package/build/generateObjectResolvers.d.mts.map +1 -0
- package/build/generateObjectResolvers.js +48 -38
- package/build/generateObjectResolvers.js.map +1 -1
- package/build/generateQueryPageResolvers.cjs +51 -0
- package/build/generateQueryPageResolvers.cjs.map +1 -0
- package/build/generateQueryPageResolvers.d.cts +8 -0
- package/build/generateQueryPageResolvers.d.cts.map +1 -0
- package/build/generateQueryPageResolvers.d.mts +8 -0
- package/build/generateQueryPageResolvers.d.mts.map +1 -0
- package/build/generateQueryPageResolvers.js +31 -35
- package/build/generateQueryPageResolvers.js.map +1 -1
- package/build/generateQueryResolvers.cjs +55 -0
- package/build/generateQueryResolvers.cjs.map +1 -0
- package/build/generateQueryResolvers.d.cts +10 -0
- package/build/generateQueryResolvers.d.cts.map +1 -0
- package/build/generateQueryResolvers.d.mts +10 -0
- package/build/generateQueryResolvers.d.mts.map +1 -0
- package/build/generateQueryResolvers.js +38 -36
- package/build/generateQueryResolvers.js.map +1 -1
- package/build/generateResolverUtils.cjs +36 -0
- package/build/generateResolverUtils.cjs.map +1 -0
- package/build/generateResolverUtils.d.cts +8 -0
- package/build/generateResolverUtils.d.cts.map +1 -0
- package/build/generateResolverUtils.d.mts +8 -0
- package/build/generateResolverUtils.d.mts.map +1 -0
- package/build/generateResolverUtils.js +25 -26
- package/build/generateResolverUtils.js.map +1 -1
- package/build/generateSaveResolvers.cjs +57 -0
- package/build/generateSaveResolvers.cjs.map +1 -0
- package/build/{generateSaveResolvers.d.ts → generateSaveResolvers.d.cts} +5 -1
- package/build/generateSaveResolvers.d.cts.map +1 -0
- package/build/generateSaveResolvers.d.mts +17 -0
- package/build/generateSaveResolvers.d.mts.map +1 -0
- package/build/generateSaveResolvers.js +39 -40
- package/build/generateSaveResolvers.js.map +1 -1
- package/build/graphqlUtils.cjs +160 -0
- package/build/graphqlUtils.cjs.map +1 -0
- package/build/graphqlUtils.d.cts +31 -0
- package/build/graphqlUtils.d.cts.map +1 -0
- package/build/graphqlUtils.d.mts +31 -0
- package/build/graphqlUtils.d.mts.map +1 -0
- package/build/graphqlUtils.js +120 -218
- package/build/graphqlUtils.js.map +1 -1
- package/build/history.cjs +25 -0
- package/build/history.cjs.map +1 -0
- package/build/history.d.cts +9 -0
- package/build/history.d.cts.map +1 -0
- package/build/history.d.mts +9 -0
- package/build/history.d.mts.map +1 -0
- package/build/history.js +17 -14
- package/build/history.js.map +1 -1
- package/build/index.cjs +57 -0
- package/build/index.cjs.map +1 -0
- package/build/index.d.cts +7 -0
- package/build/index.d.cts.map +1 -0
- package/build/index.d.mts +7 -0
- package/build/index.d.mts.map +1 -0
- package/build/index.js +48 -54
- package/build/index.js.map +1 -1
- package/build/testUtils.cjs +181 -0
- package/build/testUtils.cjs.map +1 -0
- package/build/testUtils.d.cts +20 -0
- package/build/testUtils.d.cts.map +1 -0
- package/build/testUtils.d.mts +20 -0
- package/build/testUtils.d.mts.map +1 -0
- package/build/testUtils.js +152 -158
- package/build/testUtils.js.map +1 -1
- package/build/utils.cjs +51 -0
- package/build/utils.cjs.map +1 -0
- package/build/utils.d.cts +16 -0
- package/build/utils.d.cts.map +1 -0
- package/build/utils.d.mts +16 -0
- package/build/utils.d.mts.map +1 -0
- package/build/utils.js +37 -49
- package/build/utils.js.map +1 -1
- package/package.json +28 -5
- package/build/generateEnumDetailResolvers.d.ts +0 -4
- package/build/generateEnumsGraphql.d.ts +0 -4
- package/build/generateGraphqlCodegen.d.ts +0 -4
- package/build/generateQueryPageResolvers.d.ts +0 -4
- package/build/generateQueryResolvers.d.ts +0 -6
- package/build/generateResolverUtils.d.ts +0 -4
- package/build/graphqlUtils.d.ts +0 -27
- package/build/history.d.ts +0 -5
- package/build/index.d.ts +0 -3
- package/build/testUtils.d.ts +0 -24
- package/build/utils.d.ts +0 -12
|
@@ -1,330 +1,488 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const pluralize_1 = __importDefault(require("pluralize"));
|
|
10
|
-
const graphqlUtils_1 = require("./graphqlUtils");
|
|
11
|
-
const history_1 = require("./history");
|
|
1
|
+
import "./utils.js";
|
|
2
|
+
import { mapTypescriptTypeToGraphQLType, upsertIntoFile } from "./graphqlUtils.js";
|
|
3
|
+
import { loadHistory, writeHistory } from "./history.js";
|
|
4
|
+
import { camelCase } from "change-case";
|
|
5
|
+
import "joist-codegen";
|
|
6
|
+
import pluralize from "pluralize";
|
|
7
|
+
import { groupBy } from "joist-utils";
|
|
8
|
+
//#region src/generateGraphqlSchemaFiles.ts
|
|
12
9
|
/**
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
10
|
+
* Generates `*.graphql` files based on the database schema.
|
|
11
|
+
*
|
|
12
|
+
* This follows an "evergreen" approach where we upsert changes into files that are also
|
|
13
|
+
* hand-modified by the programmer. We remember what insertions we've made in a history file,
|
|
14
|
+
* and will only do them once, which allows programmers to manually add/edit/remove fields
|
|
15
|
+
* without this stomping over their changes.
|
|
16
|
+
*/
|
|
20
17
|
async function generateGraphqlSchemaFiles(config, fs, dbMeta) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const { objectName, types } = entry;
|
|
53
|
-
history[objectName] = types;
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
const { objectName, fieldName } = entry;
|
|
57
|
-
const fields = (history[objectName] = history[objectName] || []);
|
|
58
|
-
if (!fields.includes(fieldName)) {
|
|
59
|
-
fields.push(fieldName);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
await (0, history_1.writeHistory)(fs, history);
|
|
18
|
+
const { entities } = dbMeta;
|
|
19
|
+
const fields = [
|
|
20
|
+
...createPageInfoFields(config),
|
|
21
|
+
...createQueryFields(config, entities),
|
|
22
|
+
...createSaveMutation(entities),
|
|
23
|
+
...createEntityFields(dbMeta),
|
|
24
|
+
...createFilterFields(dbMeta),
|
|
25
|
+
...createSaveEntityInputFields(dbMeta),
|
|
26
|
+
...createSaveEntityResultFields(entities)
|
|
27
|
+
];
|
|
28
|
+
const unions = createPolymorphicUnions(entities);
|
|
29
|
+
const history = await loadHistory(fs);
|
|
30
|
+
const newEntries = [...fields.filter(({ objectName, fieldName }) => !history[objectName]?.includes(fieldName)), ...unions.filter(({ objectName, types }) => {
|
|
31
|
+
const set = new Set(history[objectName] ?? []);
|
|
32
|
+
return !(set.size === types.length && types.every((type) => set.has(type)));
|
|
33
|
+
})];
|
|
34
|
+
if (newEntries.length === 0) return;
|
|
35
|
+
await Promise.all(Object.entries(groupBy(newEntries, (f) => f.file)).map(([file, fields]) => {
|
|
36
|
+
return upsertIntoFile(fs, file, fields);
|
|
37
|
+
}));
|
|
38
|
+
newEntries.forEach((entry) => {
|
|
39
|
+
if (entry.objectType === "union") {
|
|
40
|
+
const { objectName, types } = entry;
|
|
41
|
+
history[objectName] = types;
|
|
42
|
+
} else {
|
|
43
|
+
const { objectName, fieldName } = entry;
|
|
44
|
+
const fields = history[objectName] = history[objectName] || [];
|
|
45
|
+
if (!fields.includes(fieldName)) fields.push(fieldName);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
await writeHistory(fs, history);
|
|
64
49
|
}
|
|
65
50
|
/** Makes the project's pagination metadata type. */
|
|
66
51
|
function createPageInfoFields(config) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
52
|
+
const common = {
|
|
53
|
+
file: "pageInfo.graphql",
|
|
54
|
+
objectType: "output",
|
|
55
|
+
objectName: "PageInfo"
|
|
56
|
+
};
|
|
57
|
+
const shared = [
|
|
58
|
+
{
|
|
59
|
+
...common,
|
|
60
|
+
fieldName: "hasNextPage",
|
|
61
|
+
fieldType: "Boolean!"
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
...common,
|
|
65
|
+
fieldName: "hasPreviousPage",
|
|
66
|
+
fieldType: "Boolean!"
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
...common,
|
|
70
|
+
fieldName: "totalCount",
|
|
71
|
+
fieldType: "Int!"
|
|
72
|
+
}
|
|
73
|
+
];
|
|
74
|
+
if ((config.paginationStyle ?? "cursor") === "limit") return [
|
|
75
|
+
...shared,
|
|
76
|
+
{
|
|
77
|
+
...common,
|
|
78
|
+
fieldName: "nextPage",
|
|
79
|
+
fieldType: "Int"
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
...common,
|
|
83
|
+
fieldName: "currentPage",
|
|
84
|
+
fieldType: "Int"
|
|
85
|
+
}
|
|
86
|
+
];
|
|
87
|
+
return [
|
|
88
|
+
...shared,
|
|
89
|
+
{
|
|
90
|
+
...common,
|
|
91
|
+
fieldName: "startCursor",
|
|
92
|
+
fieldType: "String"
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
...common,
|
|
96
|
+
fieldName: "endCursor",
|
|
97
|
+
fieldType: "String"
|
|
98
|
+
}
|
|
99
|
+
];
|
|
87
100
|
}
|
|
88
101
|
/** Make all the fields for `type Author`, `type Book`, etc. */
|
|
89
102
|
function createPolymorphicUnions(entities) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
103
|
+
return entities.flatMap((e) => {
|
|
104
|
+
const file = fileName(e);
|
|
105
|
+
return e.polymorphics.map(({ fieldType, components }) => {
|
|
106
|
+
return {
|
|
107
|
+
file,
|
|
108
|
+
objectType: "union",
|
|
109
|
+
objectName: fieldType,
|
|
110
|
+
types: components.map((c) => c.otherEntity.name)
|
|
111
|
+
};
|
|
112
|
+
});
|
|
113
|
+
});
|
|
96
114
|
}
|
|
97
115
|
/** Make all the fields for `type Author`, `type Book`, etc. */
|
|
98
116
|
function createEntityFields(dbMeta) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
117
|
+
const { entities } = dbMeta;
|
|
118
|
+
return entities.flatMap((e) => {
|
|
119
|
+
const common = {
|
|
120
|
+
file: fileName(e),
|
|
121
|
+
objectType: "output",
|
|
122
|
+
objectName: e.entity.name
|
|
123
|
+
};
|
|
124
|
+
const id = {
|
|
125
|
+
...common,
|
|
126
|
+
fieldName: "id",
|
|
127
|
+
fieldType: "ID!"
|
|
128
|
+
};
|
|
129
|
+
const primitives = e.primitives.flatMap(({ fieldName, fieldType: tsType, isArray, notNull }) => {
|
|
130
|
+
const fieldType = primitiveFieldType(fieldName, tsType, isArray, notNull);
|
|
131
|
+
if (!fieldType) return [];
|
|
132
|
+
return [{
|
|
133
|
+
...common,
|
|
134
|
+
fieldName,
|
|
135
|
+
fieldType
|
|
136
|
+
}];
|
|
137
|
+
});
|
|
138
|
+
const enums = e.enums.map(({ fieldName, enumType, notNull, isArray }) => {
|
|
139
|
+
const fieldType = isArray ? `[${enumType.symbol}!]!` : `${enumType.symbol}Detail${maybeRequired(notNull)}`;
|
|
140
|
+
return {
|
|
141
|
+
...common,
|
|
142
|
+
fieldName,
|
|
143
|
+
fieldType
|
|
144
|
+
};
|
|
145
|
+
});
|
|
146
|
+
const pgEnums = e.pgEnums.map(({ fieldName, enumType, notNull }) => {
|
|
147
|
+
const fieldType = `${enumType.symbol}${maybeRequired(notNull)}`;
|
|
148
|
+
return {
|
|
149
|
+
...common,
|
|
150
|
+
fieldName,
|
|
151
|
+
fieldType
|
|
152
|
+
};
|
|
153
|
+
});
|
|
154
|
+
const m2os = e.manyToOnes.map(({ fieldName, otherEntity, notNull }) => {
|
|
155
|
+
const other = dbMeta.entitiesByName[otherEntity.name];
|
|
156
|
+
const maybeLike = other.subTypes.length > 0 && !other.abstract ? "Like" : "";
|
|
157
|
+
const fieldType = `${otherEntity.name}${maybeLike}${maybeRequired(notNull)}`;
|
|
158
|
+
return {
|
|
159
|
+
...common,
|
|
160
|
+
fieldName,
|
|
161
|
+
fieldType
|
|
162
|
+
};
|
|
163
|
+
});
|
|
164
|
+
const o2ms = e.oneToManys.map(({ fieldName, otherEntity }) => {
|
|
165
|
+
const fieldType = `[${otherEntity.name}!]!`;
|
|
166
|
+
return {
|
|
167
|
+
...common,
|
|
168
|
+
fieldName,
|
|
169
|
+
fieldType
|
|
170
|
+
};
|
|
171
|
+
});
|
|
172
|
+
const m2ms = e.manyToManys.map(({ fieldName, otherEntity }) => {
|
|
173
|
+
const fieldType = `[${otherEntity.name}!]!`;
|
|
174
|
+
return {
|
|
175
|
+
...common,
|
|
176
|
+
fieldName,
|
|
177
|
+
fieldType
|
|
178
|
+
};
|
|
179
|
+
});
|
|
180
|
+
const o2os = e.oneToOnes.map(({ fieldName, otherEntity }) => {
|
|
181
|
+
return {
|
|
182
|
+
...common,
|
|
183
|
+
fieldName,
|
|
184
|
+
fieldType: otherEntity.name
|
|
185
|
+
};
|
|
186
|
+
});
|
|
187
|
+
const polys = e.polymorphics.map(({ fieldName, fieldType }) => {
|
|
188
|
+
return {
|
|
189
|
+
...common,
|
|
190
|
+
fieldName,
|
|
191
|
+
fieldType
|
|
192
|
+
};
|
|
193
|
+
});
|
|
194
|
+
return [
|
|
195
|
+
id,
|
|
196
|
+
...e.baseClassName ? createEntityFields(findBaseEntity(dbMeta, e.baseClassName)).map((f) => ({
|
|
197
|
+
...f,
|
|
198
|
+
...common
|
|
199
|
+
})).filter((f) => f.fieldName !== "id") : [],
|
|
200
|
+
...primitives,
|
|
201
|
+
...enums,
|
|
202
|
+
...pgEnums,
|
|
203
|
+
...m2os,
|
|
204
|
+
...o2ms,
|
|
205
|
+
...m2ms,
|
|
206
|
+
...o2os,
|
|
207
|
+
...polys
|
|
208
|
+
];
|
|
209
|
+
});
|
|
148
210
|
}
|
|
149
211
|
/** Makes the `Mutations.save${entity}` placeholder. */
|
|
150
212
|
function createSaveMutation(entities) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
213
|
+
return entities.map((e) => {
|
|
214
|
+
const file = fileName(e);
|
|
215
|
+
const inputType = `Save${e.entity.name}Input`;
|
|
216
|
+
const outputType = `Save${e.entity.name}Result`;
|
|
217
|
+
return {
|
|
218
|
+
file,
|
|
219
|
+
objectType: "output",
|
|
220
|
+
objectName: "Mutation",
|
|
221
|
+
fieldName: `save${e.entity.name}`,
|
|
222
|
+
fieldType: `${outputType}!`,
|
|
223
|
+
argsString: `input: ${inputType}!`,
|
|
224
|
+
extends: true
|
|
225
|
+
};
|
|
226
|
+
});
|
|
165
227
|
}
|
|
166
228
|
/** Makes the `Query.${entity}` and `Query.${entity}s` placeholders. */
|
|
167
229
|
function createQueryFields(config, entities) {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
];
|
|
199
|
-
});
|
|
230
|
+
return entities.flatMap((e) => {
|
|
231
|
+
const file = fileName(e);
|
|
232
|
+
const { name } = e.entity;
|
|
233
|
+
const pluralName = pluralize(name);
|
|
234
|
+
const camelName = camelCase(name);
|
|
235
|
+
const pluralCamelName = pluralize(camelName);
|
|
236
|
+
const collectionType = (config.paginationStyle ?? "cursor") === "limit" ? `${pluralName}Page!` : `${pluralName}Connection!`;
|
|
237
|
+
const collectionArgs = (config.paginationStyle ?? "cursor") === "limit" ? `filter: ${name}Filter, limit: Int, offset: Int` : `filter: ${name}Filter, first: Int, after: String, last: Int, before: String`;
|
|
238
|
+
return [
|
|
239
|
+
{
|
|
240
|
+
file,
|
|
241
|
+
objectType: "output",
|
|
242
|
+
objectName: "Query",
|
|
243
|
+
fieldName: camelName,
|
|
244
|
+
fieldType: `${name}!`,
|
|
245
|
+
argsString: `id: ID!`,
|
|
246
|
+
extends: true
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
file,
|
|
250
|
+
objectType: "output",
|
|
251
|
+
objectName: "Query",
|
|
252
|
+
fieldName: pluralCamelName,
|
|
253
|
+
fieldType: collectionType,
|
|
254
|
+
argsString: collectionArgs,
|
|
255
|
+
extends: true
|
|
256
|
+
},
|
|
257
|
+
...createPaginationTypes(config, file, e)
|
|
258
|
+
];
|
|
259
|
+
});
|
|
200
260
|
}
|
|
201
261
|
/** Makes the `AuthorFilter`, `BookFilter`, etc. input types. */
|
|
202
262
|
function createFilterFields(dbMeta) {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
263
|
+
const { entities } = dbMeta;
|
|
264
|
+
return entities.flatMap((e) => {
|
|
265
|
+
const common = {
|
|
266
|
+
file: fileName(e),
|
|
267
|
+
objectType: "input",
|
|
268
|
+
objectName: `${e.entity.name}Filter`
|
|
269
|
+
};
|
|
270
|
+
const id = {
|
|
271
|
+
...common,
|
|
272
|
+
fieldName: "id",
|
|
273
|
+
fieldType: filterListType("ID")
|
|
274
|
+
};
|
|
275
|
+
const primitives = e.primitives.flatMap(({ fieldName, fieldType: tsType, isArray }) => {
|
|
276
|
+
const fieldType = primitiveFieldType(fieldName, tsType, isArray);
|
|
277
|
+
if (!fieldType) return [];
|
|
278
|
+
return [{
|
|
279
|
+
...common,
|
|
280
|
+
fieldName,
|
|
281
|
+
fieldType: filterListType(fieldType)
|
|
282
|
+
}];
|
|
283
|
+
});
|
|
284
|
+
const enums = e.enums.map(({ fieldName, enumType, isArray }) => {
|
|
285
|
+
const fieldType = isArray ? `[${enumType.symbol}!]` : enumType.symbol;
|
|
286
|
+
return {
|
|
287
|
+
...common,
|
|
288
|
+
fieldName,
|
|
289
|
+
fieldType: filterListType(fieldType)
|
|
290
|
+
};
|
|
291
|
+
});
|
|
292
|
+
const pgEnums = e.pgEnums.map(({ fieldName, enumType }) => {
|
|
293
|
+
return {
|
|
294
|
+
...common,
|
|
295
|
+
fieldName,
|
|
296
|
+
fieldType: filterListType(enumType.symbol)
|
|
297
|
+
};
|
|
298
|
+
});
|
|
299
|
+
const m2os = e.manyToOnes.map(({ fieldName }) => {
|
|
300
|
+
return {
|
|
301
|
+
...common,
|
|
302
|
+
fieldName: `${fieldName}Id`,
|
|
303
|
+
fieldType: filterListType("ID")
|
|
304
|
+
};
|
|
305
|
+
});
|
|
306
|
+
const polys = e.polymorphics.map(({ fieldName }) => {
|
|
307
|
+
return {
|
|
308
|
+
...common,
|
|
309
|
+
fieldName: `${fieldName}Id`,
|
|
310
|
+
fieldType: filterListType("ID")
|
|
311
|
+
};
|
|
312
|
+
});
|
|
313
|
+
return [
|
|
314
|
+
id,
|
|
315
|
+
...e.baseClassName ? createFilterFields(findBaseEntity(dbMeta, e.baseClassName)).map((f) => ({
|
|
316
|
+
...f,
|
|
317
|
+
...common
|
|
318
|
+
})).filter((f) => f.fieldName !== "id") : [],
|
|
319
|
+
...primitives,
|
|
320
|
+
...enums,
|
|
321
|
+
...pgEnums,
|
|
322
|
+
...m2os,
|
|
323
|
+
...polys
|
|
324
|
+
];
|
|
325
|
+
});
|
|
236
326
|
}
|
|
237
327
|
/** Makes the page/connection types for `Query.authors`. */
|
|
238
328
|
function createPaginationTypes(config, file, e) {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
329
|
+
const { name } = e.entity;
|
|
330
|
+
const pluralName = pluralize(name);
|
|
331
|
+
const objectType = "output";
|
|
332
|
+
if ((config.paginationStyle ?? "cursor") === "limit") return [{
|
|
333
|
+
file,
|
|
334
|
+
objectType,
|
|
335
|
+
objectName: `${pluralName}Page`,
|
|
336
|
+
fieldName: "entities",
|
|
337
|
+
fieldType: `[${name}!]!`
|
|
338
|
+
}, {
|
|
339
|
+
file,
|
|
340
|
+
objectType,
|
|
341
|
+
objectName: `${pluralName}Page`,
|
|
342
|
+
fieldName: "pageInfo",
|
|
343
|
+
fieldType: "PageInfo!"
|
|
344
|
+
}];
|
|
345
|
+
return [
|
|
346
|
+
{
|
|
347
|
+
file,
|
|
348
|
+
objectType,
|
|
349
|
+
objectName: `${pluralName}Connection`,
|
|
350
|
+
fieldName: "edges",
|
|
351
|
+
fieldType: `[${pluralName}Edge!]!`
|
|
352
|
+
},
|
|
353
|
+
{
|
|
354
|
+
file,
|
|
355
|
+
objectType,
|
|
356
|
+
objectName: `${pluralName}Connection`,
|
|
357
|
+
fieldName: "nodes",
|
|
358
|
+
fieldType: `[${name}!]!`
|
|
359
|
+
},
|
|
360
|
+
{
|
|
361
|
+
file,
|
|
362
|
+
objectType,
|
|
363
|
+
objectName: `${pluralName}Connection`,
|
|
364
|
+
fieldName: "pageInfo",
|
|
365
|
+
fieldType: "PageInfo!"
|
|
366
|
+
},
|
|
367
|
+
{
|
|
368
|
+
file,
|
|
369
|
+
objectType,
|
|
370
|
+
objectName: `${pluralName}Edge`,
|
|
371
|
+
fieldName: "node",
|
|
372
|
+
fieldType: `${name}!`
|
|
373
|
+
},
|
|
374
|
+
{
|
|
375
|
+
file,
|
|
376
|
+
objectType,
|
|
377
|
+
objectName: `${pluralName}Edge`,
|
|
378
|
+
fieldName: "cursor",
|
|
379
|
+
fieldType: "String!"
|
|
380
|
+
}
|
|
381
|
+
];
|
|
255
382
|
}
|
|
256
383
|
/** Make all the fields for `type SaveAuthorInput`, `type SaveBookBook`, etc. */
|
|
257
384
|
function createSaveEntityInputFields(dbMeta) {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
385
|
+
const { entities } = dbMeta;
|
|
386
|
+
return entities.flatMap((e) => {
|
|
387
|
+
const common = {
|
|
388
|
+
file: fileName(e),
|
|
389
|
+
objectType: "input",
|
|
390
|
+
objectName: `Save${e.entity.name}Input`
|
|
391
|
+
};
|
|
392
|
+
const id = {
|
|
393
|
+
...common,
|
|
394
|
+
fieldName: "id",
|
|
395
|
+
fieldType: "ID"
|
|
396
|
+
};
|
|
397
|
+
const primitives = e.primitives.filter((f) => f.derived === false).flatMap(({ fieldName, fieldType: tsType, isArray }) => {
|
|
398
|
+
const fieldType = primitiveFieldType(fieldName, tsType, isArray);
|
|
399
|
+
if (!fieldType) return [];
|
|
400
|
+
return [{
|
|
401
|
+
...common,
|
|
402
|
+
fieldName,
|
|
403
|
+
fieldType
|
|
404
|
+
}];
|
|
405
|
+
});
|
|
406
|
+
const enums = e.enums.map(({ fieldName, enumType, isArray }) => {
|
|
407
|
+
return {
|
|
408
|
+
...common,
|
|
409
|
+
fieldName,
|
|
410
|
+
fieldType: isArray ? `[${enumType.symbol}!]` : enumType.symbol
|
|
411
|
+
};
|
|
412
|
+
});
|
|
413
|
+
const pgEnums = e.pgEnums.map(({ fieldName, enumType }) => {
|
|
414
|
+
return {
|
|
415
|
+
...common,
|
|
416
|
+
fieldName,
|
|
417
|
+
fieldType: enumType.symbol
|
|
418
|
+
};
|
|
419
|
+
});
|
|
420
|
+
const m2os = e.manyToOnes.map(({ fieldName }) => {
|
|
421
|
+
return {
|
|
422
|
+
...common,
|
|
423
|
+
fieldName: `${fieldName}Id`,
|
|
424
|
+
fieldType: "ID"
|
|
425
|
+
};
|
|
426
|
+
});
|
|
427
|
+
const polys = e.polymorphics.map(({ fieldName }) => {
|
|
428
|
+
return {
|
|
429
|
+
...common,
|
|
430
|
+
fieldName: `${fieldName}Id`,
|
|
431
|
+
fieldType: "ID"
|
|
432
|
+
};
|
|
433
|
+
});
|
|
434
|
+
return [
|
|
435
|
+
id,
|
|
436
|
+
...e.baseClassName ? createSaveEntityInputFields(findBaseEntity(dbMeta, e.baseClassName)).map((f) => ({
|
|
437
|
+
...f,
|
|
438
|
+
...common
|
|
439
|
+
})).filter((f) => f.fieldName !== "id") : [],
|
|
440
|
+
...primitives,
|
|
441
|
+
...enums,
|
|
442
|
+
...pgEnums,
|
|
443
|
+
...m2os,
|
|
444
|
+
...polys
|
|
445
|
+
];
|
|
446
|
+
});
|
|
292
447
|
}
|
|
293
448
|
/** Makes the fields for `type SaveAuthorResult`, `type SaveBookResult`, etc. */
|
|
294
449
|
function createSaveEntityResultFields(entities) {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
450
|
+
return entities.flatMap((e) => {
|
|
451
|
+
const file = fileName(e);
|
|
452
|
+
const { entity: { name } } = e;
|
|
453
|
+
return [{
|
|
454
|
+
file,
|
|
455
|
+
objectType: "output",
|
|
456
|
+
objectName: `Save${name}Result`,
|
|
457
|
+
fieldName: camelCase(name),
|
|
458
|
+
fieldType: `${name}!`
|
|
459
|
+
}];
|
|
460
|
+
});
|
|
304
461
|
}
|
|
305
462
|
function maybeRequired(notNull) {
|
|
306
|
-
|
|
463
|
+
return notNull ? "!" : "";
|
|
307
464
|
}
|
|
308
465
|
/** Returns the GraphQL type for primitive fields, including primitive arrays. */
|
|
309
466
|
function primitiveFieldType(fieldName, tsType, isArray, notNull = false) {
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
const fieldType = isArray ? `[${gqlType}!]` : gqlType;
|
|
314
|
-
return `${fieldType}${maybeRequired(notNull)}`;
|
|
467
|
+
const gqlType = mapTypescriptTypeToGraphQLType(fieldName, tsType);
|
|
468
|
+
if (!gqlType) return void 0;
|
|
469
|
+
return `${isArray ? `[${gqlType}!]` : gqlType}${maybeRequired(notNull)}`;
|
|
315
470
|
}
|
|
316
471
|
/** Wraps filter fields in lists so GraphQL callers can pass one value or OR several values. */
|
|
317
472
|
function filterListType(fieldType) {
|
|
318
|
-
|
|
473
|
+
return `[${fieldType}!]`;
|
|
319
474
|
}
|
|
320
475
|
/** I.e. `Book` --> `books.graphql`. */
|
|
321
476
|
function fileName(e) {
|
|
322
|
-
|
|
477
|
+
return `${camelCase(e.entity.name)}.graphql`;
|
|
323
478
|
}
|
|
324
479
|
function findBaseEntity(dbMeta, baseClassName) {
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
480
|
+
return {
|
|
481
|
+
...dbMeta,
|
|
482
|
+
entities: dbMeta.entities.filter((e) => e.entity.name === baseClassName)
|
|
483
|
+
};
|
|
329
484
|
}
|
|
485
|
+
//#endregion
|
|
486
|
+
export { generateGraphqlSchemaFiles };
|
|
487
|
+
|
|
330
488
|
//# sourceMappingURL=generateGraphqlSchemaFiles.js.map
|