@@ -12,7 +12,7 @@ type Options<T = TypeNode> = {
12
12
typeName : string ;
13
13
fieldName : string ;
14
14
types : TypeItem [ ] ;
15
- typenamesConvention : NamingConvention ;
15
+ typeNamesConvention : NamingConvention ;
16
16
enumValuesConvention : NamingConvention ;
17
17
terminateCircularRelationships : boolean ;
18
18
prefix : string | undefined ;
@@ -175,7 +175,7 @@ const getNamedType = (opts: Options<NamedTypeNode>): string | number | boolean =
175
175
} ) ;
176
176
if ( ! opts . dynamicValues ) mockValueGenerator . seed ( hashedString ( opts . typeName + opts . fieldName ) ) ;
177
177
const name = opts . currentType . name . value ;
178
- const casedName = createNameConverter ( opts . typenamesConvention , opts . transformUnderscore ) ( name ) ;
178
+ const casedName = createNameConverter ( opts . typeNamesConvention , opts . transformUnderscore ) ( name ) ;
179
179
switch ( name ) {
180
180
case 'String' : {
181
181
const customScalar = opts . customScalars ? getScalarDefinition ( opts . customScalars [ 'String' ] ) : null ;
@@ -204,7 +204,7 @@ const getNamedType = (opts: Options<NamedTypeNode>): string | number | boolean =
204
204
case 'enum' : {
205
205
// It's an enum
206
206
const typenameConverter = createNameConverter (
207
- opts . typenamesConvention ,
207
+ opts . typeNamesConvention ,
208
208
opts . transformUnderscore ,
209
209
) ;
210
210
const enumConverter = createNameConverter ( opts . enumValuesConvention , opts . transformUnderscore ) ;
@@ -279,16 +279,16 @@ const generateMockValue = (opts: Options): string | number | boolean => {
279
279
const getMockString = (
280
280
typeName : string ,
281
281
fields : string ,
282
- typenamesConvention : NamingConvention ,
282
+ typeNamesConvention : NamingConvention ,
283
283
terminateCircularRelationships : boolean ,
284
284
addTypename = false ,
285
285
prefix ,
286
286
typesPrefix = '' ,
287
287
transformUnderscore : boolean ,
288
288
) => {
289
- const typenameConverter = createNameConverter ( typenamesConvention , transformUnderscore ) ;
290
- const casedName = typenameConverter ( typeName ) ;
291
- const casedNameWithPrefix = typenameConverter ( typeName , typesPrefix ) ;
289
+ const typeNameConverter = createNameConverter ( typeNamesConvention , transformUnderscore ) ;
290
+ const casedName = typeNameConverter ( typeName ) ;
291
+ const casedNameWithPrefix = typeNameConverter ( typeName , typesPrefix ) ;
292
292
const typename = addTypename ? `\n __typename: '${ typeName } ',` : '' ;
293
293
const typenameReturnType = addTypename ? `{ __typename: '${ typeName } ' } & ` : '' ;
294
294
@@ -319,23 +319,23 @@ ${fields}
319
319
} ;
320
320
321
321
const getImportTypes = ( {
322
- typenamesConvention ,
322
+ typeNamesConvention ,
323
323
definitions,
324
324
types,
325
325
typesFile,
326
326
typesPrefix,
327
327
enumsPrefix,
328
328
transformUnderscore,
329
329
} : {
330
- typenamesConvention : NamingConvention ;
330
+ typeNamesConvention : NamingConvention ;
331
331
definitions : any ;
332
332
types : TypeItem [ ] ;
333
333
typesFile : string ;
334
334
typesPrefix : string ;
335
335
enumsPrefix : string ;
336
336
transformUnderscore : boolean ;
337
337
} ) => {
338
- const typenameConverter = createNameConverter ( typenamesConvention , transformUnderscore ) ;
338
+ const typenameConverter = createNameConverter ( typeNamesConvention , transformUnderscore ) ;
339
339
const typeImports = typesPrefix ?. endsWith ( '.' )
340
340
? [ typesPrefix . slice ( 0 , - 1 ) ]
341
341
: definitions
@@ -367,7 +367,7 @@ type ScalarMap = {
367
367
export interface TypescriptMocksPluginConfig {
368
368
typesFile ?: string ;
369
369
enumValues ?: NamingConvention ;
370
- typenames ?: NamingConvention ;
370
+ typeNames ?: NamingConvention ;
371
371
addTypename ?: boolean ;
372
372
prefix ?: string ;
373
373
scalars ?: ScalarMap ;
@@ -413,8 +413,12 @@ export const plugin: PluginFunction<TypescriptMocksPluginConfig> = (schema, docu
413
413
const printedSchema = printSchema ( schema ) ; // Returns a string representation of the schema
414
414
const astNode = parse ( printedSchema ) ; // Transforms the string into ASTNode
415
415
416
+ if ( 'typenames' in config ) {
417
+ throw new Error ( 'Config `typenames` was renamed to `typeNames`. Please update your config' ) ;
418
+ }
419
+
416
420
const enumValuesConvention = config . enumValues || 'change-case-all#pascalCase' ;
417
- const typenamesConvention = config . typenames || 'change-case-all#pascalCase' ;
421
+ const typeNamesConvention = config . typeNames || 'change-case-all#pascalCase' ;
418
422
const transformUnderscore = config . transformUnderscore ?? true ;
419
423
const listElementCount = config . listElementCount > 0 ? config . listElementCount : 1 ;
420
424
const dynamicValues = ! ! config . dynamicValues ;
@@ -452,7 +456,7 @@ export const plugin: PluginFunction<TypescriptMocksPluginConfig> = (schema, docu
452
456
typeName,
453
457
fieldName,
454
458
types,
455
- typenamesConvention ,
459
+ typeNamesConvention ,
456
460
enumValuesConvention,
457
461
terminateCircularRelationships : ! ! config . terminateCircularRelationships ,
458
462
prefix : config . prefix ,
@@ -483,7 +487,7 @@ export const plugin: PluginFunction<TypescriptMocksPluginConfig> = (schema, docu
483
487
typeName : fieldName ,
484
488
fieldName : field . name . value ,
485
489
types,
486
- typenamesConvention ,
490
+ typeNamesConvention ,
487
491
enumValuesConvention,
488
492
terminateCircularRelationships : ! ! config . terminateCircularRelationships ,
489
493
prefix : config . prefix ,
@@ -505,7 +509,7 @@ export const plugin: PluginFunction<TypescriptMocksPluginConfig> = (schema, docu
505
509
return getMockString (
506
510
fieldName ,
507
511
mockFields ,
508
- typenamesConvention ,
512
+ typeNamesConvention ,
509
513
! ! config . terminateCircularRelationships ,
510
514
false ,
511
515
config . prefix ,
@@ -528,7 +532,7 @@ export const plugin: PluginFunction<TypescriptMocksPluginConfig> = (schema, docu
528
532
return getMockString (
529
533
typeName ,
530
534
mockFields ,
531
- typenamesConvention ,
535
+ typeNamesConvention ,
532
536
! ! config . terminateCircularRelationships ,
533
537
! ! config . addTypename ,
534
538
config . prefix ,
@@ -549,7 +553,7 @@ export const plugin: PluginFunction<TypescriptMocksPluginConfig> = (schema, docu
549
553
return getMockString (
550
554
typeName ,
551
555
mockFields ,
552
- typenamesConvention ,
556
+ typeNamesConvention ,
553
557
! ! config . terminateCircularRelationships ,
554
558
! ! config . addTypename ,
555
559
config . prefix ,
@@ -575,7 +579,7 @@ export const plugin: PluginFunction<TypescriptMocksPluginConfig> = (schema, docu
575
579
const typesFile = config . typesFile ? config . typesFile . replace ( / \. [ \w ] + $ / , '' ) : null ;
576
580
577
581
const typesFileImport = getImportTypes ( {
578
- typenamesConvention ,
582
+ typeNamesConvention ,
579
583
definitions,
580
584
types,
581
585
typesFile,
0 commit comments