Skip to content

Commit 207665f

Browse files
committed
added typesPrefix to config and tests
1 parent 0476bb5 commit 207665f

File tree

4 files changed

+77
-0
lines changed

4 files changed

+77
-0
lines changed

src/config.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,25 @@ export interface ValidationSchemaPluginConfig extends TypeScriptPluginConfig {
5252
* ```
5353
*/
5454
importFrom?: string;
55+
/**
56+
* @description Prefixes all import types from generated typescript type.
57+
* @default ""
58+
*
59+
* @exampleMarkdown
60+
* ```yml
61+
* generates:
62+
* path/to/types.ts:
63+
* plugins:
64+
* - typescript
65+
* path/to/schemas.ts:
66+
* plugins:
67+
* - graphql-codegen-validation-schema
68+
* config:
69+
* typesPrefix: I
70+
* importFrom: ./path/to/types
71+
* ```
72+
*/
73+
typesPrefix?: string;
5574
/**
5675
* @description Generates validation schema for enum as TypeScript `type`
5776
* @default false

tests/myzod.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,25 @@ describe('myzod', () => {
280280
expect(result.content).toContain(wantContain);
281281
}
282282
});
283+
it('with typesPrefix', async () => {
284+
const schema = buildSchema(/* GraphQL */ `
285+
input Say {
286+
phrase: String!
287+
}
288+
`);
289+
const result = await plugin(
290+
schema,
291+
[],
292+
{
293+
schema: 'myzod',
294+
typesPrefix: 'I',
295+
importFrom: './types',
296+
},
297+
{}
298+
);
299+
expect(result.prepend).toContain("import { ISay } from './types'");
300+
expect(result.content).toContain('export function ISaySchema(): myzod.Type<ISay> {');
301+
});
283302
describe('issues #19', () => {
284303
it('string field', async () => {
285304
const schema = buildSchema(/* GraphQL */ `

tests/yup.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,4 +275,23 @@ describe('yup', () => {
275275
expect(result.content).toContain(wantContain);
276276
}
277277
});
278+
279+
it('with typesPrefix', async () => {
280+
const schema = buildSchema(/* GraphQL */ `
281+
input Say {
282+
phrase: String!
283+
}
284+
`);
285+
const result = await plugin(
286+
schema,
287+
[],
288+
{
289+
typesPrefix: 'I',
290+
importFrom: './types',
291+
},
292+
{}
293+
);
294+
expect(result.prepend).toContain("import { ISay } from './types'");
295+
expect(result.content).toContain('export function ISaySchema(): yup.SchemaOf<ISay> {');
296+
});
278297
});

tests/zod.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,26 @@ describe('zod', () => {
280280
expect(result.content).toContain(wantContain);
281281
}
282282
});
283+
284+
it('with typesPrefix', async () => {
285+
const schema = buildSchema(/* GraphQL */ `
286+
input Say {
287+
phrase: String!
288+
}
289+
`);
290+
const result = await plugin(
291+
schema,
292+
[],
293+
{
294+
schema: 'zod',
295+
typesPrefix: 'I',
296+
importFrom: './types',
297+
},
298+
{}
299+
);
300+
expect(result.prepend).toContain("import { ISay } from './types'");
301+
expect(result.content).toContain('export function ISaySchema(): z.ZodObject<Properties<ISay>> {');
302+
});
283303
describe('issues #19', () => {
284304
it('string field', async () => {
285305
const schema = buildSchema(/* GraphQL */ `

0 commit comments

Comments
 (0)