@graphql-codegen/typescript 4.1.6 → 5.0.0

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.
@@ -5,9 +5,9 @@ const tslib_1 = require("tslib");
5
5
  const auto_bind_1 = tslib_1.__importDefault(require("auto-bind"));
6
6
  const visitor_js_1 = require("./visitor.js");
7
7
  class TsIntrospectionVisitor extends visitor_js_1.TsVisitor {
8
+ typesToInclude = [];
8
9
  constructor(schema, pluginConfig = {}, typesToInclude) {
9
10
  super(schema, pluginConfig);
10
- this.typesToInclude = [];
11
11
  this.typesToInclude = typesToInclude;
12
12
  (0, auto_bind_1.default)(this);
13
13
  }
@@ -15,14 +15,14 @@ class TsIntrospectionVisitor extends visitor_js_1.TsVisitor {
15
15
  return null;
16
16
  }
17
17
  ObjectTypeDefinition(node, key, parent) {
18
- const name = node.name;
18
+ const name = node.name.value;
19
19
  if (this.typesToInclude.some(type => type.name === name)) {
20
20
  return super.ObjectTypeDefinition(node, key, parent);
21
21
  }
22
22
  return null;
23
23
  }
24
24
  EnumTypeDefinition(node) {
25
- const name = node.name;
25
+ const name = node.name.value;
26
26
  if (this.typesToInclude.some(type => type.name === name)) {
27
27
  return super.EnumTypeDefinition(node);
28
28
  }
@@ -4,6 +4,9 @@ exports.TypeScriptOperationVariablesToObject = void 0;
4
4
  const visitor_plugin_common_1 = require("@graphql-codegen/visitor-plugin-common");
5
5
  const graphql_1 = require("graphql");
6
6
  class TypeScriptOperationVariablesToObject extends visitor_plugin_common_1.OperationVariablesToObject {
7
+ _avoidOptionals;
8
+ _immutableTypes;
9
+ _maybeType;
7
10
  constructor(_scalars, _convertName, _avoidOptionals, _immutableTypes, _namespacedImportName = null, _enumNames = [], _enumPrefix = true, _enumSuffix = true, _enumValues = {}, _applyCoercion = false, _directiveArgumentAndInputFieldMappings = {}, _maybeType = 'Maybe') {
8
11
  super(_scalars, _convertName, _namespacedImportName, _enumNames, _enumPrefix, _enumSuffix, _enumValues, _applyCoercion, _directiveArgumentAndInputFieldMappings);
9
12
  this._avoidOptionals = _avoidOptionals;
package/cjs/visitor.js CHANGED
@@ -43,7 +43,7 @@ class TsVisitor extends visitor_plugin_common_1.BaseTypesVisitor {
43
43
  });
44
44
  }
45
45
  _getTypeForNode(node, isVisitingInputType) {
46
- const typeAsString = node.name;
46
+ const typeAsString = node.name.value;
47
47
  if (this.config.useImplementingTypes) {
48
48
  const allTypesMap = this._schema.getTypeMap();
49
49
  const implementingTypes = [];
@@ -61,7 +61,7 @@ class TsVisitor extends visitor_plugin_common_1.BaseTypesVisitor {
61
61
  }
62
62
  }
63
63
  const typeString = super._getTypeForNode(node, isVisitingInputType);
64
- const schemaType = this._schema.getType(node.name);
64
+ const schemaType = this._schema.getType(node.name.value);
65
65
  if ((0, graphql_1.isEnumType)(schemaType)) {
66
66
  // futureProofEnums + enumsAsTypes combination adds the future value to the enum type itself
67
67
  // so it's not necessary to repeat it in the usage
@@ -167,7 +167,7 @@ class TsVisitor extends visitor_plugin_common_1.BaseTypesVisitor {
167
167
  .export()
168
168
  .asKind('type')
169
169
  .withName(this.convertName(node))
170
- .withComment(node.description)
170
+ .withComment(node.description?.value)
171
171
  .withContent(possibleTypes).string;
172
172
  // return super.UnionTypeDefinition(node, key, parent).concat(withFutureAddedValue).join("");
173
173
  }
@@ -187,7 +187,7 @@ class TsVisitor extends visitor_plugin_common_1.BaseTypesVisitor {
187
187
  const comment = this.getNodeComment(node);
188
188
  const { type } = this.config.declarationKind;
189
189
  return (comment +
190
- (0, visitor_plugin_common_1.indent)(`${this.config.immutableTypes ? 'readonly ' : ''}${node.name}${addOptionalSign ? '?' : ''}: ${typeString}${this.getPunctuation(type)}`));
190
+ (0, visitor_plugin_common_1.indent)(`${this.config.immutableTypes ? 'readonly ' : ''}${node.name.value}${addOptionalSign ? '?' : ''}: ${typeString}${this.getPunctuation(type)}`));
191
191
  }
192
192
  InputValueDefinition(node, key, parent, _path, ancestors) {
193
193
  const originalFieldNode = parent[key];
@@ -202,7 +202,7 @@ class TsVisitor extends visitor_plugin_common_1.BaseTypesVisitor {
202
202
  }
203
203
  const readonlyPrefix = this.config.immutableTypes ? 'readonly ' : '';
204
204
  const buildFieldDefinition = (isOneOf = false) => {
205
- return `${readonlyPrefix}${node.name}${addOptionalSign && !isOneOf ? '?' : ''}: ${isOneOf ? this.clearOptional(type) : type}${this.getPunctuation(declarationKind)}`;
205
+ return `${readonlyPrefix}${node.name.value}${addOptionalSign && !isOneOf ? '?' : ''}: ${isOneOf ? this.clearOptional(type) : type}${this.getPunctuation(declarationKind)}`;
206
206
  };
207
207
  const realParentDef = ancestors?.[ancestors.length - 1];
208
208
  if (realParentDef) {
@@ -213,8 +213,7 @@ class TsVisitor extends visitor_plugin_common_1.BaseTypesVisitor {
213
213
  }
214
214
  const fieldParts = [];
215
215
  for (const fieldName of Object.keys(parentType.getFields())) {
216
- // Why the heck is node.name a string and not { value: string } at runtime ?!
217
- if (fieldName === node.name) {
216
+ if (fieldName === node.name.value) {
218
217
  fieldParts.push(buildFieldDefinition(true));
219
218
  continue;
220
219
  }
@@ -226,7 +225,7 @@ class TsVisitor extends visitor_plugin_common_1.BaseTypesVisitor {
226
225
  return comment + (0, visitor_plugin_common_1.indent)(buildFieldDefinition());
227
226
  }
228
227
  EnumTypeDefinition(node) {
229
- const enumName = node.name;
228
+ const enumName = node.name.value;
230
229
  // In case of mapped external enum string
231
230
  if (this.config.enumValues[enumName]?.sourceFile) {
232
231
  return `export { ${this.config.enumValues[enumName].typeIdentifier} };\n`;
@@ -248,14 +247,14 @@ class TsVisitor extends visitor_plugin_common_1.BaseTypesVisitor {
248
247
  return new visitor_plugin_common_1.DeclarationBlock(this._declarationBlockConfig)
249
248
  .export()
250
249
  .asKind('type')
251
- .withComment(node.description)
250
+ .withComment(node.description?.value)
252
251
  .withName(enumTypeName)
253
252
  .withContent('\n' +
254
253
  node.values
255
254
  .map(enumOption => {
256
- const name = enumOption.name;
255
+ const name = enumOption.name.value;
257
256
  const enumValue = getValueFromConfig(name) ?? name;
258
- const comment = (0, visitor_plugin_common_1.transformComment)(enumOption.description, 1);
257
+ const comment = (0, visitor_plugin_common_1.transformComment)(enumOption.description?.value, 1);
259
258
  return comment + (0, visitor_plugin_common_1.indent)('| ' + (0, visitor_plugin_common_1.wrapWithSingleQuotes)(enumValue));
260
259
  })
261
260
  .concat(...withFutureAddedValue)
@@ -264,14 +263,14 @@ class TsVisitor extends visitor_plugin_common_1.BaseTypesVisitor {
264
263
  if (this.config.numericEnums) {
265
264
  const block = new visitor_plugin_common_1.DeclarationBlock(this._declarationBlockConfig)
266
265
  .export()
267
- .withComment(node.description)
266
+ .withComment(node.description?.value)
268
267
  .withName(enumTypeName)
269
268
  .asKind('enum')
270
269
  .withBlock(node.values
271
270
  .map((enumOption, i) => {
272
- const valueFromConfig = getValueFromConfig(enumOption.name);
271
+ const valueFromConfig = getValueFromConfig(enumOption.name.value);
273
272
  const enumValue = valueFromConfig ?? i;
274
- const comment = (0, visitor_plugin_common_1.transformComment)(enumOption.description, 1);
273
+ const comment = (0, visitor_plugin_common_1.transformComment)(enumOption.description?.value, 1);
275
274
  const optionName = this.makeValidEnumIdentifier(this.convertName(enumOption, {
276
275
  useTypesPrefix: false,
277
276
  transformUnderscore: true,
@@ -293,15 +292,15 @@ class TsVisitor extends visitor_plugin_common_1.BaseTypesVisitor {
293
292
  .export()
294
293
  .asKind('const')
295
294
  .withName(enumTypeName)
296
- .withComment(node.description)
295
+ .withComment(node.description?.value)
297
296
  .withBlock(node.values
298
297
  .map(enumOption => {
299
298
  const optionName = this.makeValidEnumIdentifier(this.convertName(enumOption, {
300
299
  useTypesPrefix: false,
301
300
  transformUnderscore: true,
302
301
  }));
303
- const comment = (0, visitor_plugin_common_1.transformComment)(enumOption.description, 1);
304
- const name = enumOption.name;
302
+ const comment = (0, visitor_plugin_common_1.transformComment)(enumOption.description?.value, 1);
303
+ const name = enumOption.name.value;
305
304
  const enumValue = getValueFromConfig(name) ?? name;
306
305
  return comment + (0, visitor_plugin_common_1.indent)(`${optionName}: ${(0, visitor_plugin_common_1.wrapWithSingleQuotes)(enumValue)}`);
307
306
  })
@@ -312,7 +311,7 @@ class TsVisitor extends visitor_plugin_common_1.BaseTypesVisitor {
312
311
  .export()
313
312
  .asKind(this.config.constEnums ? 'const enum' : 'enum')
314
313
  .withName(enumTypeName)
315
- .withComment(node.description)
314
+ .withComment(node.description?.value)
316
315
  .withBlock(this.buildEnumValuesBlock(enumName, node.values)).string;
317
316
  }
318
317
  getPunctuation(_declarationKind) {
@@ -1,9 +1,9 @@
1
1
  import autoBind from 'auto-bind';
2
2
  import { TsVisitor } from './visitor.js';
3
3
  export class TsIntrospectionVisitor extends TsVisitor {
4
+ typesToInclude = [];
4
5
  constructor(schema, pluginConfig = {}, typesToInclude) {
5
6
  super(schema, pluginConfig);
6
- this.typesToInclude = [];
7
7
  this.typesToInclude = typesToInclude;
8
8
  autoBind(this);
9
9
  }
@@ -11,14 +11,14 @@ export class TsIntrospectionVisitor extends TsVisitor {
11
11
  return null;
12
12
  }
13
13
  ObjectTypeDefinition(node, key, parent) {
14
- const name = node.name;
14
+ const name = node.name.value;
15
15
  if (this.typesToInclude.some(type => type.name === name)) {
16
16
  return super.ObjectTypeDefinition(node, key, parent);
17
17
  }
18
18
  return null;
19
19
  }
20
20
  EnumTypeDefinition(node) {
21
- const name = node.name;
21
+ const name = node.name.value;
22
22
  if (this.typesToInclude.some(type => type.name === name)) {
23
23
  return super.EnumTypeDefinition(node);
24
24
  }
@@ -1,6 +1,9 @@
1
1
  import { OperationVariablesToObject, } from '@graphql-codegen/visitor-plugin-common';
2
2
  import { Kind } from 'graphql';
3
3
  export class TypeScriptOperationVariablesToObject extends OperationVariablesToObject {
4
+ _avoidOptionals;
5
+ _immutableTypes;
6
+ _maybeType;
4
7
  constructor(_scalars, _convertName, _avoidOptionals, _immutableTypes, _namespacedImportName = null, _enumNames = [], _enumPrefix = true, _enumSuffix = true, _enumValues = {}, _applyCoercion = false, _directiveArgumentAndInputFieldMappings = {}, _maybeType = 'Maybe') {
5
8
  super(_scalars, _convertName, _namespacedImportName, _enumNames, _enumPrefix, _enumSuffix, _enumValues, _applyCoercion, _directiveArgumentAndInputFieldMappings);
6
9
  this._avoidOptionals = _avoidOptionals;
package/esm/visitor.js CHANGED
@@ -39,7 +39,7 @@ export class TsVisitor extends BaseTypesVisitor {
39
39
  });
40
40
  }
41
41
  _getTypeForNode(node, isVisitingInputType) {
42
- const typeAsString = node.name;
42
+ const typeAsString = node.name.value;
43
43
  if (this.config.useImplementingTypes) {
44
44
  const allTypesMap = this._schema.getTypeMap();
45
45
  const implementingTypes = [];
@@ -57,7 +57,7 @@ export class TsVisitor extends BaseTypesVisitor {
57
57
  }
58
58
  }
59
59
  const typeString = super._getTypeForNode(node, isVisitingInputType);
60
- const schemaType = this._schema.getType(node.name);
60
+ const schemaType = this._schema.getType(node.name.value);
61
61
  if (isEnumType(schemaType)) {
62
62
  // futureProofEnums + enumsAsTypes combination adds the future value to the enum type itself
63
63
  // so it's not necessary to repeat it in the usage
@@ -163,7 +163,7 @@ export class TsVisitor extends BaseTypesVisitor {
163
163
  .export()
164
164
  .asKind('type')
165
165
  .withName(this.convertName(node))
166
- .withComment(node.description)
166
+ .withComment(node.description?.value)
167
167
  .withContent(possibleTypes).string;
168
168
  // return super.UnionTypeDefinition(node, key, parent).concat(withFutureAddedValue).join("");
169
169
  }
@@ -183,7 +183,7 @@ export class TsVisitor extends BaseTypesVisitor {
183
183
  const comment = this.getNodeComment(node);
184
184
  const { type } = this.config.declarationKind;
185
185
  return (comment +
186
- indent(`${this.config.immutableTypes ? 'readonly ' : ''}${node.name}${addOptionalSign ? '?' : ''}: ${typeString}${this.getPunctuation(type)}`));
186
+ indent(`${this.config.immutableTypes ? 'readonly ' : ''}${node.name.value}${addOptionalSign ? '?' : ''}: ${typeString}${this.getPunctuation(type)}`));
187
187
  }
188
188
  InputValueDefinition(node, key, parent, _path, ancestors) {
189
189
  const originalFieldNode = parent[key];
@@ -198,7 +198,7 @@ export class TsVisitor extends BaseTypesVisitor {
198
198
  }
199
199
  const readonlyPrefix = this.config.immutableTypes ? 'readonly ' : '';
200
200
  const buildFieldDefinition = (isOneOf = false) => {
201
- return `${readonlyPrefix}${node.name}${addOptionalSign && !isOneOf ? '?' : ''}: ${isOneOf ? this.clearOptional(type) : type}${this.getPunctuation(declarationKind)}`;
201
+ return `${readonlyPrefix}${node.name.value}${addOptionalSign && !isOneOf ? '?' : ''}: ${isOneOf ? this.clearOptional(type) : type}${this.getPunctuation(declarationKind)}`;
202
202
  };
203
203
  const realParentDef = ancestors?.[ancestors.length - 1];
204
204
  if (realParentDef) {
@@ -209,8 +209,7 @@ export class TsVisitor extends BaseTypesVisitor {
209
209
  }
210
210
  const fieldParts = [];
211
211
  for (const fieldName of Object.keys(parentType.getFields())) {
212
- // Why the heck is node.name a string and not { value: string } at runtime ?!
213
- if (fieldName === node.name) {
212
+ if (fieldName === node.name.value) {
214
213
  fieldParts.push(buildFieldDefinition(true));
215
214
  continue;
216
215
  }
@@ -222,7 +221,7 @@ export class TsVisitor extends BaseTypesVisitor {
222
221
  return comment + indent(buildFieldDefinition());
223
222
  }
224
223
  EnumTypeDefinition(node) {
225
- const enumName = node.name;
224
+ const enumName = node.name.value;
226
225
  // In case of mapped external enum string
227
226
  if (this.config.enumValues[enumName]?.sourceFile) {
228
227
  return `export { ${this.config.enumValues[enumName].typeIdentifier} };\n`;
@@ -244,14 +243,14 @@ export class TsVisitor extends BaseTypesVisitor {
244
243
  return new DeclarationBlock(this._declarationBlockConfig)
245
244
  .export()
246
245
  .asKind('type')
247
- .withComment(node.description)
246
+ .withComment(node.description?.value)
248
247
  .withName(enumTypeName)
249
248
  .withContent('\n' +
250
249
  node.values
251
250
  .map(enumOption => {
252
- const name = enumOption.name;
251
+ const name = enumOption.name.value;
253
252
  const enumValue = getValueFromConfig(name) ?? name;
254
- const comment = transformComment(enumOption.description, 1);
253
+ const comment = transformComment(enumOption.description?.value, 1);
255
254
  return comment + indent('| ' + wrapWithSingleQuotes(enumValue));
256
255
  })
257
256
  .concat(...withFutureAddedValue)
@@ -260,14 +259,14 @@ export class TsVisitor extends BaseTypesVisitor {
260
259
  if (this.config.numericEnums) {
261
260
  const block = new DeclarationBlock(this._declarationBlockConfig)
262
261
  .export()
263
- .withComment(node.description)
262
+ .withComment(node.description?.value)
264
263
  .withName(enumTypeName)
265
264
  .asKind('enum')
266
265
  .withBlock(node.values
267
266
  .map((enumOption, i) => {
268
- const valueFromConfig = getValueFromConfig(enumOption.name);
267
+ const valueFromConfig = getValueFromConfig(enumOption.name.value);
269
268
  const enumValue = valueFromConfig ?? i;
270
- const comment = transformComment(enumOption.description, 1);
269
+ const comment = transformComment(enumOption.description?.value, 1);
271
270
  const optionName = this.makeValidEnumIdentifier(this.convertName(enumOption, {
272
271
  useTypesPrefix: false,
273
272
  transformUnderscore: true,
@@ -289,15 +288,15 @@ export class TsVisitor extends BaseTypesVisitor {
289
288
  .export()
290
289
  .asKind('const')
291
290
  .withName(enumTypeName)
292
- .withComment(node.description)
291
+ .withComment(node.description?.value)
293
292
  .withBlock(node.values
294
293
  .map(enumOption => {
295
294
  const optionName = this.makeValidEnumIdentifier(this.convertName(enumOption, {
296
295
  useTypesPrefix: false,
297
296
  transformUnderscore: true,
298
297
  }));
299
- const comment = transformComment(enumOption.description, 1);
300
- const name = enumOption.name;
298
+ const comment = transformComment(enumOption.description?.value, 1);
299
+ const name = enumOption.name.value;
301
300
  const enumValue = getValueFromConfig(name) ?? name;
302
301
  return comment + indent(`${optionName}: ${wrapWithSingleQuotes(enumValue)}`);
303
302
  })
@@ -308,7 +307,7 @@ export class TsVisitor extends BaseTypesVisitor {
308
307
  .export()
309
308
  .asKind(this.config.constEnums ? 'const enum' : 'enum')
310
309
  .withName(enumTypeName)
311
- .withComment(node.description)
310
+ .withComment(node.description?.value)
312
311
  .withBlock(this.buildEnumValuesBlock(enumName, node.values)).string;
313
312
  }
314
313
  getPunctuation(_declarationKind) {
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@graphql-codegen/typescript",
3
- "version": "4.1.6",
3
+ "version": "5.0.0",
4
4
  "description": "GraphQL Code Generator plugin for generating TypeScript types",
5
5
  "peerDependencies": {
6
6
  "graphql": "^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"
7
7
  },
8
8
  "dependencies": {
9
- "@graphql-codegen/plugin-helpers": "^5.1.0",
10
- "@graphql-codegen/schema-ast": "^4.0.2",
11
- "@graphql-codegen/visitor-plugin-common": "5.8.0",
9
+ "@graphql-codegen/plugin-helpers": "^6.0.0",
10
+ "@graphql-codegen/schema-ast": "^5.0.0",
11
+ "@graphql-codegen/visitor-plugin-common": "6.0.0",
12
12
  "auto-bind": "~4.0.0",
13
13
  "tslib": "~2.6.0"
14
14
  },