@graphql-codegen/visitor-plugin-common 3.0.2-alpha-20230306010122-ebeb35b8c → 3.0.2-alpha-20230306073054-e69d84f1c
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/cjs/base-resolvers-visitor.js +44 -44
- package/esm/base-resolvers-visitor.js +44 -44
- package/package.json +1 -1
|
@@ -122,7 +122,6 @@ class BaseResolversVisitor extends base_visitor_js_1.BaseVisitor {
|
|
|
122
122
|
if (typeName.startsWith('__') || (shouldInclude && !shouldInclude(schemaType))) {
|
|
123
123
|
return prev;
|
|
124
124
|
}
|
|
125
|
-
let shouldApplyOmit = false;
|
|
126
125
|
const isRootType = this._rootTypeNames.has(typeName);
|
|
127
126
|
const isMapped = this.config.mappers[typeName];
|
|
128
127
|
const isScalar = this.config.scalars[typeName];
|
|
@@ -131,7 +130,7 @@ class BaseResolversVisitor extends base_visitor_js_1.BaseVisitor {
|
|
|
131
130
|
prev[typeName] = applyWrapper(this.config.rootValueType.type);
|
|
132
131
|
return prev;
|
|
133
132
|
}
|
|
134
|
-
if (isMapped && this.config.mappers[typeName].type) {
|
|
133
|
+
if (isMapped && this.config.mappers[typeName].type && !hasPlaceholder(this.config.mappers[typeName].type)) {
|
|
135
134
|
this.markMapperAsUsed(typeName);
|
|
136
135
|
prev[typeName] = applyWrapper(this.config.mappers[typeName].type);
|
|
137
136
|
}
|
|
@@ -171,51 +170,52 @@ class BaseResolversVisitor extends base_visitor_js_1.BaseVisitor {
|
|
|
171
170
|
prev[typeName] = this.convertName(typeName, { useTypesPrefix: this.config.enumPrefix }, true);
|
|
172
171
|
}
|
|
173
172
|
else {
|
|
174
|
-
shouldApplyOmit = true;
|
|
175
173
|
prev[typeName] = this.convertName(typeName, {}, true);
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
174
|
+
// apply omit
|
|
175
|
+
if (prev[typeName] !== 'any' && (0, graphql_1.isObjectType)(schemaType)) {
|
|
176
|
+
const fields = schemaType.getFields();
|
|
177
|
+
const relevantFields = this._federation
|
|
178
|
+
.filterFieldNames(Object.keys(fields))
|
|
179
|
+
.filter(fieldName => {
|
|
180
|
+
const field = fields[fieldName];
|
|
181
|
+
const baseType = (0, plugin_helpers_1.getBaseType)(field.type);
|
|
182
|
+
// Filter out fields of types that are not included
|
|
183
|
+
if (shouldInclude && !shouldInclude(baseType)) {
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
return true;
|
|
187
|
+
})
|
|
188
|
+
.map(fieldName => {
|
|
189
|
+
const field = fields[fieldName];
|
|
190
|
+
const baseType = (0, plugin_helpers_1.getBaseType)(field.type);
|
|
191
|
+
const isUnion = (0, graphql_1.isUnionType)(baseType);
|
|
192
|
+
if (!this.config.mappers[baseType.name] && !isUnion && !this._shouldMapType[baseType.name]) {
|
|
193
|
+
return null;
|
|
194
|
+
}
|
|
195
|
+
const addOptionalSign = !this.config.avoidOptionals && !(0, graphql_1.isNonNullType)(field.type);
|
|
196
|
+
return {
|
|
197
|
+
addOptionalSign,
|
|
198
|
+
fieldName,
|
|
199
|
+
replaceWithType: (0, utils_js_1.wrapTypeWithModifiers)(getTypeToUse(baseType.name), field.type, {
|
|
200
|
+
wrapOptional: this.applyMaybe,
|
|
201
|
+
wrapArray: this.wrapWithArray,
|
|
202
|
+
}),
|
|
203
|
+
};
|
|
204
|
+
})
|
|
205
|
+
.filter(a => a);
|
|
206
|
+
// If relevantFields, puts ResolverTypeWrapper on top of an entire type
|
|
207
|
+
let internalType = relevantFields.length > 0 ? this.replaceFieldsInType(prev[typeName], relevantFields) : prev[typeName];
|
|
208
|
+
if (isMapped) {
|
|
209
|
+
// replace the placeholder with the actual type
|
|
210
|
+
if (hasPlaceholder(internalType)) {
|
|
211
|
+
internalType = replacePlaceholder(internalType, typeName);
|
|
212
|
+
}
|
|
213
|
+
if (this.config.mappers[typeName].type && hasPlaceholder(this.config.mappers[typeName].type)) {
|
|
214
|
+
internalType = replacePlaceholder(this.config.mappers[typeName].type, internalType);
|
|
215
|
+
}
|
|
196
216
|
}
|
|
197
|
-
|
|
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);
|
|
208
|
-
if (relevantFields.length > 0) {
|
|
209
|
-
// Puts ResolverTypeWrapper on top of an entire type
|
|
210
|
-
prev[typeName] = applyWrapper(this.replaceFieldsInType(prev[typeName], relevantFields));
|
|
217
|
+
prev[typeName] = applyWrapper(internalType);
|
|
211
218
|
}
|
|
212
|
-
else {
|
|
213
|
-
// We still want to use ResolverTypeWrapper, even if we don't touch any fields
|
|
214
|
-
prev[typeName] = applyWrapper(prev[typeName]);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
if (isMapped && hasPlaceholder(prev[typeName])) {
|
|
218
|
-
prev[typeName] = replacePlaceholder(prev[typeName], typeName);
|
|
219
219
|
}
|
|
220
220
|
if (!isMapped && hasDefaultMapper && hasPlaceholder(this.config.defaultMapper.type)) {
|
|
221
221
|
// Make sure the inner type has no ResolverTypeWrapper
|
|
@@ -118,7 +118,6 @@ export class BaseResolversVisitor extends BaseVisitor {
|
|
|
118
118
|
if (typeName.startsWith('__') || (shouldInclude && !shouldInclude(schemaType))) {
|
|
119
119
|
return prev;
|
|
120
120
|
}
|
|
121
|
-
let shouldApplyOmit = false;
|
|
122
121
|
const isRootType = this._rootTypeNames.has(typeName);
|
|
123
122
|
const isMapped = this.config.mappers[typeName];
|
|
124
123
|
const isScalar = this.config.scalars[typeName];
|
|
@@ -127,7 +126,7 @@ export class BaseResolversVisitor extends BaseVisitor {
|
|
|
127
126
|
prev[typeName] = applyWrapper(this.config.rootValueType.type);
|
|
128
127
|
return prev;
|
|
129
128
|
}
|
|
130
|
-
if (isMapped && this.config.mappers[typeName].type) {
|
|
129
|
+
if (isMapped && this.config.mappers[typeName].type && !hasPlaceholder(this.config.mappers[typeName].type)) {
|
|
131
130
|
this.markMapperAsUsed(typeName);
|
|
132
131
|
prev[typeName] = applyWrapper(this.config.mappers[typeName].type);
|
|
133
132
|
}
|
|
@@ -167,51 +166,52 @@ export class BaseResolversVisitor extends BaseVisitor {
|
|
|
167
166
|
prev[typeName] = this.convertName(typeName, { useTypesPrefix: this.config.enumPrefix }, true);
|
|
168
167
|
}
|
|
169
168
|
else {
|
|
170
|
-
shouldApplyOmit = true;
|
|
171
169
|
prev[typeName] = this.convertName(typeName, {}, true);
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
170
|
+
// apply omit
|
|
171
|
+
if (prev[typeName] !== 'any' && isObjectType(schemaType)) {
|
|
172
|
+
const fields = schemaType.getFields();
|
|
173
|
+
const relevantFields = this._federation
|
|
174
|
+
.filterFieldNames(Object.keys(fields))
|
|
175
|
+
.filter(fieldName => {
|
|
176
|
+
const field = fields[fieldName];
|
|
177
|
+
const baseType = getBaseType(field.type);
|
|
178
|
+
// Filter out fields of types that are not included
|
|
179
|
+
if (shouldInclude && !shouldInclude(baseType)) {
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
return true;
|
|
183
|
+
})
|
|
184
|
+
.map(fieldName => {
|
|
185
|
+
const field = fields[fieldName];
|
|
186
|
+
const baseType = getBaseType(field.type);
|
|
187
|
+
const isUnion = isUnionType(baseType);
|
|
188
|
+
if (!this.config.mappers[baseType.name] && !isUnion && !this._shouldMapType[baseType.name]) {
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
const addOptionalSign = !this.config.avoidOptionals && !isNonNullType(field.type);
|
|
192
|
+
return {
|
|
193
|
+
addOptionalSign,
|
|
194
|
+
fieldName,
|
|
195
|
+
replaceWithType: wrapTypeWithModifiers(getTypeToUse(baseType.name), field.type, {
|
|
196
|
+
wrapOptional: this.applyMaybe,
|
|
197
|
+
wrapArray: this.wrapWithArray,
|
|
198
|
+
}),
|
|
199
|
+
};
|
|
200
|
+
})
|
|
201
|
+
.filter(a => a);
|
|
202
|
+
// If relevantFields, puts ResolverTypeWrapper on top of an entire type
|
|
203
|
+
let internalType = relevantFields.length > 0 ? this.replaceFieldsInType(prev[typeName], relevantFields) : prev[typeName];
|
|
204
|
+
if (isMapped) {
|
|
205
|
+
// replace the placeholder with the actual type
|
|
206
|
+
if (hasPlaceholder(internalType)) {
|
|
207
|
+
internalType = replacePlaceholder(internalType, typeName);
|
|
208
|
+
}
|
|
209
|
+
if (this.config.mappers[typeName].type && hasPlaceholder(this.config.mappers[typeName].type)) {
|
|
210
|
+
internalType = replacePlaceholder(this.config.mappers[typeName].type, internalType);
|
|
211
|
+
}
|
|
192
212
|
}
|
|
193
|
-
|
|
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);
|
|
204
|
-
if (relevantFields.length > 0) {
|
|
205
|
-
// Puts ResolverTypeWrapper on top of an entire type
|
|
206
|
-
prev[typeName] = applyWrapper(this.replaceFieldsInType(prev[typeName], relevantFields));
|
|
213
|
+
prev[typeName] = applyWrapper(internalType);
|
|
207
214
|
}
|
|
208
|
-
else {
|
|
209
|
-
// We still want to use ResolverTypeWrapper, even if we don't touch any fields
|
|
210
|
-
prev[typeName] = applyWrapper(prev[typeName]);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
if (isMapped && hasPlaceholder(prev[typeName])) {
|
|
214
|
-
prev[typeName] = replacePlaceholder(prev[typeName], typeName);
|
|
215
215
|
}
|
|
216
216
|
if (!isMapped && hasDefaultMapper && hasPlaceholder(this.config.defaultMapper.type)) {
|
|
217
217
|
// Make sure the inner type has no ResolverTypeWrapper
|
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-20230306073054-e69d84f1c",
|
|
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
|
},
|