File tree Expand file tree Collapse file tree 4 files changed +77
-0
lines changed Expand file tree Collapse file tree 4 files changed +77
-0
lines changed Original file line number Diff line number Diff line change @@ -71,6 +71,25 @@ export interface ValidationSchemaPluginConfig extends TypeScriptPluginConfig {
71
71
* ```
72
72
*/
73
73
typesPrefix ?: string ;
74
+ /**
75
+ * @description Suffixes all import types from generated typescript type.
76
+ * @default ""
77
+ *
78
+ * @exampleMarkdown
79
+ * ```yml
80
+ * generates:
81
+ * path/to/types.ts:
82
+ * plugins:
83
+ * - typescript
84
+ * path/to/schemas.ts:
85
+ * plugins:
86
+ * - graphql-codegen-validation-schema
87
+ * config:
88
+ * typesSuffix: I
89
+ * importFrom: ./path/to/types
90
+ * ```
91
+ */
92
+ typesSuffix ?: string ;
74
93
/**
75
94
* @description Generates validation schema for enum as TypeScript `type`
76
95
* @default false
Original file line number Diff line number Diff line change @@ -299,6 +299,25 @@ describe('myzod', () => {
299
299
expect ( result . prepend ) . toContain ( "import { ISay } from './types'" ) ;
300
300
expect ( result . content ) . toContain ( 'export function ISaySchema(): myzod.Type<ISay> {' ) ;
301
301
} ) ;
302
+ it ( 'with typesSuffix' , async ( ) => {
303
+ const schema = buildSchema ( /* GraphQL */ `
304
+ input Say {
305
+ phrase: String!
306
+ }
307
+ ` ) ;
308
+ const result = await plugin (
309
+ schema ,
310
+ [ ] ,
311
+ {
312
+ schema : 'myzod' ,
313
+ typesSuffix : 'I' ,
314
+ importFrom : './types' ,
315
+ } ,
316
+ { }
317
+ ) ;
318
+ expect ( result . prepend ) . toContain ( "import { SayI } from './types'" ) ;
319
+ expect ( result . content ) . toContain ( 'export function SayISchema(): myzod.Type<SayI> {' ) ;
320
+ } ) ;
302
321
describe ( 'issues #19' , ( ) => {
303
322
it ( 'string field' , async ( ) => {
304
323
const schema = buildSchema ( /* GraphQL */ `
Original file line number Diff line number Diff line change @@ -294,4 +294,23 @@ describe('yup', () => {
294
294
expect ( result . prepend ) . toContain ( "import { ISay } from './types'" ) ;
295
295
expect ( result . content ) . toContain ( 'export function ISaySchema(): yup.SchemaOf<ISay> {' ) ;
296
296
} ) ;
297
+
298
+ it ( 'with typesSuffix' , async ( ) => {
299
+ const schema = buildSchema ( /* GraphQL */ `
300
+ input Say {
301
+ phrase: String!
302
+ }
303
+ ` ) ;
304
+ const result = await plugin (
305
+ schema ,
306
+ [ ] ,
307
+ {
308
+ typesSuffix : 'I' ,
309
+ importFrom : './types' ,
310
+ } ,
311
+ { }
312
+ ) ;
313
+ expect ( result . prepend ) . toContain ( "import { SayI } from './types'" ) ;
314
+ expect ( result . content ) . toContain ( 'export function SayISchema(): yup.SchemaOf<SayI> {' ) ;
315
+ } ) ;
297
316
} ) ;
Original file line number Diff line number Diff line change @@ -300,6 +300,26 @@ describe('zod', () => {
300
300
expect ( result . prepend ) . toContain ( "import { ISay } from './types'" ) ;
301
301
expect ( result . content ) . toContain ( 'export function ISaySchema(): z.ZodObject<Properties<ISay>> {' ) ;
302
302
} ) ;
303
+
304
+ it ( 'with typesSuffix' , async ( ) => {
305
+ const schema = buildSchema ( /* GraphQL */ `
306
+ input Say {
307
+ phrase: String!
308
+ }
309
+ ` ) ;
310
+ const result = await plugin (
311
+ schema ,
312
+ [ ] ,
313
+ {
314
+ schema : 'zod' ,
315
+ typesSuffix : 'I' ,
316
+ importFrom : './types' ,
317
+ } ,
318
+ { }
319
+ ) ;
320
+ expect ( result . prepend ) . toContain ( "import { SayI } from './types'" ) ;
321
+ expect ( result . content ) . toContain ( 'export function SayISchema(): z.ZodObject<Properties<SayI>> {' ) ;
322
+ } ) ;
303
323
describe ( 'issues #19' , ( ) => {
304
324
it ( 'string field' , async ( ) => {
305
325
const schema = buildSchema ( /* GraphQL */ `
You can’t perform that action at this time.
0 commit comments