@graphql-codegen/visitor-plugin-common 3.0.2-alpha-20230301163319-6dd816ce1 → 3.0.2-alpha-20230301201231-702320107
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.
|
@@ -50,8 +50,6 @@ class BaseResolversVisitor extends base_visitor_js_1.BaseVisitor {
|
|
|
50
50
|
this._usedMappers = {};
|
|
51
51
|
this._resolversTypes = {};
|
|
52
52
|
this._resolversParentTypes = {};
|
|
53
|
-
this._hasReferencedResolversUnionTypes = false;
|
|
54
|
-
this._resolversUnionTypes = {};
|
|
55
53
|
this._rootTypeNames = new Set();
|
|
56
54
|
this._globalDeclarations = new Set();
|
|
57
55
|
this._hasScalars = false;
|
|
@@ -63,7 +61,6 @@ class BaseResolversVisitor extends base_visitor_js_1.BaseVisitor {
|
|
|
63
61
|
this._variablesTransformer = new variables_to_object_js_1.OperationVariablesToObject(this.scalars, this.convertName, this.config.namespacedImportName);
|
|
64
62
|
this._resolversTypes = this.createResolversFields(type => this.applyResolverTypeWrapper(type), type => this.clearResolverTypeWrapper(type), name => this.getTypeToUse(name));
|
|
65
63
|
this._resolversParentTypes = this.createResolversFields(type => type, type => type, name => this.getParentTypeToUse(name), namedType => !(0, graphql_1.isEnumType)(namedType));
|
|
66
|
-
this._resolversUnionTypes = this.createResolversUnionTypes();
|
|
67
64
|
this._fieldContextTypeMap = this.createFieldContextTypeMap();
|
|
68
65
|
this._directiveContextTypesMap = this.createDirectivedContextType();
|
|
69
66
|
this._directiveResolverMappings = (_a = rawConfig.directiveResolverMappings) !== null && _a !== void 0 ? _a : {};
|
|
@@ -165,9 +162,10 @@ class BaseResolversVisitor extends base_visitor_js_1.BaseVisitor {
|
|
|
165
162
|
prev[typeName] = applyWrapper(this._getScalar(typeName));
|
|
166
163
|
}
|
|
167
164
|
else if ((0, graphql_1.isUnionType)(schemaType)) {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
165
|
+
prev[typeName] = schemaType
|
|
166
|
+
.getTypes()
|
|
167
|
+
.map(type => getTypeToUse(type.name))
|
|
168
|
+
.join(' | ');
|
|
171
169
|
}
|
|
172
170
|
else if ((0, graphql_1.isEnumType)(schemaType)) {
|
|
173
171
|
prev[typeName] = this.convertName(typeName, { useTypesPrefix: this.config.enumPrefix }, true);
|
|
@@ -177,11 +175,36 @@ class BaseResolversVisitor extends base_visitor_js_1.BaseVisitor {
|
|
|
177
175
|
prev[typeName] = this.convertName(typeName, {}, true);
|
|
178
176
|
}
|
|
179
177
|
if (shouldApplyOmit && prev[typeName] !== 'any' && (0, graphql_1.isObjectType)(schemaType)) {
|
|
180
|
-
const
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
178
|
+
const fields = schemaType.getFields();
|
|
179
|
+
const relevantFields = this._federation
|
|
180
|
+
.filterFieldNames(Object.keys(fields))
|
|
181
|
+
.filter(fieldName => {
|
|
182
|
+
const field = fields[fieldName];
|
|
183
|
+
const baseType = (0, plugin_helpers_1.getBaseType)(field.type);
|
|
184
|
+
// Filter out fields of types that are not included
|
|
185
|
+
if (shouldInclude && !shouldInclude(baseType)) {
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
return true;
|
|
189
|
+
})
|
|
190
|
+
.map(fieldName => {
|
|
191
|
+
const field = fields[fieldName];
|
|
192
|
+
const baseType = (0, plugin_helpers_1.getBaseType)(field.type);
|
|
193
|
+
const isUnion = (0, graphql_1.isUnionType)(baseType);
|
|
194
|
+
if (!this.config.mappers[baseType.name] && !isUnion && !this._shouldMapType[baseType.name]) {
|
|
195
|
+
return null;
|
|
196
|
+
}
|
|
197
|
+
const addOptionalSign = !this.config.avoidOptionals && !(0, graphql_1.isNonNullType)(field.type);
|
|
198
|
+
return {
|
|
199
|
+
addOptionalSign,
|
|
200
|
+
fieldName,
|
|
201
|
+
replaceWithType: (0, utils_js_1.wrapTypeWithModifiers)(getTypeToUse(baseType.name), field.type, {
|
|
202
|
+
wrapOptional: this.applyMaybe,
|
|
203
|
+
wrapArray: this.wrapWithArray,
|
|
204
|
+
}),
|
|
205
|
+
};
|
|
206
|
+
})
|
|
207
|
+
.filter(a => a);
|
|
185
208
|
if (relevantFields.length > 0) {
|
|
186
209
|
// Puts ResolverTypeWrapper on top of an entire type
|
|
187
210
|
prev[typeName] = applyWrapper(this.replaceFieldsInType(prev[typeName], relevantFields));
|
|
@@ -195,15 +218,15 @@ class BaseResolversVisitor extends base_visitor_js_1.BaseVisitor {
|
|
|
195
218
|
prev[typeName] = replacePlaceholder(prev[typeName], typeName);
|
|
196
219
|
}
|
|
197
220
|
if (!isMapped && hasDefaultMapper && hasPlaceholder(this.config.defaultMapper.type)) {
|
|
198
|
-
|
|
221
|
+
// Make sure the inner type has no ResolverTypeWrapper
|
|
222
|
+
const name = clearWrapper(isScalar ? this._getScalar(typeName) : prev[typeName]);
|
|
223
|
+
const replaced = replacePlaceholder(this.config.defaultMapper.type, name);
|
|
224
|
+
// Don't wrap Union with ResolverTypeWrapper, each inner type already has it
|
|
199
225
|
if ((0, graphql_1.isUnionType)(schemaType)) {
|
|
200
|
-
|
|
201
|
-
prev[typeName] = replacePlaceholder(this.config.defaultMapper.type, originalTypeName);
|
|
226
|
+
prev[typeName] = replaced;
|
|
202
227
|
}
|
|
203
228
|
else {
|
|
204
|
-
|
|
205
|
-
const replaced = replacePlaceholder(this.config.defaultMapper.type, name);
|
|
206
|
-
prev[typeName] = applyWrapper(replaced);
|
|
229
|
+
prev[typeName] = applyWrapper(replacePlaceholder(this.config.defaultMapper.type, name));
|
|
207
230
|
}
|
|
208
231
|
}
|
|
209
232
|
return prev;
|
|
@@ -242,54 +265,6 @@ class BaseResolversVisitor extends base_visitor_js_1.BaseVisitor {
|
|
|
242
265
|
}
|
|
243
266
|
return `Array<${t}>`;
|
|
244
267
|
}
|
|
245
|
-
createResolversUnionTypes() {
|
|
246
|
-
if (!this._hasReferencedResolversUnionTypes) {
|
|
247
|
-
return {};
|
|
248
|
-
}
|
|
249
|
-
const allSchemaTypes = this._schema.getTypeMap();
|
|
250
|
-
const typeNames = this._federation.filterTypeNames(Object.keys(allSchemaTypes));
|
|
251
|
-
const unionTypes = typeNames.reduce((res, typeName) => {
|
|
252
|
-
const schemaType = allSchemaTypes[typeName];
|
|
253
|
-
if ((0, graphql_1.isUnionType)(schemaType)) {
|
|
254
|
-
const referencedTypes = schemaType.getTypes().map(unionMemberType => {
|
|
255
|
-
var _a;
|
|
256
|
-
const isUnionMemberMapped = this.config.mappers[unionMemberType.name];
|
|
257
|
-
// 1. If mapped without placehoder, just use it without doing extra checks
|
|
258
|
-
if (isUnionMemberMapped && !hasPlaceholder(isUnionMemberMapped.type)) {
|
|
259
|
-
return isUnionMemberMapped.type;
|
|
260
|
-
}
|
|
261
|
-
// 2. Work out value for union member type
|
|
262
|
-
// 2a. By default, use the typescript type
|
|
263
|
-
let unionMemberValue = this.convertName(unionMemberType.name, {}, true);
|
|
264
|
-
// 2b. Find fields to Omit if needed.
|
|
265
|
-
// - If no field to Omit, "type with maybe Omit" is typescript type i.e. no Omit
|
|
266
|
-
// - If there are fields to Omit, "type with maybe Omit"
|
|
267
|
-
const fieldsToOmit = this.getRelevantFieldsToOmit({
|
|
268
|
-
schemaType: unionMemberType,
|
|
269
|
-
getTypeToUse: this.getTypeToUse,
|
|
270
|
-
});
|
|
271
|
-
if (fieldsToOmit.length > 0) {
|
|
272
|
-
unionMemberValue = this.replaceFieldsInType(unionMemberValue, fieldsToOmit);
|
|
273
|
-
}
|
|
274
|
-
// 2c. If union member is mapped with placeholder, use the "type with maybe Omit" as {T}
|
|
275
|
-
if (isUnionMemberMapped && hasPlaceholder(isUnionMemberMapped.type)) {
|
|
276
|
-
return replacePlaceholder(isUnionMemberMapped.type, unionMemberValue);
|
|
277
|
-
}
|
|
278
|
-
// 2d. If has default mapper with placeholder, use the "type with maybe Omit" as {T}
|
|
279
|
-
const hasDefaultMapper = !!((_a = this.config.defaultMapper) === null || _a === void 0 ? void 0 : _a.type);
|
|
280
|
-
const isScalar = this.config.scalars[typeName];
|
|
281
|
-
if (hasDefaultMapper && hasPlaceholder(this.config.defaultMapper.type)) {
|
|
282
|
-
const finalTypename = isScalar ? this._getScalar(typeName) : unionMemberValue;
|
|
283
|
-
return replacePlaceholder(this.config.defaultMapper.type, finalTypename);
|
|
284
|
-
}
|
|
285
|
-
return unionMemberValue;
|
|
286
|
-
});
|
|
287
|
-
res[typeName] = referencedTypes.map(type => `( ${type} )`).join(' | '); // Must wrap every union member in explicit "( )" to separate the members
|
|
288
|
-
}
|
|
289
|
-
return res;
|
|
290
|
-
}, {});
|
|
291
|
-
return unionTypes;
|
|
292
|
-
}
|
|
293
268
|
createFieldContextTypeMap() {
|
|
294
269
|
return this.config.fieldContextTypes.reduce((prev, fieldContextType) => {
|
|
295
270
|
const items = fieldContextType.split('#');
|
|
@@ -334,20 +309,6 @@ class BaseResolversVisitor extends base_visitor_js_1.BaseVisitor {
|
|
|
334
309
|
.map(typeName => (0, utils_js_1.indent)(`${typeName}: ${this._resolversParentTypes[typeName]}${this.getPunctuation(declarationKind)}`))
|
|
335
310
|
.join('\n')).string;
|
|
336
311
|
}
|
|
337
|
-
buildResolversUnionTypes() {
|
|
338
|
-
if (Object.keys(this._resolversUnionTypes).length === 0) {
|
|
339
|
-
return '';
|
|
340
|
-
}
|
|
341
|
-
const declarationKind = 'type';
|
|
342
|
-
return new utils_js_1.DeclarationBlock(this._declarationBlockConfig)
|
|
343
|
-
.export()
|
|
344
|
-
.asKind(declarationKind)
|
|
345
|
-
.withName(this.convertName('ResolversUnionTypes'))
|
|
346
|
-
.withComment('Mapping of union types')
|
|
347
|
-
.withBlock(Object.entries(this._resolversUnionTypes)
|
|
348
|
-
.map(([typeName, value]) => (0, utils_js_1.indent)(`${typeName}: ${value}${this.getPunctuation(declarationKind)}`))
|
|
349
|
-
.join('\n')).string;
|
|
350
|
-
}
|
|
351
312
|
get schema() {
|
|
352
313
|
return this._schema;
|
|
353
314
|
}
|
|
@@ -746,38 +707,6 @@ class BaseResolversVisitor extends base_visitor_js_1.BaseVisitor {
|
|
|
746
707
|
SchemaDefinition() {
|
|
747
708
|
return null;
|
|
748
709
|
}
|
|
749
|
-
getRelevantFieldsToOmit({ schemaType, shouldInclude, getTypeToUse, }) {
|
|
750
|
-
const fields = schemaType.getFields();
|
|
751
|
-
return this._federation
|
|
752
|
-
.filterFieldNames(Object.keys(fields))
|
|
753
|
-
.filter(fieldName => {
|
|
754
|
-
const field = fields[fieldName];
|
|
755
|
-
const baseType = (0, plugin_helpers_1.getBaseType)(field.type);
|
|
756
|
-
// Filter out fields of types that are not included
|
|
757
|
-
if (shouldInclude && !shouldInclude(baseType)) {
|
|
758
|
-
return false;
|
|
759
|
-
}
|
|
760
|
-
return true;
|
|
761
|
-
})
|
|
762
|
-
.map(fieldName => {
|
|
763
|
-
const field = fields[fieldName];
|
|
764
|
-
const baseType = (0, plugin_helpers_1.getBaseType)(field.type);
|
|
765
|
-
const isUnion = (0, graphql_1.isUnionType)(baseType);
|
|
766
|
-
if (!this.config.mappers[baseType.name] && !isUnion && !this._shouldMapType[baseType.name]) {
|
|
767
|
-
return null;
|
|
768
|
-
}
|
|
769
|
-
const addOptionalSign = !this.config.avoidOptionals && !(0, graphql_1.isNonNullType)(field.type);
|
|
770
|
-
return {
|
|
771
|
-
addOptionalSign,
|
|
772
|
-
fieldName,
|
|
773
|
-
replaceWithType: (0, utils_js_1.wrapTypeWithModifiers)(getTypeToUse(baseType.name), field.type, {
|
|
774
|
-
wrapOptional: this.applyMaybe,
|
|
775
|
-
wrapArray: this.wrapWithArray,
|
|
776
|
-
}),
|
|
777
|
-
};
|
|
778
|
-
})
|
|
779
|
-
.filter(a => a);
|
|
780
|
-
}
|
|
781
710
|
}
|
|
782
711
|
exports.BaseResolversVisitor = BaseResolversVisitor;
|
|
783
712
|
function replacePlaceholder(pattern, typename) {
|
|
@@ -46,8 +46,6 @@ export class BaseResolversVisitor extends BaseVisitor {
|
|
|
46
46
|
this._usedMappers = {};
|
|
47
47
|
this._resolversTypes = {};
|
|
48
48
|
this._resolversParentTypes = {};
|
|
49
|
-
this._hasReferencedResolversUnionTypes = false;
|
|
50
|
-
this._resolversUnionTypes = {};
|
|
51
49
|
this._rootTypeNames = new Set();
|
|
52
50
|
this._globalDeclarations = new Set();
|
|
53
51
|
this._hasScalars = false;
|
|
@@ -59,7 +57,6 @@ export class BaseResolversVisitor extends BaseVisitor {
|
|
|
59
57
|
this._variablesTransformer = new OperationVariablesToObject(this.scalars, this.convertName, this.config.namespacedImportName);
|
|
60
58
|
this._resolversTypes = this.createResolversFields(type => this.applyResolverTypeWrapper(type), type => this.clearResolverTypeWrapper(type), name => this.getTypeToUse(name));
|
|
61
59
|
this._resolversParentTypes = this.createResolversFields(type => type, type => type, name => this.getParentTypeToUse(name), namedType => !isEnumType(namedType));
|
|
62
|
-
this._resolversUnionTypes = this.createResolversUnionTypes();
|
|
63
60
|
this._fieldContextTypeMap = this.createFieldContextTypeMap();
|
|
64
61
|
this._directiveContextTypesMap = this.createDirectivedContextType();
|
|
65
62
|
this._directiveResolverMappings = (_a = rawConfig.directiveResolverMappings) !== null && _a !== void 0 ? _a : {};
|
|
@@ -161,9 +158,10 @@ export class BaseResolversVisitor extends BaseVisitor {
|
|
|
161
158
|
prev[typeName] = applyWrapper(this._getScalar(typeName));
|
|
162
159
|
}
|
|
163
160
|
else if (isUnionType(schemaType)) {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
161
|
+
prev[typeName] = schemaType
|
|
162
|
+
.getTypes()
|
|
163
|
+
.map(type => getTypeToUse(type.name))
|
|
164
|
+
.join(' | ');
|
|
167
165
|
}
|
|
168
166
|
else if (isEnumType(schemaType)) {
|
|
169
167
|
prev[typeName] = this.convertName(typeName, { useTypesPrefix: this.config.enumPrefix }, true);
|
|
@@ -173,11 +171,36 @@ export class BaseResolversVisitor extends BaseVisitor {
|
|
|
173
171
|
prev[typeName] = this.convertName(typeName, {}, true);
|
|
174
172
|
}
|
|
175
173
|
if (shouldApplyOmit && prev[typeName] !== 'any' && isObjectType(schemaType)) {
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
174
|
+
const fields = schemaType.getFields();
|
|
175
|
+
const relevantFields = this._federation
|
|
176
|
+
.filterFieldNames(Object.keys(fields))
|
|
177
|
+
.filter(fieldName => {
|
|
178
|
+
const field = fields[fieldName];
|
|
179
|
+
const baseType = getBaseType(field.type);
|
|
180
|
+
// Filter out fields of types that are not included
|
|
181
|
+
if (shouldInclude && !shouldInclude(baseType)) {
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
return true;
|
|
185
|
+
})
|
|
186
|
+
.map(fieldName => {
|
|
187
|
+
const field = fields[fieldName];
|
|
188
|
+
const baseType = getBaseType(field.type);
|
|
189
|
+
const isUnion = isUnionType(baseType);
|
|
190
|
+
if (!this.config.mappers[baseType.name] && !isUnion && !this._shouldMapType[baseType.name]) {
|
|
191
|
+
return null;
|
|
192
|
+
}
|
|
193
|
+
const addOptionalSign = !this.config.avoidOptionals && !isNonNullType(field.type);
|
|
194
|
+
return {
|
|
195
|
+
addOptionalSign,
|
|
196
|
+
fieldName,
|
|
197
|
+
replaceWithType: wrapTypeWithModifiers(getTypeToUse(baseType.name), field.type, {
|
|
198
|
+
wrapOptional: this.applyMaybe,
|
|
199
|
+
wrapArray: this.wrapWithArray,
|
|
200
|
+
}),
|
|
201
|
+
};
|
|
202
|
+
})
|
|
203
|
+
.filter(a => a);
|
|
181
204
|
if (relevantFields.length > 0) {
|
|
182
205
|
// Puts ResolverTypeWrapper on top of an entire type
|
|
183
206
|
prev[typeName] = applyWrapper(this.replaceFieldsInType(prev[typeName], relevantFields));
|
|
@@ -191,15 +214,15 @@ export class BaseResolversVisitor extends BaseVisitor {
|
|
|
191
214
|
prev[typeName] = replacePlaceholder(prev[typeName], typeName);
|
|
192
215
|
}
|
|
193
216
|
if (!isMapped && hasDefaultMapper && hasPlaceholder(this.config.defaultMapper.type)) {
|
|
194
|
-
|
|
217
|
+
// Make sure the inner type has no ResolverTypeWrapper
|
|
218
|
+
const name = clearWrapper(isScalar ? this._getScalar(typeName) : prev[typeName]);
|
|
219
|
+
const replaced = replacePlaceholder(this.config.defaultMapper.type, name);
|
|
220
|
+
// Don't wrap Union with ResolverTypeWrapper, each inner type already has it
|
|
195
221
|
if (isUnionType(schemaType)) {
|
|
196
|
-
|
|
197
|
-
prev[typeName] = replacePlaceholder(this.config.defaultMapper.type, originalTypeName);
|
|
222
|
+
prev[typeName] = replaced;
|
|
198
223
|
}
|
|
199
224
|
else {
|
|
200
|
-
|
|
201
|
-
const replaced = replacePlaceholder(this.config.defaultMapper.type, name);
|
|
202
|
-
prev[typeName] = applyWrapper(replaced);
|
|
225
|
+
prev[typeName] = applyWrapper(replacePlaceholder(this.config.defaultMapper.type, name));
|
|
203
226
|
}
|
|
204
227
|
}
|
|
205
228
|
return prev;
|
|
@@ -238,54 +261,6 @@ export class BaseResolversVisitor extends BaseVisitor {
|
|
|
238
261
|
}
|
|
239
262
|
return `Array<${t}>`;
|
|
240
263
|
}
|
|
241
|
-
createResolversUnionTypes() {
|
|
242
|
-
if (!this._hasReferencedResolversUnionTypes) {
|
|
243
|
-
return {};
|
|
244
|
-
}
|
|
245
|
-
const allSchemaTypes = this._schema.getTypeMap();
|
|
246
|
-
const typeNames = this._federation.filterTypeNames(Object.keys(allSchemaTypes));
|
|
247
|
-
const unionTypes = typeNames.reduce((res, typeName) => {
|
|
248
|
-
const schemaType = allSchemaTypes[typeName];
|
|
249
|
-
if (isUnionType(schemaType)) {
|
|
250
|
-
const referencedTypes = schemaType.getTypes().map(unionMemberType => {
|
|
251
|
-
var _a;
|
|
252
|
-
const isUnionMemberMapped = this.config.mappers[unionMemberType.name];
|
|
253
|
-
// 1. If mapped without placehoder, just use it without doing extra checks
|
|
254
|
-
if (isUnionMemberMapped && !hasPlaceholder(isUnionMemberMapped.type)) {
|
|
255
|
-
return isUnionMemberMapped.type;
|
|
256
|
-
}
|
|
257
|
-
// 2. Work out value for union member type
|
|
258
|
-
// 2a. By default, use the typescript type
|
|
259
|
-
let unionMemberValue = this.convertName(unionMemberType.name, {}, true);
|
|
260
|
-
// 2b. Find fields to Omit if needed.
|
|
261
|
-
// - If no field to Omit, "type with maybe Omit" is typescript type i.e. no Omit
|
|
262
|
-
// - If there are fields to Omit, "type with maybe Omit"
|
|
263
|
-
const fieldsToOmit = this.getRelevantFieldsToOmit({
|
|
264
|
-
schemaType: unionMemberType,
|
|
265
|
-
getTypeToUse: this.getTypeToUse,
|
|
266
|
-
});
|
|
267
|
-
if (fieldsToOmit.length > 0) {
|
|
268
|
-
unionMemberValue = this.replaceFieldsInType(unionMemberValue, fieldsToOmit);
|
|
269
|
-
}
|
|
270
|
-
// 2c. If union member is mapped with placeholder, use the "type with maybe Omit" as {T}
|
|
271
|
-
if (isUnionMemberMapped && hasPlaceholder(isUnionMemberMapped.type)) {
|
|
272
|
-
return replacePlaceholder(isUnionMemberMapped.type, unionMemberValue);
|
|
273
|
-
}
|
|
274
|
-
// 2d. If has default mapper with placeholder, use the "type with maybe Omit" as {T}
|
|
275
|
-
const hasDefaultMapper = !!((_a = this.config.defaultMapper) === null || _a === void 0 ? void 0 : _a.type);
|
|
276
|
-
const isScalar = this.config.scalars[typeName];
|
|
277
|
-
if (hasDefaultMapper && hasPlaceholder(this.config.defaultMapper.type)) {
|
|
278
|
-
const finalTypename = isScalar ? this._getScalar(typeName) : unionMemberValue;
|
|
279
|
-
return replacePlaceholder(this.config.defaultMapper.type, finalTypename);
|
|
280
|
-
}
|
|
281
|
-
return unionMemberValue;
|
|
282
|
-
});
|
|
283
|
-
res[typeName] = referencedTypes.map(type => `( ${type} )`).join(' | '); // Must wrap every union member in explicit "( )" to separate the members
|
|
284
|
-
}
|
|
285
|
-
return res;
|
|
286
|
-
}, {});
|
|
287
|
-
return unionTypes;
|
|
288
|
-
}
|
|
289
264
|
createFieldContextTypeMap() {
|
|
290
265
|
return this.config.fieldContextTypes.reduce((prev, fieldContextType) => {
|
|
291
266
|
const items = fieldContextType.split('#');
|
|
@@ -330,20 +305,6 @@ export class BaseResolversVisitor extends BaseVisitor {
|
|
|
330
305
|
.map(typeName => indent(`${typeName}: ${this._resolversParentTypes[typeName]}${this.getPunctuation(declarationKind)}`))
|
|
331
306
|
.join('\n')).string;
|
|
332
307
|
}
|
|
333
|
-
buildResolversUnionTypes() {
|
|
334
|
-
if (Object.keys(this._resolversUnionTypes).length === 0) {
|
|
335
|
-
return '';
|
|
336
|
-
}
|
|
337
|
-
const declarationKind = 'type';
|
|
338
|
-
return new DeclarationBlock(this._declarationBlockConfig)
|
|
339
|
-
.export()
|
|
340
|
-
.asKind(declarationKind)
|
|
341
|
-
.withName(this.convertName('ResolversUnionTypes'))
|
|
342
|
-
.withComment('Mapping of union types')
|
|
343
|
-
.withBlock(Object.entries(this._resolversUnionTypes)
|
|
344
|
-
.map(([typeName, value]) => indent(`${typeName}: ${value}${this.getPunctuation(declarationKind)}`))
|
|
345
|
-
.join('\n')).string;
|
|
346
|
-
}
|
|
347
308
|
get schema() {
|
|
348
309
|
return this._schema;
|
|
349
310
|
}
|
|
@@ -742,38 +703,6 @@ export class BaseResolversVisitor extends BaseVisitor {
|
|
|
742
703
|
SchemaDefinition() {
|
|
743
704
|
return null;
|
|
744
705
|
}
|
|
745
|
-
getRelevantFieldsToOmit({ schemaType, shouldInclude, getTypeToUse, }) {
|
|
746
|
-
const fields = schemaType.getFields();
|
|
747
|
-
return this._federation
|
|
748
|
-
.filterFieldNames(Object.keys(fields))
|
|
749
|
-
.filter(fieldName => {
|
|
750
|
-
const field = fields[fieldName];
|
|
751
|
-
const baseType = getBaseType(field.type);
|
|
752
|
-
// Filter out fields of types that are not included
|
|
753
|
-
if (shouldInclude && !shouldInclude(baseType)) {
|
|
754
|
-
return false;
|
|
755
|
-
}
|
|
756
|
-
return true;
|
|
757
|
-
})
|
|
758
|
-
.map(fieldName => {
|
|
759
|
-
const field = fields[fieldName];
|
|
760
|
-
const baseType = getBaseType(field.type);
|
|
761
|
-
const isUnion = isUnionType(baseType);
|
|
762
|
-
if (!this.config.mappers[baseType.name] && !isUnion && !this._shouldMapType[baseType.name]) {
|
|
763
|
-
return null;
|
|
764
|
-
}
|
|
765
|
-
const addOptionalSign = !this.config.avoidOptionals && !isNonNullType(field.type);
|
|
766
|
-
return {
|
|
767
|
-
addOptionalSign,
|
|
768
|
-
fieldName,
|
|
769
|
-
replaceWithType: wrapTypeWithModifiers(getTypeToUse(baseType.name), field.type, {
|
|
770
|
-
wrapOptional: this.applyMaybe,
|
|
771
|
-
wrapArray: this.wrapWithArray,
|
|
772
|
-
}),
|
|
773
|
-
};
|
|
774
|
-
})
|
|
775
|
-
.filter(a => a);
|
|
776
|
-
}
|
|
777
706
|
}
|
|
778
707
|
function replacePlaceholder(pattern, typename) {
|
|
779
708
|
return pattern.replace(/\{T\}/g, typename);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/visitor-plugin-common",
|
|
3
|
-
"version": "3.0.2-alpha-
|
|
3
|
+
"version": "3.0.2-alpha-20230301201231-702320107",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"
|
|
6
6
|
},
|
|
@@ -525,8 +525,6 @@ export declare class BaseResolversVisitor<TRawConfig extends RawResolversConfig
|
|
|
525
525
|
};
|
|
526
526
|
protected _resolversTypes: ResolverTypes;
|
|
527
527
|
protected _resolversParentTypes: ResolverParentTypes;
|
|
528
|
-
protected _hasReferencedResolversUnionTypes: boolean;
|
|
529
|
-
protected _resolversUnionTypes: Record<string, string>;
|
|
530
528
|
protected _rootTypeNames: Set<string>;
|
|
531
529
|
protected _globalDeclarations: Set<string>;
|
|
532
530
|
protected _federation: ApolloFederation;
|
|
@@ -541,18 +539,20 @@ export declare class BaseResolversVisitor<TRawConfig extends RawResolversConfig
|
|
|
541
539
|
protected shouldMapType(type: GraphQLNamedType, duringCheck?: string[]): boolean;
|
|
542
540
|
convertName(node: ASTNode | string, options?: BaseVisitorConvertOptions & ConvertOptions, applyNamespacedImport?: boolean): string;
|
|
543
541
|
protected createResolversFields(applyWrapper: (str: string) => string, clearWrapper: (str: string) => string, getTypeToUse: (str: string) => string, shouldInclude?: (type: GraphQLNamedType) => boolean): ResolverTypes;
|
|
544
|
-
protected replaceFieldsInType(typeName: string, relevantFields:
|
|
542
|
+
protected replaceFieldsInType(typeName: string, relevantFields: {
|
|
543
|
+
addOptionalSign: boolean;
|
|
544
|
+
fieldName: string;
|
|
545
|
+
replaceWithType: string;
|
|
546
|
+
}[]): string;
|
|
545
547
|
protected applyMaybe(str: string): string;
|
|
546
548
|
protected applyResolverTypeWrapper(str: string): string;
|
|
547
549
|
protected clearMaybe(str: string): string;
|
|
548
550
|
protected clearResolverTypeWrapper(str: string): string;
|
|
549
551
|
protected wrapWithArray(t: string): string;
|
|
550
|
-
protected createResolversUnionTypes(): Record<string, string>;
|
|
551
552
|
protected createFieldContextTypeMap(): FieldContextTypeMap;
|
|
552
553
|
protected createDirectivedContextType(): FieldContextTypeMap;
|
|
553
554
|
buildResolversTypes(): string;
|
|
554
555
|
buildResolversParentTypes(): string;
|
|
555
|
-
buildResolversUnionTypes(): string;
|
|
556
556
|
get schema(): GraphQLSchema;
|
|
557
557
|
get defaultMapperType(): string;
|
|
558
558
|
get unusedMappers(): string[];
|
|
@@ -592,6 +592,5 @@ export declare class BaseResolversVisitor<TRawConfig extends RawResolversConfig
|
|
|
592
592
|
EnumTypeDefinition(node: EnumTypeDefinitionNode): string;
|
|
593
593
|
InterfaceTypeDefinition(node: InterfaceTypeDefinitionNode): string;
|
|
594
594
|
SchemaDefinition(): any;
|
|
595
|
-
private getRelevantFieldsToOmit;
|
|
596
595
|
}
|
|
597
596
|
export {};
|
|
@@ -525,8 +525,6 @@ export declare class BaseResolversVisitor<TRawConfig extends RawResolversConfig
|
|
|
525
525
|
};
|
|
526
526
|
protected _resolversTypes: ResolverTypes;
|
|
527
527
|
protected _resolversParentTypes: ResolverParentTypes;
|
|
528
|
-
protected _hasReferencedResolversUnionTypes: boolean;
|
|
529
|
-
protected _resolversUnionTypes: Record<string, string>;
|
|
530
528
|
protected _rootTypeNames: Set<string>;
|
|
531
529
|
protected _globalDeclarations: Set<string>;
|
|
532
530
|
protected _federation: ApolloFederation;
|
|
@@ -541,18 +539,20 @@ export declare class BaseResolversVisitor<TRawConfig extends RawResolversConfig
|
|
|
541
539
|
protected shouldMapType(type: GraphQLNamedType, duringCheck?: string[]): boolean;
|
|
542
540
|
convertName(node: ASTNode | string, options?: BaseVisitorConvertOptions & ConvertOptions, applyNamespacedImport?: boolean): string;
|
|
543
541
|
protected createResolversFields(applyWrapper: (str: string) => string, clearWrapper: (str: string) => string, getTypeToUse: (str: string) => string, shouldInclude?: (type: GraphQLNamedType) => boolean): ResolverTypes;
|
|
544
|
-
protected replaceFieldsInType(typeName: string, relevantFields:
|
|
542
|
+
protected replaceFieldsInType(typeName: string, relevantFields: {
|
|
543
|
+
addOptionalSign: boolean;
|
|
544
|
+
fieldName: string;
|
|
545
|
+
replaceWithType: string;
|
|
546
|
+
}[]): string;
|
|
545
547
|
protected applyMaybe(str: string): string;
|
|
546
548
|
protected applyResolverTypeWrapper(str: string): string;
|
|
547
549
|
protected clearMaybe(str: string): string;
|
|
548
550
|
protected clearResolverTypeWrapper(str: string): string;
|
|
549
551
|
protected wrapWithArray(t: string): string;
|
|
550
|
-
protected createResolversUnionTypes(): Record<string, string>;
|
|
551
552
|
protected createFieldContextTypeMap(): FieldContextTypeMap;
|
|
552
553
|
protected createDirectivedContextType(): FieldContextTypeMap;
|
|
553
554
|
buildResolversTypes(): string;
|
|
554
555
|
buildResolversParentTypes(): string;
|
|
555
|
-
buildResolversUnionTypes(): string;
|
|
556
556
|
get schema(): GraphQLSchema;
|
|
557
557
|
get defaultMapperType(): string;
|
|
558
558
|
get unusedMappers(): string[];
|
|
@@ -592,6 +592,5 @@ export declare class BaseResolversVisitor<TRawConfig extends RawResolversConfig
|
|
|
592
592
|
EnumTypeDefinition(node: EnumTypeDefinitionNode): string;
|
|
593
593
|
InterfaceTypeDefinition(node: InterfaceTypeDefinitionNode): string;
|
|
594
594
|
SchemaDefinition(): any;
|
|
595
|
-
private getRelevantFieldsToOmit;
|
|
596
595
|
}
|
|
597
596
|
export {};
|