@baeta/plugin-graphql 0.0.2 → 0.0.3
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/index.cjs +1282 -0
- package/dist/index.d.ts +10 -3
- package/dist/index.js +1260 -21
- package/package.json +13 -12
- package/dist/codegen.d.ts +0 -6
- package/dist/codegen.js +0 -116
- package/dist/codegen.mjs +0 -89
- package/dist/config.d.ts +0 -10
- package/dist/config.js +0 -16
- package/dist/config.mjs +0 -0
- package/dist/index.mjs +0 -19
- package/dist/modules/builder.d.ts +0 -17
- package/dist/modules/builder.js +0 -439
- package/dist/modules/builder.mjs +0 -429
- package/dist/modules/config.d.ts +0 -11
- package/dist/modules/config.js +0 -16
- package/dist/modules/config.mjs +0 -0
- package/dist/modules/index.d.ts +0 -6
- package/dist/modules/index.js +0 -148
- package/dist/modules/index.mjs +0 -132
- package/dist/modules/utils.d.ts +0 -28
- package/dist/modules/utils.js +0 -209
- package/dist/modules/utils.mjs +0 -168
- package/dist/resolvers/config.d.ts +0 -16
- package/dist/resolvers/config.js +0 -16
- package/dist/resolvers/config.mjs +0 -0
- package/dist/resolvers/index.d.ts +0 -10
- package/dist/resolvers/index.js +0 -309
- package/dist/resolvers/index.mjs +0 -289
- package/dist/resolvers/visitor.d.ts +0 -29
- package/dist/resolvers/visitor.js +0 -139
- package/dist/resolvers/visitor.mjs +0 -111
- package/dist/utils/cache.d.ts +0 -3
- package/dist/utils/cache.js +0 -40
- package/dist/utils/cache.mjs +0 -16
- package/dist/utils/hash.d.ts +0 -6
- package/dist/utils/hash.js +0 -38
- package/dist/utils/hash.mjs +0 -13
- package/dist/utils/load.d.ts +0 -9
- package/dist/utils/load.js +0 -62
- package/dist/utils/load.mjs +0 -40
- package/dist/utils/path.d.ts +0 -3
- package/dist/utils/path.js +0 -37
- package/dist/utils/path.mjs +0 -7
package/dist/modules/builder.mjs
DELETED
|
@@ -1,429 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
visit,
|
|
3
|
-
Kind,
|
|
4
|
-
isScalarType
|
|
5
|
-
} from "graphql";
|
|
6
|
-
import { pascalCase } from "change-case-all";
|
|
7
|
-
import {
|
|
8
|
-
unique,
|
|
9
|
-
withQuotes,
|
|
10
|
-
buildBlock,
|
|
11
|
-
pushUnique,
|
|
12
|
-
concatByKey,
|
|
13
|
-
uniqueByKey,
|
|
14
|
-
createObject,
|
|
15
|
-
collectUsedTypes,
|
|
16
|
-
indent
|
|
17
|
-
} from "./utils";
|
|
18
|
-
const registryKeys = [
|
|
19
|
-
"objects",
|
|
20
|
-
"inputs",
|
|
21
|
-
"interfaces",
|
|
22
|
-
"scalars",
|
|
23
|
-
"unions",
|
|
24
|
-
"enums"
|
|
25
|
-
];
|
|
26
|
-
const resolverKeys = ["scalars", "objects", "enums"];
|
|
27
|
-
function buildModule(name, doc, {
|
|
28
|
-
importNamespace,
|
|
29
|
-
importPath,
|
|
30
|
-
encapsulate,
|
|
31
|
-
requireRootResolvers,
|
|
32
|
-
shouldDeclare,
|
|
33
|
-
rootTypes,
|
|
34
|
-
schema,
|
|
35
|
-
baseVisitor
|
|
36
|
-
}) {
|
|
37
|
-
const picks = createObject(
|
|
38
|
-
registryKeys,
|
|
39
|
-
() => ({})
|
|
40
|
-
);
|
|
41
|
-
const defined = createObject(registryKeys, () => []);
|
|
42
|
-
const extended = createObject(registryKeys, () => []);
|
|
43
|
-
const usedTypes = collectUsedTypes(doc);
|
|
44
|
-
visit(doc, {
|
|
45
|
-
ObjectTypeDefinition(node) {
|
|
46
|
-
collectTypeDefinition(node);
|
|
47
|
-
},
|
|
48
|
-
ObjectTypeExtension(node) {
|
|
49
|
-
collectTypeExtension(node);
|
|
50
|
-
},
|
|
51
|
-
InputObjectTypeDefinition(node) {
|
|
52
|
-
collectTypeDefinition(node);
|
|
53
|
-
},
|
|
54
|
-
InputObjectTypeExtension(node) {
|
|
55
|
-
collectTypeExtension(node);
|
|
56
|
-
},
|
|
57
|
-
InterfaceTypeDefinition(node) {
|
|
58
|
-
collectTypeDefinition(node);
|
|
59
|
-
},
|
|
60
|
-
InterfaceTypeExtension(node) {
|
|
61
|
-
collectTypeExtension(node);
|
|
62
|
-
},
|
|
63
|
-
ScalarTypeDefinition(node) {
|
|
64
|
-
collectTypeDefinition(node);
|
|
65
|
-
},
|
|
66
|
-
UnionTypeDefinition(node) {
|
|
67
|
-
collectTypeDefinition(node);
|
|
68
|
-
},
|
|
69
|
-
UnionTypeExtension(node) {
|
|
70
|
-
collectTypeExtension(node);
|
|
71
|
-
},
|
|
72
|
-
EnumTypeDefinition(node) {
|
|
73
|
-
collectTypeDefinition(node);
|
|
74
|
-
},
|
|
75
|
-
EnumTypeExtension(node) {
|
|
76
|
-
collectTypeExtension(node);
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
const visited = createObject(
|
|
80
|
-
registryKeys,
|
|
81
|
-
(key) => concatByKey(defined, extended, key)
|
|
82
|
-
);
|
|
83
|
-
const external = createObject(
|
|
84
|
-
registryKeys,
|
|
85
|
-
(key) => uniqueByKey(extended, defined, key)
|
|
86
|
-
);
|
|
87
|
-
const imports = [
|
|
88
|
-
`import * as ${importNamespace} from "${importPath}";`,
|
|
89
|
-
'import { DocumentNode } from "graphql";',
|
|
90
|
-
'import * as Baeta from "@baeta/core/sdk";'
|
|
91
|
-
];
|
|
92
|
-
let content = [
|
|
93
|
-
printDefinedFields(),
|
|
94
|
-
printDefinedEnumValues(),
|
|
95
|
-
printDefinedInputFields(),
|
|
96
|
-
printSchemaTypes(usedTypes),
|
|
97
|
-
printScalars(visited),
|
|
98
|
-
printResolveSignaturesPerType(visited),
|
|
99
|
-
printResolversType(visited),
|
|
100
|
-
printMetadata()
|
|
101
|
-
].filter(Boolean).join("\n\n");
|
|
102
|
-
const moduleNamespace = baseVisitor.convertName(name, {
|
|
103
|
-
suffix: "Module",
|
|
104
|
-
useTypesPrefix: false,
|
|
105
|
-
useTypesSuffix: false
|
|
106
|
-
});
|
|
107
|
-
if (encapsulate === "namespace") {
|
|
108
|
-
content = `${shouldDeclare ? "declare" : "export"} namespace ${baseVisitor.convertName(name, {
|
|
109
|
-
suffix: "Module",
|
|
110
|
-
useTypesPrefix: false,
|
|
111
|
-
useTypesSuffix: false
|
|
112
|
-
})} {
|
|
113
|
-
` + (shouldDeclare ? `${indent(2)(imports.join("\n"))}
|
|
114
|
-
` : "") + indent(2)(content) + "\n}";
|
|
115
|
-
}
|
|
116
|
-
return [...!shouldDeclare ? imports : [], content, printFactoryMethod()].filter(Boolean).join("\n");
|
|
117
|
-
function printMetadata() {
|
|
118
|
-
return `export namespace ModuleMetadata {
|
|
119
|
-
export const id = '${name}';
|
|
120
|
-
export const dirname = __dirname;
|
|
121
|
-
export const typedef = ${JSON.stringify(doc)} as unknown as DocumentNode;
|
|
122
|
-
${printBaetaManager()}
|
|
123
|
-
}`;
|
|
124
|
-
}
|
|
125
|
-
function printDefinedFields() {
|
|
126
|
-
return buildBlock({
|
|
127
|
-
name: `interface DefinedFields`,
|
|
128
|
-
lines: [...visited.objects, ...visited.interfaces].map(
|
|
129
|
-
(typeName) => `${typeName}: ${printPicks(typeName, {
|
|
130
|
-
...picks.objects,
|
|
131
|
-
...picks.interfaces
|
|
132
|
-
})};`
|
|
133
|
-
)
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
function printFactoryMethod() {
|
|
137
|
-
const name2 = moduleNamespace.slice(0, moduleNamespace.length - 6);
|
|
138
|
-
const createModuleFn = `create${name2}Module`;
|
|
139
|
-
const getModuleFn = `get${name2}Module`;
|
|
140
|
-
return `
|
|
141
|
-
export const ${createModuleFn} = () => Baeta.createModule(ModuleMetadata);
|
|
142
|
-
export const ${getModuleFn} = Baeta.createSingletonModule(${createModuleFn});
|
|
143
|
-
`;
|
|
144
|
-
}
|
|
145
|
-
function printObjectFieldResolverBuilder(typeName, field) {
|
|
146
|
-
const resolverType = `${typeName}Resolvers["${field}"]`;
|
|
147
|
-
return `${field}: Baeta.createResolverBuilder<NonNullable<${resolverType}>>("${typeName}", "${field}", options),`;
|
|
148
|
-
}
|
|
149
|
-
function printObjectResolverBuilder(typeName, objects) {
|
|
150
|
-
var _a;
|
|
151
|
-
const fields = ((_a = objects[typeName]) == null ? void 0 : _a.filter(unique).map((field) => printObjectFieldResolverBuilder(typeName, field))) ?? [];
|
|
152
|
-
if (fields.length === 0) {
|
|
153
|
-
return "";
|
|
154
|
-
}
|
|
155
|
-
const resolversType = `${typeName}Resolvers`;
|
|
156
|
-
const content2 = `{
|
|
157
|
-
${fields.map(indent(2)).join("\n")}
|
|
158
|
-
}`;
|
|
159
|
-
return `${typeName}: Baeta.createResolversBuilder("${typeName}", options, {} as ${resolversType}, ${content2}),`;
|
|
160
|
-
}
|
|
161
|
-
function printSubscriptionFieldBuilder(field) {
|
|
162
|
-
const resolverType = `SubscriptionResolvers["${field}"]`;
|
|
163
|
-
return `${field}: Baeta.createSubscriptionBuilder<${resolverType}>("${field}", options),`;
|
|
164
|
-
}
|
|
165
|
-
function printSubscriptionObjectBuilder() {
|
|
166
|
-
var _a;
|
|
167
|
-
const subscriptions = ((_a = picks.objects["Subscription"]) == null ? void 0 : _a.filter(unique)) ?? [];
|
|
168
|
-
if (subscriptions.length === 0) {
|
|
169
|
-
return "";
|
|
170
|
-
}
|
|
171
|
-
const fields = subscriptions.map(
|
|
172
|
-
(subscription) => printSubscriptionFieldBuilder(subscription)
|
|
173
|
-
);
|
|
174
|
-
const resolversType = `SubscriptionResolvers`;
|
|
175
|
-
const content2 = `{
|
|
176
|
-
${fields.map(indent(2)).join("\n")}
|
|
177
|
-
}`;
|
|
178
|
-
return `Subscription: Baeta.createSubscriptionsBuilder(options, {} as ${resolversType}, ${content2}),`;
|
|
179
|
-
}
|
|
180
|
-
function printScalarBuilder() {
|
|
181
|
-
const scalars = visited.scalars;
|
|
182
|
-
if (scalars.length === 0) {
|
|
183
|
-
return "";
|
|
184
|
-
}
|
|
185
|
-
const fields = scalars.map(
|
|
186
|
-
(scalar) => `${scalar}: Baeta.createScalarBuilder("${scalar}", options),`
|
|
187
|
-
);
|
|
188
|
-
const content2 = fields.map(indent(2)).join("\n");
|
|
189
|
-
return `Scalar: {
|
|
190
|
-
${content2}
|
|
191
|
-
},`;
|
|
192
|
-
}
|
|
193
|
-
function printBaetaManager() {
|
|
194
|
-
const objects = visited.objects.filter((type) => type !== "Subscription").map((typeName) => printObjectResolverBuilder(typeName, picks.objects)).filter(Boolean);
|
|
195
|
-
const bodyFields = [
|
|
196
|
-
...objects,
|
|
197
|
-
printScalarBuilder(),
|
|
198
|
-
printSubscriptionObjectBuilder()
|
|
199
|
-
];
|
|
200
|
-
const body = bodyFields.filter(Boolean).map(indent(6)).join("\n");
|
|
201
|
-
const content2 = `{
|
|
202
|
-
${body}
|
|
203
|
-
}`;
|
|
204
|
-
return `
|
|
205
|
-
export function createManager(options: Baeta.ManagerOptions) {
|
|
206
|
-
return Baeta.createManager(options, {}, ${content2});
|
|
207
|
-
}`;
|
|
208
|
-
}
|
|
209
|
-
function printDefinedEnumValues() {
|
|
210
|
-
return buildBlock({
|
|
211
|
-
name: `interface DefinedEnumValues`,
|
|
212
|
-
lines: visited.enums.map(
|
|
213
|
-
(typeName) => `${typeName}: ${printPicks(typeName, picks.enums)};`
|
|
214
|
-
)
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
function encapsulateTypeName(typeName) {
|
|
218
|
-
if (encapsulate === "prefix") {
|
|
219
|
-
return `${pascalCase(name)}_${typeName}`;
|
|
220
|
-
}
|
|
221
|
-
return typeName;
|
|
222
|
-
}
|
|
223
|
-
function printDefinedInputFields() {
|
|
224
|
-
return buildBlock({
|
|
225
|
-
name: `interface DefinedInputFields`,
|
|
226
|
-
lines: visited.inputs.map(
|
|
227
|
-
(typeName) => `${typeName}: ${printPicks(typeName, picks.inputs)};`
|
|
228
|
-
)
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
function printSchemaTypes(types) {
|
|
232
|
-
return types.filter((type) => !visited.scalars.includes(type)).map(printExportType).join("\n");
|
|
233
|
-
}
|
|
234
|
-
function printResolveSignaturesPerType(registry) {
|
|
235
|
-
return [
|
|
236
|
-
[...registry.objects, ...registry.interfaces].map(
|
|
237
|
-
(name2) => printResolverType(
|
|
238
|
-
name2,
|
|
239
|
-
"DefinedFields",
|
|
240
|
-
requireRootResolvers && rootTypes.includes(name2),
|
|
241
|
-
!rootTypes.includes(name2) && defined.objects.includes(name2) ? ` | '__isTypeOf'` : ""
|
|
242
|
-
)
|
|
243
|
-
).join("\n")
|
|
244
|
-
].join("\n");
|
|
245
|
-
}
|
|
246
|
-
function printScalars(registry) {
|
|
247
|
-
if (!registry.scalars.length) {
|
|
248
|
-
return "";
|
|
249
|
-
}
|
|
250
|
-
return [
|
|
251
|
-
`export type ${encapsulateTypeName(
|
|
252
|
-
"Scalars"
|
|
253
|
-
)} = Pick<${importNamespace}.Scalars, ${registry.scalars.map(withQuotes).join(" | ")}>;`,
|
|
254
|
-
...registry.scalars.map((scalar) => {
|
|
255
|
-
const convertedName = baseVisitor.convertName(scalar, {
|
|
256
|
-
suffix: "ScalarConfig"
|
|
257
|
-
});
|
|
258
|
-
return `export type ${encapsulateTypeName(
|
|
259
|
-
convertedName
|
|
260
|
-
)} = ${importNamespace}.${convertedName};`;
|
|
261
|
-
})
|
|
262
|
-
].join("\n");
|
|
263
|
-
}
|
|
264
|
-
function printResolversType(registry) {
|
|
265
|
-
const lines = [];
|
|
266
|
-
for (const kind in registry) {
|
|
267
|
-
const k = kind;
|
|
268
|
-
if (registry.hasOwnProperty(k) && resolverKeys.includes(k)) {
|
|
269
|
-
const types = registry[k];
|
|
270
|
-
types.forEach((typeName) => {
|
|
271
|
-
if (k === "enums") {
|
|
272
|
-
return;
|
|
273
|
-
}
|
|
274
|
-
if (k === "scalars") {
|
|
275
|
-
lines.push(
|
|
276
|
-
`${typeName}?: ${encapsulateTypeName(
|
|
277
|
-
importNamespace
|
|
278
|
-
)}.Resolvers['${typeName}'];`
|
|
279
|
-
);
|
|
280
|
-
} else {
|
|
281
|
-
const fieldModifier = requireRootResolvers && rootTypes.includes(typeName) ? "" : "?";
|
|
282
|
-
lines.push(
|
|
283
|
-
`${typeName}${fieldModifier}: ${encapsulateTypeName(
|
|
284
|
-
typeName
|
|
285
|
-
)}Resolvers;`
|
|
286
|
-
);
|
|
287
|
-
}
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
return buildBlock({
|
|
292
|
-
name: `export interface ${encapsulateTypeName("Resolvers")}`,
|
|
293
|
-
lines
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
function printResolverType(typeName, picksTypeName, requireFieldsResolvers = false, extraKeys = "") {
|
|
297
|
-
const typeSignature = `Pick<${importNamespace}.${baseVisitor.convertName(
|
|
298
|
-
typeName,
|
|
299
|
-
{
|
|
300
|
-
suffix: "Resolvers"
|
|
301
|
-
}
|
|
302
|
-
)}, ${picksTypeName}['${typeName}']${extraKeys}>`;
|
|
303
|
-
return `export type ${encapsulateTypeName(`${typeName}Resolvers`)} = ${requireFieldsResolvers ? `Required<${typeSignature}>` : typeSignature};`;
|
|
304
|
-
}
|
|
305
|
-
function printPicks(typeName, records) {
|
|
306
|
-
return records[typeName].filter(unique).map(withQuotes).join(" | ");
|
|
307
|
-
}
|
|
308
|
-
function printTypeBody(typeName) {
|
|
309
|
-
const coreType = `${importNamespace}.${baseVisitor.convertName(typeName, {
|
|
310
|
-
useTypesSuffix: true,
|
|
311
|
-
useTypesPrefix: true
|
|
312
|
-
})}`;
|
|
313
|
-
if (external.enums.includes(typeName) || external.objects.includes(typeName)) {
|
|
314
|
-
if (schema && isScalarType(schema.getType(typeName))) {
|
|
315
|
-
return `${importNamespace}.Scalars['${typeName}']`;
|
|
316
|
-
}
|
|
317
|
-
return coreType;
|
|
318
|
-
}
|
|
319
|
-
if (defined.enums.includes(typeName) && picks.enums[typeName]) {
|
|
320
|
-
return `DefinedEnumValues['${typeName}']`;
|
|
321
|
-
}
|
|
322
|
-
if (defined.objects.includes(typeName) && picks.objects[typeName]) {
|
|
323
|
-
return `Pick<${coreType}, DefinedFields['${typeName}']>`;
|
|
324
|
-
}
|
|
325
|
-
if (defined.interfaces.includes(typeName) && picks.interfaces[typeName]) {
|
|
326
|
-
return `Pick<${coreType}, DefinedFields['${typeName}']>`;
|
|
327
|
-
}
|
|
328
|
-
if (defined.inputs.includes(typeName) && picks.inputs[typeName]) {
|
|
329
|
-
return `Pick<${coreType}, DefinedInputFields['${typeName}']>`;
|
|
330
|
-
}
|
|
331
|
-
return coreType;
|
|
332
|
-
}
|
|
333
|
-
function printExportType(typeName) {
|
|
334
|
-
return `export type ${encapsulateTypeName(typeName)} = ${printTypeBody(
|
|
335
|
-
typeName
|
|
336
|
-
)};`;
|
|
337
|
-
}
|
|
338
|
-
function collectFields(node, picksObj) {
|
|
339
|
-
const name2 = node.name.value;
|
|
340
|
-
if (node.fields) {
|
|
341
|
-
if (!picksObj[name2]) {
|
|
342
|
-
picksObj[name2] = [];
|
|
343
|
-
}
|
|
344
|
-
node.fields.forEach((field) => {
|
|
345
|
-
picksObj[name2].push(field.name.value);
|
|
346
|
-
});
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
function collectValuesFromEnum(node) {
|
|
350
|
-
const name2 = node.name.value;
|
|
351
|
-
if (node.values) {
|
|
352
|
-
if (!picks.enums[name2]) {
|
|
353
|
-
picks.enums[name2] = [];
|
|
354
|
-
}
|
|
355
|
-
node.values.forEach((field) => {
|
|
356
|
-
picks.enums[name2].push(field.name.value);
|
|
357
|
-
});
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
function collectTypeDefinition(node) {
|
|
361
|
-
const name2 = node.name.value;
|
|
362
|
-
switch (node.kind) {
|
|
363
|
-
case Kind.OBJECT_TYPE_DEFINITION: {
|
|
364
|
-
defined.objects.push(name2);
|
|
365
|
-
collectFields(node, picks.objects);
|
|
366
|
-
break;
|
|
367
|
-
}
|
|
368
|
-
case Kind.ENUM_TYPE_DEFINITION: {
|
|
369
|
-
defined.enums.push(name2);
|
|
370
|
-
collectValuesFromEnum(node);
|
|
371
|
-
break;
|
|
372
|
-
}
|
|
373
|
-
case Kind.INPUT_OBJECT_TYPE_DEFINITION: {
|
|
374
|
-
defined.inputs.push(name2);
|
|
375
|
-
collectFields(node, picks.inputs);
|
|
376
|
-
break;
|
|
377
|
-
}
|
|
378
|
-
case Kind.SCALAR_TYPE_DEFINITION: {
|
|
379
|
-
defined.scalars.push(name2);
|
|
380
|
-
break;
|
|
381
|
-
}
|
|
382
|
-
case Kind.INTERFACE_TYPE_DEFINITION: {
|
|
383
|
-
defined.interfaces.push(name2);
|
|
384
|
-
collectFields(node, picks.interfaces);
|
|
385
|
-
break;
|
|
386
|
-
}
|
|
387
|
-
case Kind.UNION_TYPE_DEFINITION: {
|
|
388
|
-
defined.unions.push(name2);
|
|
389
|
-
break;
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
function collectTypeExtension(node) {
|
|
394
|
-
const name2 = node.name.value;
|
|
395
|
-
switch (node.kind) {
|
|
396
|
-
case Kind.OBJECT_TYPE_EXTENSION: {
|
|
397
|
-
collectFields(node, picks.objects);
|
|
398
|
-
if (rootTypes.includes(name2)) {
|
|
399
|
-
pushUnique(defined.objects, name2);
|
|
400
|
-
return;
|
|
401
|
-
}
|
|
402
|
-
pushUnique(extended.objects, name2);
|
|
403
|
-
break;
|
|
404
|
-
}
|
|
405
|
-
case Kind.ENUM_TYPE_EXTENSION: {
|
|
406
|
-
collectValuesFromEnum(node);
|
|
407
|
-
pushUnique(extended.enums, name2);
|
|
408
|
-
break;
|
|
409
|
-
}
|
|
410
|
-
case Kind.INPUT_OBJECT_TYPE_EXTENSION: {
|
|
411
|
-
collectFields(node, picks.inputs);
|
|
412
|
-
pushUnique(extended.inputs, name2);
|
|
413
|
-
break;
|
|
414
|
-
}
|
|
415
|
-
case Kind.INTERFACE_TYPE_EXTENSION: {
|
|
416
|
-
collectFields(node, picks.interfaces);
|
|
417
|
-
pushUnique(extended.interfaces, name2);
|
|
418
|
-
break;
|
|
419
|
-
}
|
|
420
|
-
case Kind.UNION_TYPE_EXTENSION: {
|
|
421
|
-
pushUnique(extended.unions, name2);
|
|
422
|
-
break;
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
export {
|
|
428
|
-
buildModule
|
|
429
|
-
};
|
package/dist/modules/config.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
declare type ModulesConfig = {
|
|
2
|
-
baseTypesPath: string;
|
|
3
|
-
importBaseTypesFrom?: string;
|
|
4
|
-
cwd?: string;
|
|
5
|
-
importTypesNamespace?: string;
|
|
6
|
-
filename: string;
|
|
7
|
-
encapsulateModuleTypes: "prefix" | "namespace" | "none";
|
|
8
|
-
requireRootResolvers?: boolean;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export { ModulesConfig };
|
package/dist/modules/config.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __copyProps = (to, from, except, desc) => {
|
|
7
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
-
for (let key of __getOwnPropNames(from))
|
|
9
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
-
}
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
-
var config_exports = {};
|
|
16
|
-
module.exports = __toCommonJS(config_exports);
|
package/dist/modules/config.mjs
DELETED
|
File without changes
|
package/dist/modules/index.d.ts
DELETED
package/dist/modules/index.js
DELETED
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var modules_exports = {};
|
|
20
|
-
__export(modules_exports, {
|
|
21
|
-
default: () => modules_default,
|
|
22
|
-
preset: () => preset
|
|
23
|
-
});
|
|
24
|
-
module.exports = __toCommonJS(modules_exports);
|
|
25
|
-
var import_graphql = require("graphql");
|
|
26
|
-
var import_path = require("path");
|
|
27
|
-
var import_utils = require("./utils");
|
|
28
|
-
var import_builder = require("./builder");
|
|
29
|
-
var import_visitor_plugin_common = require("@graphql-codegen/visitor-plugin-common");
|
|
30
|
-
const preset = {
|
|
31
|
-
buildGeneratesSection: (options) => {
|
|
32
|
-
const { baseOutputDir } = options;
|
|
33
|
-
const { baseTypesPath, encapsulateModuleTypes } = options.presetConfig;
|
|
34
|
-
const requireRootResolvers = (0, import_visitor_plugin_common.getConfigValue)(
|
|
35
|
-
options == null ? void 0 : options.presetConfig.requireRootResolvers,
|
|
36
|
-
false
|
|
37
|
-
);
|
|
38
|
-
const cwd = (0, import_path.resolve)(options.presetConfig.cwd || process.cwd());
|
|
39
|
-
const importTypesNamespace = options.presetConfig.importTypesNamespace || "Types";
|
|
40
|
-
if (!baseTypesPath) {
|
|
41
|
-
throw new Error(
|
|
42
|
-
`Preset "graphql-modules" requires you to specify "baseTypesPath" configuration and point it to your base types file (generated by "typescript" plugin)!`
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
if (!options.schemaAst || !options.schemaAst.extensions.sources) {
|
|
46
|
-
throw new Error(`Preset "graphql-modules" requires to use GraphQL SDL`);
|
|
47
|
-
}
|
|
48
|
-
const extensions = options.schemaAst.extensions;
|
|
49
|
-
const sourcesByModuleMap = (0, import_utils.groupSourcesByModule)(
|
|
50
|
-
extensions.extendedSources,
|
|
51
|
-
baseOutputDir
|
|
52
|
-
);
|
|
53
|
-
const modules = Object.keys(sourcesByModuleMap);
|
|
54
|
-
const baseVisitor = new import_visitor_plugin_common.BaseVisitor(options.config, {});
|
|
55
|
-
const baseOutput = {
|
|
56
|
-
filename: (0, import_path.resolve)(cwd, baseOutputDir, baseTypesPath),
|
|
57
|
-
schema: options.schema,
|
|
58
|
-
documents: options.documents,
|
|
59
|
-
plugins: [
|
|
60
|
-
...options.plugins,
|
|
61
|
-
{
|
|
62
|
-
"modules-exported-scalars": {}
|
|
63
|
-
}
|
|
64
|
-
],
|
|
65
|
-
pluginMap: {
|
|
66
|
-
...options.pluginMap,
|
|
67
|
-
"modules-exported-scalars": {
|
|
68
|
-
plugin: (schema) => {
|
|
69
|
-
const typeMap = schema.getTypeMap();
|
|
70
|
-
return Object.keys(typeMap).map((t) => {
|
|
71
|
-
if (t && typeMap[t] && (0, import_graphql.isScalarType)(typeMap[t]) && !(0, import_utils.isGraphQLPrimitive)(t)) {
|
|
72
|
-
const convertedName = baseVisitor.convertName(t);
|
|
73
|
-
return `export type ${convertedName} = Scalars["${t}"];`;
|
|
74
|
-
}
|
|
75
|
-
return null;
|
|
76
|
-
}).filter(Boolean).join("\n");
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
|
-
config: {
|
|
81
|
-
...options.config,
|
|
82
|
-
enumsAsTypes: true
|
|
83
|
-
},
|
|
84
|
-
schemaAst: options.schemaAst
|
|
85
|
-
};
|
|
86
|
-
const baseTypesFilename = baseTypesPath.replace(/\.(js|ts|d.ts)$/, "");
|
|
87
|
-
const baseTypesDir = (0, import_utils.stripFilename)(baseOutput.filename);
|
|
88
|
-
const outputs = modules.map((moduleName) => {
|
|
89
|
-
const filename = (0, import_path.resolve)(
|
|
90
|
-
cwd,
|
|
91
|
-
baseOutputDir,
|
|
92
|
-
moduleName,
|
|
93
|
-
options.presetConfig.filename
|
|
94
|
-
);
|
|
95
|
-
const dirpath = (0, import_utils.stripFilename)(filename);
|
|
96
|
-
const relativePath = (0, import_path.relative)(dirpath, baseTypesDir);
|
|
97
|
-
const importPath = options.presetConfig.importBaseTypesFrom || (0, import_utils.normalize)((0, import_path.join)(relativePath, baseTypesFilename));
|
|
98
|
-
const sources = sourcesByModuleMap[moduleName];
|
|
99
|
-
const documents = sources.map(
|
|
100
|
-
(source) => source.document
|
|
101
|
-
);
|
|
102
|
-
const moduleDocument = (0, import_graphql.concatAST)(documents);
|
|
103
|
-
const shouldDeclare = filename.endsWith(".d.ts");
|
|
104
|
-
return {
|
|
105
|
-
filename,
|
|
106
|
-
schema: options.schema,
|
|
107
|
-
documents: [],
|
|
108
|
-
plugins: [
|
|
109
|
-
...options.plugins.filter((p) => typeof p === "object" && !!p.add),
|
|
110
|
-
{
|
|
111
|
-
"graphql-modules-plugin": {}
|
|
112
|
-
}
|
|
113
|
-
],
|
|
114
|
-
pluginMap: {
|
|
115
|
-
...options.pluginMap,
|
|
116
|
-
"graphql-modules-plugin": {
|
|
117
|
-
plugin: (schema) => {
|
|
118
|
-
var _a, _b, _c;
|
|
119
|
-
return (0, import_builder.buildModule)(moduleName, moduleDocument, {
|
|
120
|
-
importNamespace: importTypesNamespace,
|
|
121
|
-
importPath,
|
|
122
|
-
encapsulate: encapsulateModuleTypes || "namespace",
|
|
123
|
-
requireRootResolvers,
|
|
124
|
-
shouldDeclare,
|
|
125
|
-
schema,
|
|
126
|
-
baseVisitor,
|
|
127
|
-
useGraphQLModules: false,
|
|
128
|
-
rootTypes: [
|
|
129
|
-
((_a = schema.getQueryType()) == null ? void 0 : _a.name) || "",
|
|
130
|
-
((_b = schema.getMutationType()) == null ? void 0 : _b.name) || "",
|
|
131
|
-
((_c = schema.getSubscriptionType()) == null ? void 0 : _c.name) || ""
|
|
132
|
-
].filter(Boolean)
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
},
|
|
137
|
-
config: options.config,
|
|
138
|
-
schemaAst: options.schemaAst
|
|
139
|
-
};
|
|
140
|
-
});
|
|
141
|
-
return [baseOutput].concat(outputs);
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
var modules_default = preset;
|
|
145
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
146
|
-
0 && (module.exports = {
|
|
147
|
-
preset
|
|
148
|
-
});
|