@graphql-codegen/visitor-plugin-common 3.0.2-alpha-20230306073054-e69d84f1c → 3.0.2-alpha-20230306101700-e8822ec25

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.
@@ -122,6 +122,7 @@ 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;
125
126
  const isRootType = this._rootTypeNames.has(typeName);
126
127
  const isMapped = this.config.mappers[typeName];
127
128
  const isScalar = this.config.scalars[typeName];
@@ -130,7 +131,7 @@ class BaseResolversVisitor extends base_visitor_js_1.BaseVisitor {
130
131
  prev[typeName] = applyWrapper(this.config.rootValueType.type);
131
132
  return prev;
132
133
  }
133
- if (isMapped && this.config.mappers[typeName].type && !hasPlaceholder(this.config.mappers[typeName].type)) {
134
+ if (isMapped && this.config.mappers[typeName].type) {
134
135
  this.markMapperAsUsed(typeName);
135
136
  prev[typeName] = applyWrapper(this.config.mappers[typeName].type);
136
137
  }
@@ -170,52 +171,51 @@ class BaseResolversVisitor extends base_visitor_js_1.BaseVisitor {
170
171
  prev[typeName] = this.convertName(typeName, { useTypesPrefix: this.config.enumPrefix }, true);
171
172
  }
172
173
  else {
174
+ shouldApplyOmit = true;
173
175
  prev[typeName] = this.convertName(typeName, {}, true);
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
- }
176
+ }
177
+ if (shouldApplyOmit && prev[typeName] !== 'any' && (0, graphql_1.isObjectType)(schemaType)) {
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;
216
196
  }
217
- prev[typeName] = applyWrapper(internalType);
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);
208
+ if (relevantFields.length > 0) {
209
+ // Puts ResolverTypeWrapper on top of an entire type
210
+ prev[typeName] = applyWrapper(this.replaceFieldsInType(prev[typeName], relevantFields));
218
211
  }
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,6 +118,7 @@ export class BaseResolversVisitor extends BaseVisitor {
118
118
  if (typeName.startsWith('__') || (shouldInclude && !shouldInclude(schemaType))) {
119
119
  return prev;
120
120
  }
121
+ let shouldApplyOmit = false;
121
122
  const isRootType = this._rootTypeNames.has(typeName);
122
123
  const isMapped = this.config.mappers[typeName];
123
124
  const isScalar = this.config.scalars[typeName];
@@ -126,7 +127,7 @@ export class BaseResolversVisitor extends BaseVisitor {
126
127
  prev[typeName] = applyWrapper(this.config.rootValueType.type);
127
128
  return prev;
128
129
  }
129
- if (isMapped && this.config.mappers[typeName].type && !hasPlaceholder(this.config.mappers[typeName].type)) {
130
+ if (isMapped && this.config.mappers[typeName].type) {
130
131
  this.markMapperAsUsed(typeName);
131
132
  prev[typeName] = applyWrapper(this.config.mappers[typeName].type);
132
133
  }
@@ -166,52 +167,51 @@ export class BaseResolversVisitor extends BaseVisitor {
166
167
  prev[typeName] = this.convertName(typeName, { useTypesPrefix: this.config.enumPrefix }, true);
167
168
  }
168
169
  else {
170
+ shouldApplyOmit = true;
169
171
  prev[typeName] = this.convertName(typeName, {}, true);
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
- }
172
+ }
173
+ if (shouldApplyOmit && prev[typeName] !== 'any' && isObjectType(schemaType)) {
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;
212
192
  }
213
- prev[typeName] = applyWrapper(internalType);
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);
204
+ if (relevantFields.length > 0) {
205
+ // Puts ResolverTypeWrapper on top of an entire type
206
+ prev[typeName] = applyWrapper(this.replaceFieldsInType(prev[typeName], relevantFields));
214
207
  }
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-20230306073054-e69d84f1c",
3
+ "version": "3.0.2-alpha-20230306101700-e8822ec25",
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
  },