@baeta/plugin-graphql 0.0.11 → 0.0.13
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/CHANGELOG.md +20 -0
- package/index.cjs +288 -620
- package/index.js +216 -538
- package/package.json +24 -24
package/index.cjs
CHANGED
|
@@ -1,55 +1,139 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var __defProp = Object.defineProperty;
|
|
8
2
|
var __export = (target, all) => {
|
|
9
3
|
for (var name in all)
|
|
10
4
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
5
|
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
-
mod
|
|
23
|
-
));
|
|
24
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
6
|
|
|
26
7
|
// index.ts
|
|
27
|
-
var
|
|
28
|
-
__export(graphql_exports, {
|
|
29
|
-
default: () => graphql_default
|
|
30
|
-
});
|
|
31
|
-
module.exports = __toCommonJS(graphql_exports);
|
|
32
|
-
var import_plugin2 = require("@baeta/plugin");
|
|
8
|
+
var _plugin = require('@baeta/plugin');
|
|
33
9
|
|
|
34
10
|
// lib/codegen.ts
|
|
35
|
-
var import_plugin = require("@baeta/plugin");
|
|
36
|
-
var import_core = require("@graphql-codegen/core");
|
|
37
|
-
var import_plugin_helpers4 = require("@graphql-codegen/plugin-helpers");
|
|
38
|
-
var typescriptPlugin = __toESM(require("@graphql-codegen/typescript"), 1);
|
|
39
|
-
var import_path2 = __toESM(require("path"), 1);
|
|
40
11
|
|
|
41
|
-
|
|
42
|
-
var
|
|
43
|
-
var
|
|
44
|
-
var
|
|
12
|
+
var _core = require('@graphql-codegen/core');
|
|
13
|
+
var _pluginhelpers = require('@graphql-codegen/plugin-helpers');
|
|
14
|
+
var _typescript = require('@graphql-codegen/typescript'); var typescriptPlugin = _interopRequireWildcard(_typescript);
|
|
15
|
+
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
16
|
+
|
|
17
|
+
// utils/cache.ts
|
|
18
|
+
function createCache() {
|
|
19
|
+
const cache = /* @__PURE__ */ new Map();
|
|
20
|
+
return function ensure(namespace, key, factory) {
|
|
21
|
+
const cacheKey = `${namespace}:${key}`;
|
|
22
|
+
const cachedValue = cache.get(cacheKey);
|
|
23
|
+
if (cachedValue) {
|
|
24
|
+
return cachedValue;
|
|
25
|
+
}
|
|
26
|
+
const value = factory();
|
|
27
|
+
cache.set(cacheKey, value);
|
|
28
|
+
return value;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// utils/load.ts
|
|
33
|
+
|
|
34
|
+
var _apolloengineloader = require('@graphql-tools/apollo-engine-loader');
|
|
35
|
+
var _codefileloader = require('@graphql-tools/code-file-loader');
|
|
36
|
+
var _gitloader = require('@graphql-tools/git-loader');
|
|
37
|
+
var _githubloader = require('@graphql-tools/github-loader');
|
|
38
|
+
var _graphqlfileloader = require('@graphql-tools/graphql-file-loader');
|
|
39
|
+
var _jsonfileloader = require('@graphql-tools/json-file-loader');
|
|
40
|
+
var _load = require('@graphql-tools/load');
|
|
41
|
+
var _prismaloader = require('@graphql-tools/prisma-loader');
|
|
42
|
+
var _urlloader = require('@graphql-tools/url-loader');
|
|
43
|
+
|
|
44
|
+
// utils/hash.ts
|
|
45
|
+
|
|
46
|
+
var _graphql = require('graphql');
|
|
47
|
+
var _crypto = require('crypto');
|
|
48
|
+
function hashContent(content) {
|
|
49
|
+
return _crypto.createHash.call(void 0, "sha256").update(content).digest("hex");
|
|
50
|
+
}
|
|
51
|
+
function hashSchema(schema) {
|
|
52
|
+
return hashContent(_graphql.print.call(void 0, _pluginhelpers.getCachedDocumentNodeFromSchema.call(void 0, schema)));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// utils/load.ts
|
|
56
|
+
async function loadSchema(schemaPointerMap, cwd) {
|
|
57
|
+
const outputSchemaAst = await _load.loadSchema.call(void 0, schemaPointerMap, {
|
|
58
|
+
loaders: [
|
|
59
|
+
new (0, _codefileloader.CodeFileLoader)(),
|
|
60
|
+
new (0, _gitloader.GitLoader)(),
|
|
61
|
+
new (0, _githubloader.GithubLoader)(),
|
|
62
|
+
new (0, _graphqlfileloader.GraphQLFileLoader)(),
|
|
63
|
+
new (0, _jsonfileloader.JsonFileLoader)(),
|
|
64
|
+
new (0, _urlloader.UrlLoader)(),
|
|
65
|
+
new (0, _apolloengineloader.ApolloEngineLoader)(),
|
|
66
|
+
new (0, _prismaloader.PrismaLoader)()
|
|
67
|
+
],
|
|
68
|
+
cwd,
|
|
69
|
+
includeSources: true
|
|
70
|
+
});
|
|
71
|
+
if (!outputSchemaAst.extensions) {
|
|
72
|
+
outputSchemaAst.extensions = {};
|
|
73
|
+
}
|
|
74
|
+
outputSchemaAst.extensions["hash"] = hashSchema(outputSchemaAst);
|
|
75
|
+
return {
|
|
76
|
+
outputSchemaAst,
|
|
77
|
+
outputSchema: _pluginhelpers.getCachedDocumentNodeFromSchema.call(void 0, outputSchemaAst)
|
|
78
|
+
};
|
|
79
|
+
}
|
|
45
80
|
|
|
46
|
-
//
|
|
47
|
-
var
|
|
48
|
-
|
|
81
|
+
// lib/context/index.ts
|
|
82
|
+
var context_exports = {};
|
|
83
|
+
__export(context_exports, {
|
|
84
|
+
default: () => context_default,
|
|
85
|
+
plugin: () => plugin
|
|
86
|
+
});
|
|
87
|
+
var _visitorplugincommon = require('@graphql-codegen/visitor-plugin-common');
|
|
88
|
+
var plugin = async (schema, documents, config) => {
|
|
89
|
+
const prepend = [];
|
|
90
|
+
const mapper = _visitorplugincommon.parseMapper.call(void 0, config.contextType || "any");
|
|
91
|
+
if (mapper.isExternal && mapper.source) {
|
|
92
|
+
const identifier = mapper.default ? "ContextType" : `${mapper.import} as ContextType`;
|
|
93
|
+
const result = _visitorplugincommon.buildMapperImport.call(void 0,
|
|
94
|
+
mapper.source,
|
|
95
|
+
[
|
|
96
|
+
{
|
|
97
|
+
identifier,
|
|
98
|
+
asDefault: mapper.default
|
|
99
|
+
}
|
|
100
|
+
],
|
|
101
|
+
true
|
|
102
|
+
);
|
|
103
|
+
if (result) {
|
|
104
|
+
prepend.push(result);
|
|
105
|
+
}
|
|
106
|
+
} else {
|
|
107
|
+
prepend.push(`type ContextType = ${mapper.type}`);
|
|
108
|
+
}
|
|
109
|
+
prepend.push("export type { ContextType }");
|
|
110
|
+
return {
|
|
111
|
+
content: "",
|
|
112
|
+
prepend
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
var context_default = { plugin };
|
|
49
116
|
|
|
50
|
-
// modules/
|
|
51
|
-
|
|
52
|
-
|
|
117
|
+
// lib/modules/index.ts
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
// lib/modules/builder.ts
|
|
123
|
+
var _changecaseall = require('change-case-all');
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
// lib/modules/utils.ts
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
var _parsefilepath = require('parse-filepath'); var _parsefilepath2 = _interopRequireDefault(_parsefilepath);
|
|
53
137
|
var sep = "/";
|
|
54
138
|
function collectUsedTypes(doc) {
|
|
55
139
|
const used = [];
|
|
@@ -58,7 +142,7 @@ function collectUsedTypes(doc) {
|
|
|
58
142
|
pushUnique(used, type);
|
|
59
143
|
}
|
|
60
144
|
function findRelated(node) {
|
|
61
|
-
if (node.kind ===
|
|
145
|
+
if (node.kind === _graphql.Kind.OBJECT_TYPE_DEFINITION || node.kind === _graphql.Kind.OBJECT_TYPE_EXTENSION) {
|
|
62
146
|
markAsUsed(node.name.value);
|
|
63
147
|
if (node.fields) {
|
|
64
148
|
node.fields.forEach(findRelated);
|
|
@@ -66,12 +150,12 @@ function collectUsedTypes(doc) {
|
|
|
66
150
|
if (node.interfaces) {
|
|
67
151
|
node.interfaces.forEach(findRelated);
|
|
68
152
|
}
|
|
69
|
-
} else if (node.kind ===
|
|
153
|
+
} else if (node.kind === _graphql.Kind.INPUT_OBJECT_TYPE_DEFINITION || node.kind === _graphql.Kind.INPUT_OBJECT_TYPE_EXTENSION) {
|
|
70
154
|
markAsUsed(node.name.value);
|
|
71
155
|
if (node.fields) {
|
|
72
156
|
node.fields.forEach(findRelated);
|
|
73
157
|
}
|
|
74
|
-
} else if (node.kind ===
|
|
158
|
+
} else if (node.kind === _graphql.Kind.INTERFACE_TYPE_DEFINITION || node.kind === _graphql.Kind.INTERFACE_TYPE_EXTENSION) {
|
|
75
159
|
markAsUsed(node.name.value);
|
|
76
160
|
if (node.fields) {
|
|
77
161
|
node.fields.forEach(findRelated);
|
|
@@ -79,35 +163,84 @@ function collectUsedTypes(doc) {
|
|
|
79
163
|
if (node.interfaces) {
|
|
80
164
|
node.interfaces.forEach(findRelated);
|
|
81
165
|
}
|
|
82
|
-
} else if (node.kind ===
|
|
166
|
+
} else if (node.kind === _graphql.Kind.UNION_TYPE_DEFINITION || node.kind === _graphql.Kind.UNION_TYPE_EXTENSION) {
|
|
83
167
|
markAsUsed(node.name.value);
|
|
84
168
|
if (node.types) {
|
|
85
169
|
node.types.forEach(findRelated);
|
|
86
170
|
}
|
|
87
|
-
} else if (node.kind ===
|
|
171
|
+
} else if (node.kind === _graphql.Kind.ENUM_TYPE_DEFINITION || node.kind === _graphql.Kind.ENUM_TYPE_EXTENSION) {
|
|
88
172
|
markAsUsed(node.name.value);
|
|
89
|
-
} else if (node.kind ===
|
|
173
|
+
} else if (node.kind === _graphql.Kind.SCALAR_TYPE_DEFINITION || node.kind === _graphql.Kind.SCALAR_TYPE_EXTENSION) {
|
|
90
174
|
if (!isGraphQLPrimitive(node.name.value)) {
|
|
91
175
|
markAsUsed(node.name.value);
|
|
92
176
|
}
|
|
93
|
-
} else if (node.kind ===
|
|
177
|
+
} else if (node.kind === _graphql.Kind.INPUT_VALUE_DEFINITION) {
|
|
94
178
|
findRelated(resolveTypeNode(node.type));
|
|
95
|
-
} else if (node.kind ===
|
|
179
|
+
} else if (node.kind === _graphql.Kind.FIELD_DEFINITION) {
|
|
96
180
|
findRelated(resolveTypeNode(node.type));
|
|
97
181
|
if (node.arguments) {
|
|
98
182
|
node.arguments.forEach(findRelated);
|
|
99
183
|
}
|
|
100
|
-
} else if (node.kind ===
|
|
184
|
+
} else if (node.kind === _graphql.Kind.NAMED_TYPE && !isGraphQLPrimitive(node.name.value)) {
|
|
101
185
|
markAsUsed(node.name.value);
|
|
102
186
|
}
|
|
103
187
|
}
|
|
104
188
|
return used;
|
|
105
189
|
}
|
|
190
|
+
function collectObjectFieldType(node, fieldDefinition, fieldsMap, fieldTypes) {
|
|
191
|
+
const objectName = node.name.value;
|
|
192
|
+
const fieldName = fieldDefinition.name.value;
|
|
193
|
+
const field = fieldsMap[fieldDefinition.name.value];
|
|
194
|
+
const baseName = _pluginhelpers.getBaseType.call(void 0, field.type).name;
|
|
195
|
+
const isDefaultScalar = _visitorplugincommon.DEFAULT_SCALARS[baseName] != null;
|
|
196
|
+
const name = isDefaultScalar ? `Types.Scalars["${baseName}"]` : baseName;
|
|
197
|
+
const type = _visitorplugincommon.wrapTypeWithModifiers.call(void 0, name, field.type, {
|
|
198
|
+
wrapOptional: (str) => {
|
|
199
|
+
return `Types.Maybe<${str}>`;
|
|
200
|
+
},
|
|
201
|
+
wrapArray: (str) => {
|
|
202
|
+
return `Array<${str}>`;
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
if (fieldTypes[objectName] == null) {
|
|
206
|
+
fieldTypes[objectName] = {};
|
|
207
|
+
}
|
|
208
|
+
fieldTypes[objectName][fieldName] = type;
|
|
209
|
+
}
|
|
210
|
+
function collectObjectFieldArguments(node, fieldDefinition, fieldArguments) {
|
|
211
|
+
const objectName = node.name.value;
|
|
212
|
+
const fieldName = fieldDefinition.name.value;
|
|
213
|
+
const hasArguments = fieldDefinition.arguments != null && fieldDefinition.arguments.length > 0;
|
|
214
|
+
if (fieldArguments[objectName] == null) {
|
|
215
|
+
fieldArguments[objectName] = {};
|
|
216
|
+
}
|
|
217
|
+
fieldArguments[objectName][fieldName] = hasArguments;
|
|
218
|
+
}
|
|
219
|
+
function collectObjectFieldTypesAndArguments(schema) {
|
|
220
|
+
const fieldTypes = {};
|
|
221
|
+
const fieldArguments = {};
|
|
222
|
+
if (!schema) {
|
|
223
|
+
return { fieldTypes, fieldArguments };
|
|
224
|
+
}
|
|
225
|
+
const schemaTypes = schema.getTypeMap();
|
|
226
|
+
for (const type of Object.values(schemaTypes)) {
|
|
227
|
+
if (_optionalChain([type, 'access', _ => _.astNode, 'optionalAccess', _2 => _2.kind]) !== _graphql.Kind.OBJECT_TYPE_DEFINITION) {
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
const schemaType = schemaTypes[type.name];
|
|
231
|
+
const fieldsMap = schemaType.getFields();
|
|
232
|
+
for (const field of _nullishCoalesce(type.astNode.fields, () => ( []))) {
|
|
233
|
+
collectObjectFieldArguments(type.astNode, field, fieldArguments);
|
|
234
|
+
collectObjectFieldType(type.astNode, field, fieldsMap, fieldTypes);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return { fieldTypes, fieldArguments };
|
|
238
|
+
}
|
|
106
239
|
function resolveTypeNode(node) {
|
|
107
|
-
if (node.kind ===
|
|
240
|
+
if (node.kind === _graphql.Kind.LIST_TYPE) {
|
|
108
241
|
return resolveTypeNode(node.type);
|
|
109
242
|
}
|
|
110
|
-
if (node.kind ===
|
|
243
|
+
if (node.kind === _graphql.Kind.NON_NULL_TYPE) {
|
|
111
244
|
return resolveTypeNode(node.type);
|
|
112
245
|
}
|
|
113
246
|
return node;
|
|
@@ -165,7 +298,7 @@ function extractModuleDirectory(filepath, basePath) {
|
|
|
165
298
|
return moduleDirectory;
|
|
166
299
|
}
|
|
167
300
|
function stripFilename(path2) {
|
|
168
|
-
const parsedPath = (0,
|
|
301
|
+
const parsedPath = _parsefilepath2.default.call(void 0, path2);
|
|
169
302
|
return normalize(parsedPath.dir);
|
|
170
303
|
}
|
|
171
304
|
function normalize(path2) {
|
|
@@ -196,7 +329,7 @@ function createObject(keys, valueFn) {
|
|
|
196
329
|
return obj;
|
|
197
330
|
}
|
|
198
331
|
|
|
199
|
-
// modules/builder.ts
|
|
332
|
+
// lib/modules/builder.ts
|
|
200
333
|
var registryKeys = [
|
|
201
334
|
"objects",
|
|
202
335
|
"inputs",
|
|
@@ -205,11 +338,6 @@ var registryKeys = [
|
|
|
205
338
|
"unions",
|
|
206
339
|
"enums"
|
|
207
340
|
];
|
|
208
|
-
var resolverKeys = [
|
|
209
|
-
"scalars",
|
|
210
|
-
"objects",
|
|
211
|
-
"enums"
|
|
212
|
-
];
|
|
213
341
|
function buildModule(name, doc, {
|
|
214
342
|
importNamespace,
|
|
215
343
|
importPath,
|
|
@@ -218,7 +346,9 @@ function buildModule(name, doc, {
|
|
|
218
346
|
shouldDeclare,
|
|
219
347
|
rootTypes,
|
|
220
348
|
schema,
|
|
221
|
-
baseVisitor
|
|
349
|
+
baseVisitor,
|
|
350
|
+
fieldTypes,
|
|
351
|
+
fieldArguments
|
|
222
352
|
}) {
|
|
223
353
|
const picks = createObject(
|
|
224
354
|
registryKeys,
|
|
@@ -227,7 +357,7 @@ function buildModule(name, doc, {
|
|
|
227
357
|
const defined = createObject(registryKeys, () => []);
|
|
228
358
|
const extended = createObject(registryKeys, () => []);
|
|
229
359
|
const usedTypes = collectUsedTypes(doc);
|
|
230
|
-
(0,
|
|
360
|
+
_graphql.visit.call(void 0, doc, {
|
|
231
361
|
ObjectTypeDefinition(node) {
|
|
232
362
|
collectTypeDefinition(node);
|
|
233
363
|
},
|
|
@@ -280,9 +410,6 @@ function buildModule(name, doc, {
|
|
|
280
410
|
printDefinedEnumValues(),
|
|
281
411
|
printDefinedInputFields(),
|
|
282
412
|
printSchemaTypes(usedTypes),
|
|
283
|
-
printScalars(visited),
|
|
284
|
-
printResolveSignaturesPerType(visited),
|
|
285
|
-
printResolversType(visited),
|
|
286
413
|
printMetadata()
|
|
287
414
|
].filter(Boolean).join("\n\n");
|
|
288
415
|
const moduleNamespace = baseVisitor.convertName(name, {
|
|
@@ -330,44 +457,54 @@ export const ${getModuleFn} = Baeta.createSingletonModule(${createModuleFn});
|
|
|
330
457
|
`;
|
|
331
458
|
}
|
|
332
459
|
function printObjectFieldResolverBuilder(typeName, field) {
|
|
333
|
-
const
|
|
334
|
-
|
|
460
|
+
const parentType = getParentType(typeName);
|
|
461
|
+
const resultType = getResultType(typeName, field);
|
|
462
|
+
const argumentsType = getArgsType(typeName, field);
|
|
463
|
+
const contextType = getContextType();
|
|
464
|
+
return `${field}: module.createResolverBuilder<${resultType}, ${parentType}, ${contextType}, ${argumentsType}>("${typeName}", "${field}"),`;
|
|
335
465
|
}
|
|
336
466
|
function printObjectResolverBuilder(typeName, objects) {
|
|
337
|
-
const fields = objects[typeName]
|
|
467
|
+
const fields = _nullishCoalesce(_optionalChain([objects, 'access', _3 => _3[typeName], 'optionalAccess', _4 => _4.filter, 'call', _5 => _5(unique), 'access', _6 => _6.map, 'call', _7 => _7((field) => printObjectFieldResolverBuilder(typeName, field))]), () => ( []));
|
|
338
468
|
if (fields.length === 0) {
|
|
339
469
|
return "";
|
|
340
470
|
}
|
|
341
|
-
const
|
|
471
|
+
const parentType = getParentType(typeName);
|
|
472
|
+
const contextType = getContextType();
|
|
473
|
+
const addons = [`...module.createTypeMethods<${parentType}, ${contextType}>("${typeName}"),`];
|
|
474
|
+
const contentBody = [...addons, ...fields].map(indent(2)).join("\n");
|
|
342
475
|
const content2 = `{
|
|
343
|
-
${
|
|
476
|
+
${contentBody}
|
|
344
477
|
}`;
|
|
345
|
-
return `${typeName}:
|
|
478
|
+
return `${typeName}: ${content2},`;
|
|
346
479
|
}
|
|
347
480
|
function printSubscriptionFieldBuilder(field) {
|
|
348
|
-
const
|
|
349
|
-
|
|
481
|
+
const parentType = getParentType("Subscription");
|
|
482
|
+
const resultType = getResultType("Subscription", field);
|
|
483
|
+
const argumentsType = getArgsType("Subscription", field);
|
|
484
|
+
const contextType = getContextType();
|
|
485
|
+
return `${field}: module.createSubscriptionBuilder<${resultType}, ${parentType}, ${contextType}, ${argumentsType}>("${field}"),`;
|
|
350
486
|
}
|
|
351
487
|
function printSubscriptionObjectBuilder() {
|
|
352
|
-
const subscriptions = picks.objects["Subscription"]
|
|
488
|
+
const subscriptions = _nullishCoalesce(_optionalChain([picks, 'access', _8 => _8.objects, 'access', _9 => _9["Subscription"], 'optionalAccess', _10 => _10.filter, 'call', _11 => _11(unique)]), () => ( []));
|
|
353
489
|
if (subscriptions.length === 0) {
|
|
354
490
|
return "";
|
|
355
491
|
}
|
|
356
492
|
const fields = subscriptions.map((subscription) => printSubscriptionFieldBuilder(subscription));
|
|
357
|
-
const
|
|
493
|
+
const parentType = getParentType("Subscription");
|
|
494
|
+
const contextType = getContextType();
|
|
495
|
+
const addons = [`...module.createSubscriptionMethods<${parentType}, ${contextType}>(),`];
|
|
496
|
+
const contentBody = [...addons, ...fields].map(indent(2)).join("\n");
|
|
358
497
|
const content2 = `{
|
|
359
|
-
${
|
|
498
|
+
${contentBody}
|
|
360
499
|
}`;
|
|
361
|
-
return `Subscription:
|
|
500
|
+
return `Subscription: ${content2},`;
|
|
362
501
|
}
|
|
363
502
|
function printScalarBuilder() {
|
|
364
503
|
const scalars = visited.scalars;
|
|
365
504
|
if (scalars.length === 0) {
|
|
366
505
|
return "";
|
|
367
506
|
}
|
|
368
|
-
const fields = scalars.map(
|
|
369
|
-
(scalar) => `${scalar}: Baeta.createScalarBuilder(module, "${scalar}"),`
|
|
370
|
-
);
|
|
507
|
+
const fields = scalars.map((scalar) => `${scalar}: module.createScalarBuilder("${scalar}"),`);
|
|
371
508
|
const content2 = fields.map(indent(2)).join("\n");
|
|
372
509
|
return `Scalar: {
|
|
373
510
|
${content2}
|
|
@@ -375,14 +512,21 @@ ${content2}
|
|
|
375
512
|
}
|
|
376
513
|
function printBaetaManager() {
|
|
377
514
|
const objects = visited.objects.filter((type) => type !== "Subscription").map((typeName) => printObjectResolverBuilder(typeName, picks.objects)).filter(Boolean);
|
|
378
|
-
const
|
|
515
|
+
const contextType = getContextType();
|
|
516
|
+
const addons = [`...module.createModuleMethods<${contextType}>(),`];
|
|
517
|
+
const bodyFields = [
|
|
518
|
+
...addons,
|
|
519
|
+
...objects,
|
|
520
|
+
printScalarBuilder(),
|
|
521
|
+
printSubscriptionObjectBuilder()
|
|
522
|
+
];
|
|
379
523
|
const body = bodyFields.filter(Boolean).map(indent(6)).join("\n");
|
|
380
524
|
const content2 = `{
|
|
381
525
|
${body}
|
|
382
526
|
}`;
|
|
383
527
|
return `
|
|
384
528
|
export function createManager(module: Baeta.ModuleBuilder) {
|
|
385
|
-
return
|
|
529
|
+
return ${content2};
|
|
386
530
|
}`;
|
|
387
531
|
}
|
|
388
532
|
function printDefinedEnumValues() {
|
|
@@ -393,7 +537,7 @@ ${body}
|
|
|
393
537
|
}
|
|
394
538
|
function encapsulateTypeName(typeName) {
|
|
395
539
|
if (encapsulate === "prefix") {
|
|
396
|
-
return `${(0,
|
|
540
|
+
return `${_changecaseall.pascalCase.call(void 0, name)}_${typeName}`;
|
|
397
541
|
}
|
|
398
542
|
return typeName;
|
|
399
543
|
}
|
|
@@ -408,72 +552,6 @@ ${body}
|
|
|
408
552
|
function printSchemaTypes(types) {
|
|
409
553
|
return types.filter((type) => !visited.scalars.includes(type)).map(printExportType).join("\n");
|
|
410
554
|
}
|
|
411
|
-
function printResolveSignaturesPerType(registry) {
|
|
412
|
-
return [
|
|
413
|
-
[...registry.objects, ...registry.interfaces].map(
|
|
414
|
-
(name2) => printResolverType(
|
|
415
|
-
name2,
|
|
416
|
-
"DefinedFields",
|
|
417
|
-
requireRootResolvers && rootTypes.includes(name2),
|
|
418
|
-
!rootTypes.includes(name2) && defined.objects.includes(name2) ? ` | '__isTypeOf'` : ""
|
|
419
|
-
)
|
|
420
|
-
).join("\n")
|
|
421
|
-
].join("\n");
|
|
422
|
-
}
|
|
423
|
-
function printScalars(registry) {
|
|
424
|
-
if (!registry.scalars.length) {
|
|
425
|
-
return "";
|
|
426
|
-
}
|
|
427
|
-
return [
|
|
428
|
-
`export type ${encapsulateTypeName(
|
|
429
|
-
"Scalars"
|
|
430
|
-
)} = Pick<${importNamespace}.Scalars, ${registry.scalars.map(withQuotes).join(" | ")}>;`,
|
|
431
|
-
...registry.scalars.map((scalar) => {
|
|
432
|
-
const convertedName = baseVisitor.convertName(scalar, {
|
|
433
|
-
suffix: "ScalarConfig"
|
|
434
|
-
});
|
|
435
|
-
return `export type ${encapsulateTypeName(
|
|
436
|
-
convertedName
|
|
437
|
-
)} = ${importNamespace}.${convertedName};`;
|
|
438
|
-
})
|
|
439
|
-
].join("\n");
|
|
440
|
-
}
|
|
441
|
-
function printResolversType(registry) {
|
|
442
|
-
const lines = [];
|
|
443
|
-
for (const kind in registry) {
|
|
444
|
-
if (!Object.prototype.hasOwnProperty.call(registry, kind)) {
|
|
445
|
-
continue;
|
|
446
|
-
}
|
|
447
|
-
if (!resolverKeys.includes(kind)) {
|
|
448
|
-
continue;
|
|
449
|
-
}
|
|
450
|
-
const k = kind;
|
|
451
|
-
const types = registry[k];
|
|
452
|
-
types.forEach((typeName) => {
|
|
453
|
-
if (k === "enums") {
|
|
454
|
-
return;
|
|
455
|
-
}
|
|
456
|
-
if (k === "scalars") {
|
|
457
|
-
lines.push(
|
|
458
|
-
`${typeName}?: ${encapsulateTypeName(importNamespace)}.Resolvers['${typeName}'];`
|
|
459
|
-
);
|
|
460
|
-
} else {
|
|
461
|
-
const fieldModifier = requireRootResolvers && rootTypes.includes(typeName) ? "" : "?";
|
|
462
|
-
lines.push(`${typeName}${fieldModifier}: ${encapsulateTypeName(typeName)}Resolvers;`);
|
|
463
|
-
}
|
|
464
|
-
});
|
|
465
|
-
}
|
|
466
|
-
return buildBlock({
|
|
467
|
-
name: `export interface ${encapsulateTypeName("Resolvers")}`,
|
|
468
|
-
lines
|
|
469
|
-
});
|
|
470
|
-
}
|
|
471
|
-
function printResolverType(typeName, picksTypeName, requireFieldsResolvers = false, extraKeys = "") {
|
|
472
|
-
const typeSignature = `Pick<${importNamespace}.${baseVisitor.convertName(typeName, {
|
|
473
|
-
suffix: "Resolvers"
|
|
474
|
-
})}, ${picksTypeName}['${typeName}']${extraKeys}>`;
|
|
475
|
-
return `export type ${encapsulateTypeName(`${typeName}Resolvers`)} = ${requireFieldsResolvers ? `Required<${typeSignature}>` : typeSignature};`;
|
|
476
|
-
}
|
|
477
555
|
function printPicks(typeName, records) {
|
|
478
556
|
return records[typeName].filter(unique).map(withQuotes).join(" | ");
|
|
479
557
|
}
|
|
@@ -483,7 +561,7 @@ ${body}
|
|
|
483
561
|
useTypesPrefix: true
|
|
484
562
|
})}`;
|
|
485
563
|
if (external.enums.includes(typeName) || external.objects.includes(typeName)) {
|
|
486
|
-
if (schema && (0,
|
|
564
|
+
if (schema && _graphql.isScalarType.call(void 0, schema.getType(typeName))) {
|
|
487
565
|
return `${importNamespace}.Scalars['${typeName}']`;
|
|
488
566
|
}
|
|
489
567
|
return coreType;
|
|
@@ -530,31 +608,31 @@ ${body}
|
|
|
530
608
|
function collectTypeDefinition(node) {
|
|
531
609
|
const name2 = node.name.value;
|
|
532
610
|
switch (node.kind) {
|
|
533
|
-
case
|
|
611
|
+
case _graphql.Kind.OBJECT_TYPE_DEFINITION: {
|
|
534
612
|
defined.objects.push(name2);
|
|
535
613
|
collectFields(node, picks.objects);
|
|
536
614
|
break;
|
|
537
615
|
}
|
|
538
|
-
case
|
|
616
|
+
case _graphql.Kind.ENUM_TYPE_DEFINITION: {
|
|
539
617
|
defined.enums.push(name2);
|
|
540
618
|
collectValuesFromEnum(node);
|
|
541
619
|
break;
|
|
542
620
|
}
|
|
543
|
-
case
|
|
621
|
+
case _graphql.Kind.INPUT_OBJECT_TYPE_DEFINITION: {
|
|
544
622
|
defined.inputs.push(name2);
|
|
545
623
|
collectFields(node, picks.inputs);
|
|
546
624
|
break;
|
|
547
625
|
}
|
|
548
|
-
case
|
|
626
|
+
case _graphql.Kind.SCALAR_TYPE_DEFINITION: {
|
|
549
627
|
defined.scalars.push(name2);
|
|
550
628
|
break;
|
|
551
629
|
}
|
|
552
|
-
case
|
|
630
|
+
case _graphql.Kind.INTERFACE_TYPE_DEFINITION: {
|
|
553
631
|
defined.interfaces.push(name2);
|
|
554
632
|
collectFields(node, picks.interfaces);
|
|
555
633
|
break;
|
|
556
634
|
}
|
|
557
|
-
case
|
|
635
|
+
case _graphql.Kind.UNION_TYPE_DEFINITION: {
|
|
558
636
|
defined.unions.push(name2);
|
|
559
637
|
break;
|
|
560
638
|
}
|
|
@@ -563,7 +641,7 @@ ${body}
|
|
|
563
641
|
function collectTypeExtension(node) {
|
|
564
642
|
const name2 = node.name.value;
|
|
565
643
|
switch (node.kind) {
|
|
566
|
-
case
|
|
644
|
+
case _graphql.Kind.OBJECT_TYPE_EXTENSION: {
|
|
567
645
|
collectFields(node, picks.objects);
|
|
568
646
|
if (rootTypes.includes(name2)) {
|
|
569
647
|
pushUnique(defined.objects, name2);
|
|
@@ -572,52 +650,73 @@ ${body}
|
|
|
572
650
|
pushUnique(extended.objects, name2);
|
|
573
651
|
break;
|
|
574
652
|
}
|
|
575
|
-
case
|
|
653
|
+
case _graphql.Kind.ENUM_TYPE_EXTENSION: {
|
|
576
654
|
collectValuesFromEnum(node);
|
|
577
655
|
pushUnique(extended.enums, name2);
|
|
578
656
|
break;
|
|
579
657
|
}
|
|
580
|
-
case
|
|
658
|
+
case _graphql.Kind.INPUT_OBJECT_TYPE_EXTENSION: {
|
|
581
659
|
collectFields(node, picks.inputs);
|
|
582
660
|
pushUnique(extended.inputs, name2);
|
|
583
661
|
break;
|
|
584
662
|
}
|
|
585
|
-
case
|
|
663
|
+
case _graphql.Kind.INTERFACE_TYPE_EXTENSION: {
|
|
586
664
|
collectFields(node, picks.interfaces);
|
|
587
665
|
pushUnique(extended.interfaces, name2);
|
|
588
666
|
break;
|
|
589
667
|
}
|
|
590
|
-
case
|
|
668
|
+
case _graphql.Kind.UNION_TYPE_EXTENSION: {
|
|
591
669
|
pushUnique(extended.unions, name2);
|
|
592
670
|
break;
|
|
593
671
|
}
|
|
594
672
|
}
|
|
595
673
|
}
|
|
674
|
+
function getParentType(type) {
|
|
675
|
+
if (["Query", "Mutation", "Subscription"].includes(type)) {
|
|
676
|
+
return "{}";
|
|
677
|
+
}
|
|
678
|
+
return type;
|
|
679
|
+
}
|
|
680
|
+
function getResultType(type, field) {
|
|
681
|
+
return _optionalChain([fieldTypes, 'optionalAccess', _12 => _12[type], 'optionalAccess', _13 => _13[field]]) || "{}";
|
|
682
|
+
}
|
|
683
|
+
function getArgsType(type, field) {
|
|
684
|
+
const hasArgs = _nullishCoalesce(_optionalChain([fieldArguments, 'optionalAccess', _14 => _14[type], 'optionalAccess', _15 => _15[field]]), () => ( false));
|
|
685
|
+
if (!hasArgs) {
|
|
686
|
+
return "{}";
|
|
687
|
+
}
|
|
688
|
+
const fieldUpper = field[0].toUpperCase() + field.slice(1);
|
|
689
|
+
return `Types.${type}${fieldUpper}Args`;
|
|
690
|
+
}
|
|
691
|
+
function getContextType() {
|
|
692
|
+
return "Types.ContextType";
|
|
693
|
+
}
|
|
596
694
|
}
|
|
597
695
|
|
|
598
|
-
// modules/index.ts
|
|
696
|
+
// lib/modules/index.ts
|
|
599
697
|
var preset = {
|
|
600
698
|
buildGeneratesSection: (options) => {
|
|
601
699
|
const { baseOutputDir } = options;
|
|
602
700
|
const { baseTypesPath, encapsulateModuleTypes } = options.presetConfig;
|
|
603
|
-
const requireRootResolvers = (0,
|
|
604
|
-
const cwd = (0,
|
|
701
|
+
const requireRootResolvers = _visitorplugincommon.getConfigValue.call(void 0, _optionalChain([options, 'optionalAccess', _16 => _16.presetConfig, 'access', _17 => _17.requireRootResolvers]), false);
|
|
702
|
+
const cwd = _path.resolve.call(void 0, options.presetConfig.cwd || process.cwd());
|
|
605
703
|
const importTypesNamespace = options.presetConfig.importTypesNamespace || "Types";
|
|
606
704
|
if (!baseTypesPath) {
|
|
607
705
|
throw new Error(
|
|
608
706
|
`Preset "graphql-modules" requires you to specify "baseTypesPath" configuration and point it to your base types file (generated by "typescript" plugin)!`
|
|
609
707
|
);
|
|
610
708
|
}
|
|
611
|
-
if (!options.schemaAst
|
|
709
|
+
if (!_optionalChain([options, 'access', _18 => _18.schemaAst, 'optionalAccess', _19 => _19.extensions, 'access', _20 => _20.sources])) {
|
|
612
710
|
throw new Error(`Preset "graphql-modules" requires to use GraphQL SDL`);
|
|
613
711
|
}
|
|
614
|
-
const extensions = options.schemaAst
|
|
615
|
-
const sources = extensions
|
|
712
|
+
const extensions = _optionalChain([options, 'access', _21 => _21.schemaAst, 'optionalAccess', _22 => _22.extensions]);
|
|
713
|
+
const sources = _nullishCoalesce(_optionalChain([extensions, 'optionalAccess', _23 => _23.extendedSources]), () => ( []));
|
|
616
714
|
const sourcesByModuleMap = groupSourcesByModule(sources, baseOutputDir);
|
|
617
715
|
const modules = Object.keys(sourcesByModuleMap);
|
|
618
|
-
const baseVisitor = new
|
|
716
|
+
const baseVisitor = new (0, _visitorplugincommon.BaseVisitor)(options.config, {});
|
|
717
|
+
const { fieldTypes, fieldArguments } = collectObjectFieldTypesAndArguments(options.schemaAst);
|
|
619
718
|
const baseOutput = {
|
|
620
|
-
filename: (0,
|
|
719
|
+
filename: _path.resolve.call(void 0, cwd, baseOutputDir, baseTypesPath),
|
|
621
720
|
schema: options.schema,
|
|
622
721
|
documents: options.documents,
|
|
623
722
|
plugins: [
|
|
@@ -632,7 +731,7 @@ var preset = {
|
|
|
632
731
|
plugin: (schema) => {
|
|
633
732
|
const typeMap = schema.getTypeMap();
|
|
634
733
|
return Object.keys(typeMap).map((t) => {
|
|
635
|
-
if (t && typeMap[t] && (0,
|
|
734
|
+
if (t && typeMap[t] && _graphql.isScalarType.call(void 0, typeMap[t]) && !isGraphQLPrimitive(t)) {
|
|
636
735
|
const convertedName = baseVisitor.convertName(t);
|
|
637
736
|
return `export type ${convertedName} = Scalars["${t}"];`;
|
|
638
737
|
}
|
|
@@ -650,13 +749,13 @@ var preset = {
|
|
|
650
749
|
const baseTypesFilename = baseTypesPath.replace(/\.(js|ts|d.ts)$/, "");
|
|
651
750
|
const baseTypesDir = stripFilename(baseOutput.filename);
|
|
652
751
|
const outputs = modules.map((moduleName) => {
|
|
653
|
-
const filename = (0,
|
|
752
|
+
const filename = _path.resolve.call(void 0, cwd, baseOutputDir, moduleName, options.presetConfig.filename);
|
|
654
753
|
const dirpath = stripFilename(filename);
|
|
655
|
-
const relativePath = (0,
|
|
656
|
-
const importPath = options.presetConfig.importBaseTypesFrom || normalize((0,
|
|
754
|
+
const relativePath = _path.relative.call(void 0, dirpath, baseTypesDir);
|
|
755
|
+
const importPath = options.presetConfig.importBaseTypesFrom || normalize(_path.join.call(void 0, relativePath, baseTypesFilename));
|
|
657
756
|
const sources2 = sourcesByModuleMap[moduleName];
|
|
658
757
|
const documents = sources2.map((source) => source.document);
|
|
659
|
-
const moduleDocument = (0,
|
|
758
|
+
const moduleDocument = _graphql.concatAST.call(void 0, documents);
|
|
660
759
|
const shouldDeclare = filename.endsWith(".d.ts");
|
|
661
760
|
return {
|
|
662
761
|
filename,
|
|
@@ -680,10 +779,12 @@ var preset = {
|
|
|
680
779
|
schema,
|
|
681
780
|
baseVisitor,
|
|
682
781
|
useGraphQLModules: false,
|
|
782
|
+
fieldTypes,
|
|
783
|
+
fieldArguments,
|
|
683
784
|
rootTypes: [
|
|
684
|
-
schema.getQueryType()
|
|
685
|
-
schema.getMutationType()
|
|
686
|
-
schema.getSubscriptionType()
|
|
785
|
+
_optionalChain([schema, 'access', _24 => _24.getQueryType, 'call', _25 => _25(), 'optionalAccess', _26 => _26.name]) || "",
|
|
786
|
+
_optionalChain([schema, 'access', _27 => _27.getMutationType, 'call', _28 => _28(), 'optionalAccess', _29 => _29.name]) || "",
|
|
787
|
+
_optionalChain([schema, 'access', _30 => _30.getSubscriptionType, 'call', _31 => _31(), 'optionalAccess', _32 => _32.name]) || ""
|
|
687
788
|
].filter(Boolean)
|
|
688
789
|
})
|
|
689
790
|
}
|
|
@@ -696,447 +797,21 @@ var preset = {
|
|
|
696
797
|
}
|
|
697
798
|
};
|
|
698
799
|
|
|
699
|
-
// resolvers/index.ts
|
|
700
|
-
var resolvers_exports = {};
|
|
701
|
-
__export(resolvers_exports, {
|
|
702
|
-
plugin: () => plugin
|
|
703
|
-
});
|
|
704
|
-
var import_plugin_helpers = require("@graphql-codegen/plugin-helpers");
|
|
705
|
-
var import_visitor_plugin_common3 = require("@graphql-codegen/visitor-plugin-common");
|
|
706
|
-
|
|
707
|
-
// resolvers/visitor.ts
|
|
708
|
-
var import_typescript = require("@graphql-codegen/typescript");
|
|
709
|
-
var import_visitor_plugin_common2 = require("@graphql-codegen/visitor-plugin-common");
|
|
710
|
-
var import_auto_bind = __toESM(require("auto-bind"), 1);
|
|
711
|
-
var ENUM_RESOLVERS_SIGNATURE = "export type EnumResolverSignature<T, AllowedValues = any> = { [key in keyof T]?: AllowedValues };";
|
|
712
|
-
var TypeScriptResolversVisitor = class extends import_visitor_plugin_common2.BaseResolversVisitor {
|
|
713
|
-
constructor(pluginConfig, schema) {
|
|
714
|
-
super(
|
|
715
|
-
pluginConfig,
|
|
716
|
-
{
|
|
717
|
-
avoidOptionals: (0, import_visitor_plugin_common2.getConfigValue)(pluginConfig.avoidOptionals, false),
|
|
718
|
-
useIndexSignature: (0, import_visitor_plugin_common2.getConfigValue)(pluginConfig.useIndexSignature, false),
|
|
719
|
-
wrapFieldDefinitions: (0, import_visitor_plugin_common2.getConfigValue)(pluginConfig.wrapFieldDefinitions, false),
|
|
720
|
-
allowParentTypeOverride: (0, import_visitor_plugin_common2.getConfigValue)(pluginConfig.allowParentTypeOverride, false),
|
|
721
|
-
optionalInfoArgument: (0, import_visitor_plugin_common2.getConfigValue)(pluginConfig.optionalInfoArgument, false)
|
|
722
|
-
},
|
|
723
|
-
schema
|
|
724
|
-
);
|
|
725
|
-
(0, import_auto_bind.default)(this);
|
|
726
|
-
this.setVariablesTransformer(
|
|
727
|
-
new import_typescript.TypeScriptOperationVariablesToObject(
|
|
728
|
-
this.scalars,
|
|
729
|
-
this.convertName,
|
|
730
|
-
this.config.avoidOptionals,
|
|
731
|
-
this.config.immutableTypes,
|
|
732
|
-
this.config.namespacedImportName,
|
|
733
|
-
[],
|
|
734
|
-
this.config.enumPrefix,
|
|
735
|
-
this.config.enumValues
|
|
736
|
-
)
|
|
737
|
-
);
|
|
738
|
-
if (this.config.useIndexSignature) {
|
|
739
|
-
this._declarationBlockConfig = {
|
|
740
|
-
blockTransformer(block) {
|
|
741
|
-
return `ResolversObject<${block}>`;
|
|
742
|
-
}
|
|
743
|
-
};
|
|
744
|
-
}
|
|
745
|
-
}
|
|
746
|
-
transformParentGenericType(parentType) {
|
|
747
|
-
if (this.config.allowParentTypeOverride) {
|
|
748
|
-
return `ParentType = ${parentType}`;
|
|
749
|
-
}
|
|
750
|
-
return `ParentType extends ${parentType} = ${parentType}`;
|
|
751
|
-
}
|
|
752
|
-
formatRootResolver(schemaTypeName, resolverType, declarationKind) {
|
|
753
|
-
const avoidOptionals = this.config.avoidOptionals?.resolvers ?? this.config.avoidOptionals === true;
|
|
754
|
-
return `${schemaTypeName}${avoidOptionals ? "" : "?"}: ${resolverType}${this.getPunctuation(
|
|
755
|
-
declarationKind
|
|
756
|
-
)}`;
|
|
757
|
-
}
|
|
758
|
-
clearOptional(str) {
|
|
759
|
-
if (str.startsWith("Maybe")) {
|
|
760
|
-
return str.replace(/Maybe<(.*?)>$/, "$1");
|
|
761
|
-
}
|
|
762
|
-
return str;
|
|
763
|
-
}
|
|
764
|
-
ListType(node) {
|
|
765
|
-
return `Maybe<${super.ListType(node)}>`;
|
|
766
|
-
}
|
|
767
|
-
wrapWithListType(str) {
|
|
768
|
-
return `${this.config.immutableTypes ? "ReadonlyArray" : "Array"}<${str}>`;
|
|
769
|
-
}
|
|
770
|
-
getParentTypeForSignature(node) {
|
|
771
|
-
if (this._federation.isResolveReferenceField(node) && this.config.wrapFieldDefinitions) {
|
|
772
|
-
return "UnwrappedObject<ParentType>";
|
|
773
|
-
}
|
|
774
|
-
return "ParentType";
|
|
775
|
-
}
|
|
776
|
-
NamedType(node) {
|
|
777
|
-
return `Maybe<${super.NamedType(node)}>`;
|
|
778
|
-
}
|
|
779
|
-
NonNullType(node) {
|
|
780
|
-
const baseValue = super.NonNullType(node);
|
|
781
|
-
return this.clearOptional(baseValue);
|
|
782
|
-
}
|
|
783
|
-
getPunctuation(_declarationKind) {
|
|
784
|
-
return ";";
|
|
785
|
-
}
|
|
786
|
-
buildEnumResolverContentBlock(node, mappedEnumType) {
|
|
787
|
-
const valuesMap = `{ ${(node.values || []).map((v) => `${v.name}${this.config.avoidOptionals ? "" : "?"}: any`).join(", ")} }`;
|
|
788
|
-
this._globalDeclarations.add(ENUM_RESOLVERS_SIGNATURE);
|
|
789
|
-
return `EnumResolverSignature<${valuesMap}, ${mappedEnumType}>`;
|
|
790
|
-
}
|
|
791
|
-
buildEnumResolversExplicitMappedValues(node, valuesMapping) {
|
|
792
|
-
return `{ ${(node.values || []).map((v) => {
|
|
793
|
-
const valueName = v.name;
|
|
794
|
-
const mappedValue = valuesMapping[valueName];
|
|
795
|
-
return `${valueName}: ${typeof mappedValue === "number" ? mappedValue : `'${mappedValue}'`}`;
|
|
796
|
-
}).join(", ")} }`;
|
|
797
|
-
}
|
|
798
|
-
};
|
|
799
|
-
|
|
800
|
-
// resolvers/index.ts
|
|
801
|
-
var capitalize = (s) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
802
|
-
var plugin = (schema, documents, config) => {
|
|
803
|
-
const imports = [];
|
|
804
|
-
if (!config.customResolveInfo) {
|
|
805
|
-
imports.push("GraphQLResolveInfo");
|
|
806
|
-
}
|
|
807
|
-
const showUnusedMappers = typeof config.showUnusedMappers === "boolean" ? config.showUnusedMappers : true;
|
|
808
|
-
const noSchemaStitching = typeof config.noSchemaStitching === "boolean" ? config.noSchemaStitching : true;
|
|
809
|
-
const indexSignature = config.useIndexSignature ? [
|
|
810
|
-
"export type WithIndex<TObject> = TObject & Record<string, any>;",
|
|
811
|
-
"export type ResolversObject<TObject> = WithIndex<TObject>;"
|
|
812
|
-
].join("\n") : "";
|
|
813
|
-
const importType = config.useTypeImports ? "import type" : "import";
|
|
814
|
-
const prepend = [];
|
|
815
|
-
const defsToInclude = [];
|
|
816
|
-
const directiveResolverMappings = {};
|
|
817
|
-
if (config.directiveResolverMappings) {
|
|
818
|
-
for (const [directiveName, mapper] of Object.entries(config.directiveResolverMappings)) {
|
|
819
|
-
const parsedMapper = (0, import_visitor_plugin_common3.parseMapper)(mapper);
|
|
820
|
-
const capitalizedDirectiveName = capitalize(directiveName);
|
|
821
|
-
const resolverFnName = `ResolverFn${capitalizedDirectiveName}`;
|
|
822
|
-
const resolverFnUsage2 = `${resolverFnName}<TResult, TParent, TContext, TArgs>`;
|
|
823
|
-
const resolverWithResolveUsage2 = `Resolver${capitalizedDirectiveName}WithResolve<TResult, TParent, TContext, TArgs>`;
|
|
824
|
-
const resolverWithResolve2 = `
|
|
825
|
-
export type Resolver${capitalizedDirectiveName}WithResolve<TResult, TParent, TContext, TArgs> = {
|
|
826
|
-
resolve: ${resolverFnName}<TResult, TParent, TContext, TArgs>;
|
|
827
|
-
};`;
|
|
828
|
-
const resolverTypeName = `Resolver${capitalizedDirectiveName}`;
|
|
829
|
-
const resolverType2 = `export type ${resolverTypeName}<TResult, TParent = {}, TContext = {}, TArgs = {}> =`;
|
|
830
|
-
if (parsedMapper.isExternal) {
|
|
831
|
-
if (parsedMapper.default) {
|
|
832
|
-
prepend.push(`${importType} ${resolverFnName} from '${parsedMapper.source}';`);
|
|
833
|
-
} else {
|
|
834
|
-
prepend.push(
|
|
835
|
-
`${importType} { ${parsedMapper.import} ${parsedMapper.import !== resolverFnName ? `as ${resolverFnName} ` : ""}} from '${parsedMapper.source}';`
|
|
836
|
-
);
|
|
837
|
-
}
|
|
838
|
-
prepend.push(`export${config.useTypeImports ? " type" : ""} { ${resolverFnName} };`);
|
|
839
|
-
} else {
|
|
840
|
-
defsToInclude.push(
|
|
841
|
-
`export type ${resolverFnName}<TResult, TParent, TContext, TArgs> = ${parsedMapper.type}`
|
|
842
|
-
);
|
|
843
|
-
}
|
|
844
|
-
if (config.makeResolverTypeCallable) {
|
|
845
|
-
defsToInclude.push(`${resolverType2} ${resolverFnUsage2};`);
|
|
846
|
-
} else {
|
|
847
|
-
defsToInclude.push(resolverWithResolve2);
|
|
848
|
-
defsToInclude.push(`${resolverType2} ${resolverFnUsage2} | ${resolverWithResolveUsage2};`);
|
|
849
|
-
}
|
|
850
|
-
directiveResolverMappings[directiveName] = resolverTypeName;
|
|
851
|
-
}
|
|
852
|
-
}
|
|
853
|
-
const transformedSchema = config.federation ? (0, import_plugin_helpers.addFederationReferencesToSchema)(schema) : schema;
|
|
854
|
-
const visitor = new TypeScriptResolversVisitor(
|
|
855
|
-
{ ...config, directiveResolverMappings },
|
|
856
|
-
transformedSchema
|
|
857
|
-
);
|
|
858
|
-
const namespacedImportPrefix = visitor.config.namespacedImportName ? `${visitor.config.namespacedImportName}.` : "";
|
|
859
|
-
const astNode = (0, import_plugin_helpers.getCachedDocumentNodeFromSchema)(transformedSchema);
|
|
860
|
-
const visitorResult = (0, import_plugin_helpers.oldVisit)(astNode, { leave: visitor });
|
|
861
|
-
const optionalSignForInfoArg = visitor.config.optionalInfoArgument ? "?" : "";
|
|
862
|
-
const legacyStitchingResolverType = `
|
|
863
|
-
export type LegacyStitchingResolver<TResult, TParent, TContext, TArgs> = {
|
|
864
|
-
fragment: string;
|
|
865
|
-
resolve: ResolverFn<TResult, TParent, TContext, TArgs>;
|
|
866
|
-
};`;
|
|
867
|
-
const newStitchingResolverType = `
|
|
868
|
-
export type NewStitchingResolver<TResult, TParent, TContext, TArgs> = {
|
|
869
|
-
selectionSet: string | ((fieldNode: FieldNode) => SelectionSetNode);
|
|
870
|
-
resolve: ResolverFn<TResult, TParent, TContext, TArgs>;
|
|
871
|
-
};`;
|
|
872
|
-
const stitchingResolverType = "export type StitchingResolver<TResult, TParent, TContext, TArgs> = LegacyStitchingResolver<TResult, TParent, TContext, TArgs> | NewStitchingResolver<TResult, TParent, TContext, TArgs>;";
|
|
873
|
-
const resolverWithResolve = `
|
|
874
|
-
export type ResolverWithResolve<TResult, TParent, TContext, TArgs> = {
|
|
875
|
-
resolve: ResolverFn<TResult, TParent, TContext, TArgs>;
|
|
876
|
-
};`;
|
|
877
|
-
const resolverType = "export type Resolver<TResult, TParent = {}, TContext = {}, TArgs = {}> =";
|
|
878
|
-
const resolverFnUsage = "ResolverFn<TResult, TParent, TContext, TArgs>";
|
|
879
|
-
const resolverWithResolveUsage = "ResolverWithResolve<TResult, TParent, TContext, TArgs>";
|
|
880
|
-
const stitchingResolverUsage = "StitchingResolver<TResult, TParent, TContext, TArgs>";
|
|
881
|
-
if (visitor.hasFederation()) {
|
|
882
|
-
if (visitor.config.wrapFieldDefinitions) {
|
|
883
|
-
defsToInclude.push(`export type UnwrappedObject<T> = {
|
|
884
|
-
[P in keyof T]: T[P] extends infer R | Promise<infer R> | (() => infer R2 | Promise<infer R2>)
|
|
885
|
-
? R & R2 : T[P]
|
|
886
|
-
};`);
|
|
887
|
-
}
|
|
888
|
-
defsToInclude.push(`export type ReferenceResolver<TResult, TReference, TContext> = (
|
|
889
|
-
reference: TReference,
|
|
890
|
-
context: TContext,
|
|
891
|
-
info${optionalSignForInfoArg}: GraphQLResolveInfo
|
|
892
|
-
) => Promise<TResult> | TResult;`);
|
|
893
|
-
defsToInclude.push(`
|
|
894
|
-
type ScalarCheck<T, S> = S extends true ? T : NullableCheck<T, S>;
|
|
895
|
-
type NullableCheck<T, S> = ${namespacedImportPrefix}Maybe<T> extends T ? ${namespacedImportPrefix}Maybe<ListCheck<NonNullable<T>, S>> : ListCheck<T, S>;
|
|
896
|
-
type ListCheck<T, S> = T extends (infer U)[] ? NullableCheck<U, S>[] : GraphQLRecursivePick<T, S>;
|
|
897
|
-
export type GraphQLRecursivePick<T, S> = { [K in keyof T & keyof S]: ScalarCheck<T[K], S[K]> };
|
|
898
|
-
`);
|
|
899
|
-
}
|
|
900
|
-
if (!config.makeResolverTypeCallable) {
|
|
901
|
-
defsToInclude.push(resolverWithResolve);
|
|
902
|
-
}
|
|
903
|
-
if (noSchemaStitching) {
|
|
904
|
-
const defs = config.makeResolverTypeCallable ? `${resolverType} ${resolverFnUsage};` : `${resolverType} ${resolverFnUsage} | ${resolverWithResolveUsage};`;
|
|
905
|
-
defsToInclude.push(defs);
|
|
906
|
-
} else {
|
|
907
|
-
defsToInclude.push(
|
|
908
|
-
[
|
|
909
|
-
legacyStitchingResolverType,
|
|
910
|
-
newStitchingResolverType,
|
|
911
|
-
stitchingResolverType,
|
|
912
|
-
resolverType,
|
|
913
|
-
` | ${resolverFnUsage}`,
|
|
914
|
-
config.makeResolverTypeCallable ? "" : ` | ${resolverWithResolveUsage}`,
|
|
915
|
-
` | ${stitchingResolverUsage};`
|
|
916
|
-
].join("\n")
|
|
917
|
-
);
|
|
918
|
-
imports.push("SelectionSetNode", "FieldNode");
|
|
919
|
-
}
|
|
920
|
-
if (config.customResolverFn) {
|
|
921
|
-
const parsedMapper = (0, import_visitor_plugin_common3.parseMapper)(config.customResolverFn);
|
|
922
|
-
if (parsedMapper.isExternal) {
|
|
923
|
-
if (parsedMapper.default) {
|
|
924
|
-
prepend.push(`${importType} ResolverFn from '${parsedMapper.source}';`);
|
|
925
|
-
} else {
|
|
926
|
-
prepend.push(
|
|
927
|
-
`${importType} { ${parsedMapper.import} ${parsedMapper.import !== "ResolverFn" ? "as ResolverFn " : ""}} from '${parsedMapper.source}';`
|
|
928
|
-
);
|
|
929
|
-
}
|
|
930
|
-
prepend.push(`export${config.useTypeImports ? " type" : ""} { ResolverFn };`);
|
|
931
|
-
} else {
|
|
932
|
-
prepend.push(
|
|
933
|
-
`export type ResolverFn<TResult, TParent, TContext, TArgs> = ${parsedMapper.type}`
|
|
934
|
-
);
|
|
935
|
-
}
|
|
936
|
-
} else {
|
|
937
|
-
const defaultResolverFn = `
|
|
938
|
-
export type ResolverFn<TResult, TParent, TContext, TArgs> = (
|
|
939
|
-
parent: TParent,
|
|
940
|
-
args: TArgs,
|
|
941
|
-
context: TContext,
|
|
942
|
-
info${optionalSignForInfoArg}: GraphQLResolveInfo
|
|
943
|
-
) => Promise<TResult> | TResult;`;
|
|
944
|
-
defsToInclude.push(defaultResolverFn);
|
|
945
|
-
}
|
|
946
|
-
if (config.customSubscriptionResolver) {
|
|
947
|
-
const parsedMapper = (0, import_visitor_plugin_common3.parseMapper)(config.customSubscriptionResolver);
|
|
948
|
-
if (parsedMapper.isExternal) {
|
|
949
|
-
if (parsedMapper.default) {
|
|
950
|
-
prepend.push(`${importType} SubscriptionResolver from '${parsedMapper.source}';`);
|
|
951
|
-
} else {
|
|
952
|
-
prepend.push(
|
|
953
|
-
`${importType} { ${parsedMapper.import} ${parsedMapper.import !== "SubscriptionResolver" ? "as SubscriptionResolver " : ""}} from '${parsedMapper.source}';`
|
|
954
|
-
);
|
|
955
|
-
}
|
|
956
|
-
prepend.push(`export${config.useTypeImports ? " type" : ""} { SubscriptionResolver };`);
|
|
957
|
-
} else {
|
|
958
|
-
prepend.push(
|
|
959
|
-
`export type SubscriptionResolver<TResult, TKey extends string, TParent = {}, TContext = {}, TArgs = {}> = ${parsedMapper.type}`
|
|
960
|
-
);
|
|
961
|
-
}
|
|
962
|
-
} else {
|
|
963
|
-
const defaultSubscriptionDef = `
|
|
964
|
-
export type SubscriptionSubscribeFn<TResult, TParent, TContext, TArgs> = (
|
|
965
|
-
parent: TParent,
|
|
966
|
-
args: TArgs,
|
|
967
|
-
context: TContext,
|
|
968
|
-
info${optionalSignForInfoArg}: GraphQLResolveInfo
|
|
969
|
-
) => AsyncIterable<TResult> | Promise<AsyncIterable<TResult>>;
|
|
970
|
-
|
|
971
|
-
export type SubscriptionResolveFn<TResult, TParent, TContext, TArgs> = (
|
|
972
|
-
parent: TParent,
|
|
973
|
-
args: TArgs,
|
|
974
|
-
context: TContext,
|
|
975
|
-
info${optionalSignForInfoArg}: GraphQLResolveInfo
|
|
976
|
-
) => TResult | Promise<TResult>;
|
|
977
|
-
|
|
978
|
-
export interface SubscriptionSubscriberObject<TResult, TKey extends string, TParent, TContext, TArgs> {
|
|
979
|
-
subscribe: SubscriptionSubscribeFn<{ [key in TKey]: TResult }, TParent, TContext, TArgs>;
|
|
980
|
-
resolve?: SubscriptionResolveFn<TResult, { [key in TKey]: TResult }, TContext, TArgs>;
|
|
981
|
-
}
|
|
982
|
-
|
|
983
|
-
export interface SubscriptionResolverObject<TResult, TParent, TContext, TArgs> {
|
|
984
|
-
subscribe: SubscriptionSubscribeFn<any, TParent, TContext, TArgs>;
|
|
985
|
-
resolve: SubscriptionResolveFn<TResult, any, TContext, TArgs>;
|
|
986
|
-
}
|
|
987
|
-
|
|
988
|
-
export type SubscriptionObject<TResult, TKey extends string, TParent, TContext, TArgs> =
|
|
989
|
-
| SubscriptionSubscriberObject<TResult, TKey, TParent, TContext, TArgs>
|
|
990
|
-
| SubscriptionResolverObject<TResult, TParent, TContext, TArgs>;
|
|
991
|
-
|
|
992
|
-
export type SubscriptionResolver<TResult, TKey extends string, TParent = {}, TContext = {}, TArgs = {}> =
|
|
993
|
-
| ((...args: any[]) => SubscriptionObject<TResult, TKey, TParent, TContext, TArgs>)
|
|
994
|
-
| SubscriptionObject<TResult, TKey, TParent, TContext, TArgs>;
|
|
995
|
-
`;
|
|
996
|
-
defsToInclude.push(defaultSubscriptionDef);
|
|
997
|
-
}
|
|
998
|
-
const header = `${indexSignature}
|
|
999
|
-
|
|
1000
|
-
${visitor.getResolverTypeWrapperSignature()}
|
|
1001
|
-
|
|
1002
|
-
${defsToInclude.join("\n")}
|
|
1003
|
-
|
|
1004
|
-
export type TypeResolveFn<TTypes, TParent = {}, TContext = {}> = (
|
|
1005
|
-
parent: TParent,
|
|
1006
|
-
context: TContext,
|
|
1007
|
-
info${optionalSignForInfoArg}: GraphQLResolveInfo
|
|
1008
|
-
) => ${namespacedImportPrefix}Maybe<TTypes> | Promise<${namespacedImportPrefix}Maybe<TTypes>>;
|
|
1009
|
-
|
|
1010
|
-
export type IsTypeOfResolverFn<T = {}, TContext = {}> = (obj: T, context: TContext, info${optionalSignForInfoArg}: GraphQLResolveInfo) => boolean | Promise<boolean>;
|
|
1011
|
-
|
|
1012
|
-
export type NextResolverFn<T> = () => Promise<T>;
|
|
1013
|
-
|
|
1014
|
-
export type DirectiveResolverFn<TResult = {}, TParent = {}, TContext = {}, TArgs = {}> = (
|
|
1015
|
-
next: NextResolverFn<TResult>,
|
|
1016
|
-
parent: TParent,
|
|
1017
|
-
args: TArgs,
|
|
1018
|
-
context: TContext,
|
|
1019
|
-
info${optionalSignForInfoArg}: GraphQLResolveInfo
|
|
1020
|
-
) => TResult | Promise<TResult>;
|
|
1021
|
-
`;
|
|
1022
|
-
const resolversTypeMapping = visitor.buildResolversTypes();
|
|
1023
|
-
const resolversParentTypeMapping = visitor.buildResolversParentTypes();
|
|
1024
|
-
const { getRootResolver, getAllDirectiveResolvers, mappersImports, unusedMappers, hasScalars } = visitor;
|
|
1025
|
-
if (hasScalars()) {
|
|
1026
|
-
imports.push("GraphQLScalarType", "GraphQLScalarTypeConfig");
|
|
1027
|
-
}
|
|
1028
|
-
if (showUnusedMappers && unusedMappers.length) {
|
|
1029
|
-
console.warn(`Unused mappers: ${unusedMappers.join(",")}`);
|
|
1030
|
-
}
|
|
1031
|
-
if (imports.length) {
|
|
1032
|
-
prepend.push(`${importType} { ${imports.join(", ")} } from 'graphql';`);
|
|
1033
|
-
}
|
|
1034
|
-
if (config.customResolveInfo) {
|
|
1035
|
-
const parsedMapper = (0, import_visitor_plugin_common3.parseMapper)(config.customResolveInfo);
|
|
1036
|
-
if (parsedMapper.isExternal) {
|
|
1037
|
-
if (parsedMapper.default) {
|
|
1038
|
-
prepend.push(`import GraphQLResolveInfo from '${parsedMapper.source}'`);
|
|
1039
|
-
}
|
|
1040
|
-
prepend.push(
|
|
1041
|
-
`import { ${parsedMapper.import} ${parsedMapper.import !== "GraphQLResolveInfo" ? "as GraphQLResolveInfo" : ""} } from '${parsedMapper.source}';`
|
|
1042
|
-
);
|
|
1043
|
-
} else {
|
|
1044
|
-
prepend.push(`type GraphQLResolveInfo = ${parsedMapper.type}`);
|
|
1045
|
-
}
|
|
1046
|
-
}
|
|
1047
|
-
prepend.push(...mappersImports, ...visitor.globalDeclarations);
|
|
1048
|
-
return {
|
|
1049
|
-
prepend,
|
|
1050
|
-
content: [
|
|
1051
|
-
header,
|
|
1052
|
-
resolversTypeMapping,
|
|
1053
|
-
resolversParentTypeMapping,
|
|
1054
|
-
...visitorResult.definitions.filter((d) => typeof d === "string"),
|
|
1055
|
-
getRootResolver(),
|
|
1056
|
-
getAllDirectiveResolvers()
|
|
1057
|
-
].join("\n")
|
|
1058
|
-
};
|
|
1059
|
-
};
|
|
1060
|
-
|
|
1061
|
-
// utils/cache.ts
|
|
1062
|
-
function createCache() {
|
|
1063
|
-
const cache = /* @__PURE__ */ new Map();
|
|
1064
|
-
return function ensure(namespace, key, factory) {
|
|
1065
|
-
const cacheKey = `${namespace}:${key}`;
|
|
1066
|
-
const cachedValue = cache.get(cacheKey);
|
|
1067
|
-
if (cachedValue) {
|
|
1068
|
-
return cachedValue;
|
|
1069
|
-
}
|
|
1070
|
-
const value = factory();
|
|
1071
|
-
cache.set(cacheKey, value);
|
|
1072
|
-
return value;
|
|
1073
|
-
};
|
|
1074
|
-
}
|
|
1075
|
-
|
|
1076
|
-
// utils/load.ts
|
|
1077
|
-
var import_plugin_helpers3 = require("@graphql-codegen/plugin-helpers");
|
|
1078
|
-
var import_apollo_engine_loader = require("@graphql-tools/apollo-engine-loader");
|
|
1079
|
-
var import_code_file_loader = require("@graphql-tools/code-file-loader");
|
|
1080
|
-
var import_git_loader = require("@graphql-tools/git-loader");
|
|
1081
|
-
var import_github_loader = require("@graphql-tools/github-loader");
|
|
1082
|
-
var import_graphql_file_loader = require("@graphql-tools/graphql-file-loader");
|
|
1083
|
-
var import_json_file_loader = require("@graphql-tools/json-file-loader");
|
|
1084
|
-
var import_load = require("@graphql-tools/load");
|
|
1085
|
-
var import_prisma_loader = require("@graphql-tools/prisma-loader");
|
|
1086
|
-
var import_url_loader = require("@graphql-tools/url-loader");
|
|
1087
|
-
|
|
1088
|
-
// utils/hash.ts
|
|
1089
|
-
var import_plugin_helpers2 = require("@graphql-codegen/plugin-helpers");
|
|
1090
|
-
var import_graphql4 = require("graphql");
|
|
1091
|
-
var import_node_crypto = require("crypto");
|
|
1092
|
-
function hashContent(content) {
|
|
1093
|
-
return (0, import_node_crypto.createHash)("sha256").update(content).digest("hex");
|
|
1094
|
-
}
|
|
1095
|
-
function hashSchema(schema) {
|
|
1096
|
-
return hashContent((0, import_graphql4.print)((0, import_plugin_helpers2.getCachedDocumentNodeFromSchema)(schema)));
|
|
1097
|
-
}
|
|
1098
|
-
|
|
1099
|
-
// utils/load.ts
|
|
1100
|
-
async function loadSchema(schemaPointerMap, cwd) {
|
|
1101
|
-
const outputSchemaAst = await (0, import_load.loadSchema)(schemaPointerMap, {
|
|
1102
|
-
loaders: [
|
|
1103
|
-
new import_code_file_loader.CodeFileLoader(),
|
|
1104
|
-
new import_git_loader.GitLoader(),
|
|
1105
|
-
new import_github_loader.GithubLoader(),
|
|
1106
|
-
new import_graphql_file_loader.GraphQLFileLoader(),
|
|
1107
|
-
new import_json_file_loader.JsonFileLoader(),
|
|
1108
|
-
new import_url_loader.UrlLoader(),
|
|
1109
|
-
new import_apollo_engine_loader.ApolloEngineLoader(),
|
|
1110
|
-
new import_prisma_loader.PrismaLoader()
|
|
1111
|
-
],
|
|
1112
|
-
cwd,
|
|
1113
|
-
includeSources: true
|
|
1114
|
-
});
|
|
1115
|
-
if (!outputSchemaAst.extensions) {
|
|
1116
|
-
outputSchemaAst.extensions = {};
|
|
1117
|
-
}
|
|
1118
|
-
outputSchemaAst.extensions["hash"] = hashSchema(outputSchemaAst);
|
|
1119
|
-
return {
|
|
1120
|
-
outputSchemaAst,
|
|
1121
|
-
outputSchema: (0, import_plugin_helpers3.getCachedDocumentNodeFromSchema)(outputSchemaAst)
|
|
1122
|
-
};
|
|
1123
|
-
}
|
|
1124
|
-
|
|
1125
800
|
// lib/codegen.ts
|
|
1126
801
|
async function generate(options) {
|
|
1127
802
|
const root = process.cwd();
|
|
1128
|
-
const modulesDir =
|
|
803
|
+
const modulesDir = _path2.default.relative(root, options.modulesDir || "modules");
|
|
1129
804
|
const rootConfig = {
|
|
1130
|
-
schemas: (0,
|
|
805
|
+
schemas: _pluginhelpers.normalizeInstanceOrArray.call(void 0, options.schemas),
|
|
1131
806
|
modulesDir,
|
|
1132
|
-
baseTypesPath:
|
|
807
|
+
baseTypesPath: _path2.default.relative(modulesDir, options.baseTypesPath || "./__generated__/types.ts"),
|
|
1133
808
|
contextType: options.contextType,
|
|
1134
809
|
moduleDefinitionName: options.moduleDefinitionName || "typedef.ts",
|
|
1135
810
|
scalars: options.scalars,
|
|
1136
|
-
plugins: (0,
|
|
811
|
+
plugins: _pluginhelpers.normalizeConfig.call(void 0, ["typescript", "context"]),
|
|
1137
812
|
pluginMap: {
|
|
1138
813
|
typescript: typescriptPlugin,
|
|
1139
|
-
|
|
814
|
+
context: context_exports
|
|
1140
815
|
}
|
|
1141
816
|
};
|
|
1142
817
|
const cache = createCache();
|
|
@@ -1165,17 +840,9 @@ async function generate(options) {
|
|
|
1165
840
|
pluginMap: rootConfig.pluginMap,
|
|
1166
841
|
plugins: rootConfig.plugins,
|
|
1167
842
|
config: {
|
|
1168
|
-
useIndexSignature: true,
|
|
1169
843
|
inputMaybeValue: "T | undefined",
|
|
1170
|
-
mapperTypeSuffix: "Prisma",
|
|
1171
844
|
contextType: rootConfig.contextType,
|
|
1172
|
-
customResolverFn: "@baeta/core#Resolver",
|
|
1173
|
-
customSubscriptionResolver: "@baeta/core#SubscriptionResolver",
|
|
1174
845
|
useTypeImports: true,
|
|
1175
|
-
makeResolverTypeCallable: true,
|
|
1176
|
-
includeDirectives: true,
|
|
1177
|
-
resolverTypeWrapperSignature: "T",
|
|
1178
|
-
emitLegacyCommonJSImports: false,
|
|
1179
846
|
scalars: {
|
|
1180
847
|
BigInt: "number",
|
|
1181
848
|
Bytes: "Buffer",
|
|
@@ -1187,17 +854,17 @@ async function generate(options) {
|
|
|
1187
854
|
}
|
|
1188
855
|
});
|
|
1189
856
|
const promises = outputs.map(async (output) => {
|
|
1190
|
-
const result2 = await (0,
|
|
857
|
+
const result2 = await _core.codegen.call(void 0, {
|
|
1191
858
|
...output,
|
|
1192
859
|
cache
|
|
1193
860
|
});
|
|
1194
|
-
return new
|
|
861
|
+
return new (0, _plugin.File)(output.filename, result2, "graphql");
|
|
1195
862
|
});
|
|
1196
863
|
return Promise.all(promises);
|
|
1197
864
|
}
|
|
1198
865
|
|
|
1199
866
|
// index.ts
|
|
1200
|
-
var graphql_default = (0,
|
|
867
|
+
var graphql_default = _plugin.createPluginFactoryV1.call(void 0, {
|
|
1201
868
|
name: "graphql",
|
|
1202
869
|
watch: (baetaConfig, pluginConfig) => {
|
|
1203
870
|
return {
|
|
@@ -1211,5 +878,6 @@ var graphql_default = (0, import_plugin2.createPluginFactoryV1)({
|
|
|
1211
878
|
return params.next();
|
|
1212
879
|
}
|
|
1213
880
|
});
|
|
1214
|
-
|
|
1215
|
-
|
|
881
|
+
|
|
882
|
+
|
|
883
|
+
exports.default = graphql_default;
|