Skip to content

Commit 35ea682

Browse files
committed
added generated example code for myzod
1 parent 5dd2d62 commit 35ea682

File tree

3 files changed

+86
-8
lines changed

3 files changed

+86
-8
lines changed

codegen.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,6 @@ generates:
6363
schema: myzod
6464
importFrom: ../types
6565
directives:
66-
# Write directives like
67-
#
68-
# directive:
69-
# arg1: schemaApi
70-
# arg2: ["schemaApi2", "Hello $1"]
71-
#
72-
# See more examples in `./tests/directive.spec.ts`
73-
# https://github.com/Code-Hex/graphql-codegen-typescript-validation-schema/blob/main/tests/directive.spec.ts
7466
constraint:
7567
minLength: min
7668
# Replace $1 with specified `startsWith` argument value of the constraint directive

example/myzod/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Tips for myzod schema
2+
3+
## How to overwrite generated schema?
4+
5+
Basically, I think [it does not support overwrite schema](https://github.com/davidmdm/myzod/issues/51) in myzod. However, [`and`](https://github.com/davidmdm/myzod#typeand) and [`or`](https://github.com/davidmdm/myzod#typeor) may helps you.
6+
7+
See also: https://github.com/Code-Hex/graphql-codegen-typescript-validation-schema/issues/25#issuecomment-1086532098

example/myzod/schemas.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import * as myzod from 'myzod'
2+
import { AttributeInput, ButtonComponentType, ComponentInput, DropDownComponentInput, EventArgumentInput, EventInput, EventOptionType, HttpInput, HttpMethod, LayoutInput, PageInput, PageType } from '../types'
3+
4+
export const definedNonNullAnySchema = myzod.object({});
5+
6+
export function AttributeInputSchema(): myzod.Type<AttributeInput> {
7+
return myzod.object({
8+
key: myzod.string().optional().nullable(),
9+
val: myzod.string().optional().nullable()
10+
})
11+
}
12+
13+
export const ButtonComponentTypeSchema = myzod.enum(ButtonComponentType);
14+
15+
export function ComponentInputSchema(): myzod.Type<ComponentInput> {
16+
return myzod.object({
17+
child: myzod.lazy(() => ComponentInputSchema().optional().nullable()),
18+
childrens: myzod.array(myzod.lazy(() => ComponentInputSchema().nullable())).optional().nullable(),
19+
event: myzod.lazy(() => EventInputSchema().optional().nullable()),
20+
name: myzod.string(),
21+
type: ButtonComponentTypeSchema
22+
})
23+
}
24+
25+
export function DropDownComponentInputSchema(): myzod.Type<DropDownComponentInput> {
26+
return myzod.object({
27+
dropdownComponent: myzod.lazy(() => ComponentInputSchema().optional().nullable()),
28+
getEvent: myzod.lazy(() => EventInputSchema())
29+
})
30+
}
31+
32+
export function EventArgumentInputSchema(): myzod.Type<EventArgumentInput> {
33+
return myzod.object({
34+
name: myzod.string().min(5),
35+
value: myzod.string().pattern(/^foo/)
36+
})
37+
}
38+
39+
export function EventInputSchema(): myzod.Type<EventInput> {
40+
return myzod.object({
41+
arguments: myzod.array(myzod.lazy(() => EventArgumentInputSchema())),
42+
options: myzod.array(EventOptionTypeSchema).optional().nullable()
43+
})
44+
}
45+
46+
export const EventOptionTypeSchema = myzod.enum(EventOptionType);
47+
48+
export function HttpInputSchema(): myzod.Type<HttpInput> {
49+
return myzod.object({
50+
method: HttpMethodSchema.optional().nullable(),
51+
url: definedNonNullAnySchema
52+
})
53+
}
54+
55+
export const HttpMethodSchema = myzod.enum(HttpMethod);
56+
57+
export function LayoutInputSchema(): myzod.Type<LayoutInput> {
58+
return myzod.object({
59+
dropdown: myzod.lazy(() => DropDownComponentInputSchema().optional().nullable())
60+
})
61+
}
62+
63+
export function PageInputSchema(): myzod.Type<PageInput> {
64+
return myzod.object({
65+
attributes: myzod.array(myzod.lazy(() => AttributeInputSchema())).optional().nullable(),
66+
date: definedNonNullAnySchema.optional().nullable(),
67+
height: myzod.number(),
68+
id: myzod.string(),
69+
layout: myzod.lazy(() => LayoutInputSchema()),
70+
pageType: PageTypeSchema,
71+
postIDs: myzod.array(myzod.string()).optional().nullable(),
72+
show: myzod.boolean(),
73+
tags: myzod.array(myzod.string().nullable()).optional().nullable(),
74+
title: myzod.string(),
75+
width: myzod.number()
76+
})
77+
}
78+
79+
export const PageTypeSchema = myzod.enum(PageType);

0 commit comments

Comments
 (0)