Skip to content

Commit ff8dc02

Browse files
committed
fixed example and tests
1 parent 66388e8 commit ff8dc02

File tree

8 files changed

+20
-14
lines changed

8 files changed

+20
-14
lines changed

example/myzod/schemas.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,13 @@ export function UserSchema(): myzod.Type<User> {
9898
createdAt: definedNonNullAnySchema.optional().nullable(),
9999
email: myzod.string().optional().nullable(),
100100
id: myzod.string().optional().nullable(),
101-
kind: UserKindSchema.optional().nullable(),
101+
kind: UserKindSchema().optional().nullable(),
102102
name: myzod.string().optional().nullable(),
103103
password: myzod.string().optional().nullable(),
104104
updatedAt: definedNonNullAnySchema.optional().nullable()
105105
})
106106
}
107107

108-
export const UserKindSchema = myzod.union([AdminSchema(), GuestSchema()]);
108+
export function UserKindSchema() {
109+
return AdminSchema()
110+
}

example/test.graphql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type Guest {
1313
lastLoggedIn: Date
1414
}
1515

16-
union UserKind = Admin | Guest
16+
union UserKind = Admin
1717

1818
type User {
1919
id: ID

example/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,4 @@ export type User = {
108108
updatedAt?: Maybe<Scalars['Date']>;
109109
};
110110

111-
export type UserKind = Admin | Guest;
111+
export type UserKind = Admin;

example/yup/schemas.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,13 @@ export function UserSchema(): yup.SchemaOf<User> {
102102
createdAt: yup.mixed(),
103103
email: yup.string(),
104104
id: yup.string(),
105-
kind: UserKindSchema,
105+
kind: UserKindSchema(),
106106
name: yup.string(),
107107
password: yup.string(),
108108
updatedAt: yup.mixed()
109109
})
110110
}
111111

112-
export const UserKindSchema: yup.BaseSchema<UserKind> = union<UserKind>(AdminSchema(), GuestSchema());
112+
export function UserKindSchema(): yup.BaseSchema<UserKind> {
113+
return union<UserKind>(AdminSchema())
114+
}

example/zod/schemas.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,13 @@ export function UserSchema(): z.ZodObject<Properties<User>> {
106106
createdAt: definedNonNullAnySchema.nullish(),
107107
email: z.string().nullish(),
108108
id: z.string().nullish(),
109-
kind: UserKindSchema.nullish(),
109+
kind: UserKindSchema().nullish(),
110110
name: z.string().nullish(),
111111
password: z.string().nullish(),
112112
updatedAt: definedNonNullAnySchema.nullish()
113113
})
114114
}
115115

116-
export const UserKindSchema = z.union([AdminSchema(), GuestSchema()]);
116+
export function UserKindSchema() {
117+
return AdminSchema()
118+
}

tests/myzod.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ describe('myzod', () => {
563563
const wantContains = [
564564
// Shape Schema
565565
'export function ShapeSchema() {',
566-
'myzod.union([CircleSchema(), SquareSchema()])',
566+
'return myzod.union([CircleSchema(), SquareSchema()])',
567567
'}',
568568
];
569569
for (const wantContain of wantContains) {
@@ -629,7 +629,7 @@ describe('myzod', () => {
629629
const wantContains = [
630630
// Shape Schema
631631
'export function ShapeSchema() {',
632-
'CircleSchema()',
632+
'return CircleSchema()',
633633
'}',
634634
];
635635
for (const wantContain of wantContains) {

tests/yup.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ describe('yup', () => {
513513
'export function GeometrySchema(): yup.SchemaOf<Geometry> {',
514514
'return yup.object({',
515515
"__typename: yup.mixed().oneOf(['Geometry', undefined]),",
516-
'shape: yup.mixed()',
516+
'shape: ShapeSchema()',
517517
'})',
518518
];
519519
for (const wantContain of wantContains) {
@@ -542,7 +542,7 @@ describe('yup', () => {
542542
const wantContains = [
543543
// Shape Schema
544544
'export function ShapeSchema(): yup.BaseSchema<Shape> {',
545-
'CircleSchema()',
545+
'return union<Shape>(CircleSchema())',
546546
'}',
547547
];
548548
for (const wantContain of wantContains) {

tests/zod.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ describe('zod', () => {
661661
const wantContains = [
662662
// Shape Schema
663663
'export function ShapeSchema() {',
664-
'z.union([CircleSchema(), SquareSchema()])',
664+
'return z.union([CircleSchema(), SquareSchema()])',
665665
'}',
666666
];
667667
for (const wantContain of wantContains) {
@@ -725,7 +725,7 @@ describe('zod', () => {
725725
const wantContains = [
726726
// Shape Schema
727727
'export function ShapeSchema() {',
728-
'CircleSchema()',
728+
'return CircleSchema()',
729729
'}',
730730
];
731731
for (const wantContain of wantContains) {

0 commit comments

Comments
 (0)