Skip to content

Commit 6ae565e

Browse files
committed
added example for variables
1 parent 3b531d0 commit 6ae565e

File tree

5 files changed

+68
-3
lines changed

5 files changed

+68
-3
lines changed

example/myzod/schemas.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as myzod from 'myzod'
2-
import { Admin, AttributeInput, ButtonComponentType, ComponentInput, DropDownComponentInput, EventArgumentInput, EventInput, EventOptionType, Guest, HttpInput, HttpMethod, LayoutInput, PageInput, PageType, User } from '../types'
2+
import { Admin, AttributeInput, ButtonComponentType, ComponentInput, DropDownComponentInput, EventArgumentInput, EventInput, EventOptionType, Guest, HttpInput, HttpMethod, LayoutInput, MyType, MyTypeFooArgs, PageInput, PageType, User } from '../types'
33

44
export const definedNonNullAnySchema = myzod.object({});
55

@@ -76,6 +76,22 @@ export function LayoutInputSchema(): myzod.Type<LayoutInput> {
7676
})
7777
}
7878

79+
export function MyTypeSchema(): myzod.Type<MyType> {
80+
return myzod.object({
81+
__typename: myzod.literal('MyType').optional(),
82+
foo: myzod.string().optional().nullable()
83+
})
84+
}
85+
86+
export function MyTypeFooArgsSchema(): myzod.Type<MyTypeFooArgs> {
87+
return myzod.object({
88+
a: myzod.string().optional().nullable(),
89+
b: myzod.number(),
90+
c: myzod.boolean().optional().nullable(),
91+
d: myzod.number()
92+
})
93+
}
94+
7995
export function PageInputSchema(): myzod.Type<PageInput> {
8096
return myzod.object({
8197
attributes: myzod.array(myzod.lazy(() => AttributeInputSchema())).optional().nullable(),

example/test.graphql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ enum HTTPMethod {
9494
scalar Date
9595
scalar URL
9696

97+
type MyType {
98+
foo(a: String, b: Int!, c: Boolean, d: Float!): String
99+
}
100+
97101
# https://github.com/confuser/graphql-constraint-directive
98102
directive @constraint(
99103
# String constraints

example/types.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,19 @@ export type LayoutInput = {
7878
dropdown?: InputMaybe<DropDownComponentInput>;
7979
};
8080

81+
export type MyType = {
82+
__typename?: 'MyType';
83+
foo?: Maybe<Scalars['String']['output']>;
84+
};
85+
86+
87+
export type MyTypeFooArgs = {
88+
a?: InputMaybe<Scalars['String']['input']>;
89+
b: Scalars['Int']['input'];
90+
c?: InputMaybe<Scalars['Boolean']['input']>;
91+
d: Scalars['Float']['input'];
92+
};
93+
8194
export type PageInput = {
8295
attributes?: InputMaybe<Array<AttributeInput>>;
8396
date?: InputMaybe<Scalars['Date']['input']>;

example/yup/schemas.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as yup from 'yup'
2-
import { Admin, AttributeInput, ButtonComponentType, ComponentInput, DropDownComponentInput, EventArgumentInput, EventInput, EventOptionType, Guest, HttpInput, HttpMethod, LayoutInput, PageInput, PageType, User, UserKind } from '../types'
2+
import { Admin, AttributeInput, ButtonComponentType, ComponentInput, DropDownComponentInput, EventArgumentInput, EventInput, EventOptionType, Guest, HttpInput, HttpMethod, LayoutInput, MyType, MyTypeFooArgs, PageInput, PageType, User, UserKind } from '../types'
33

44
export const ButtonComponentTypeSchema = yup.string<ButtonComponentType>().oneOf([ButtonComponentType.Button, ButtonComponentType.Submit]).defined();
55

@@ -80,6 +80,22 @@ export function LayoutInputSchema(): yup.ObjectSchema<LayoutInput> {
8080
})
8181
}
8282

83+
export function MyTypeSchema(): yup.ObjectSchema<MyType> {
84+
return yup.object({
85+
__typename: yup.string<'MyType'>().optional(),
86+
foo: yup.string().defined().nullable().optional()
87+
})
88+
}
89+
90+
export function MyTypeFooArgsSchema(): yup.ObjectSchema<MyTypeFooArgs> {
91+
return yup.object({
92+
a: yup.string().defined().nullable(),
93+
b: yup.number().defined().nonNullable(),
94+
c: yup.boolean().defined().nullable(),
95+
d: yup.number().defined().nonNullable()
96+
})
97+
}
98+
8399
export function PageInputSchema(): yup.ObjectSchema<PageInput> {
84100
return yup.object({
85101
attributes: yup.array(yup.lazy(() => AttributeInputSchema().nonNullable())).defined().nullable().optional(),

example/zod/schemas.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { z } from 'zod'
2-
import { Admin, AttributeInput, ButtonComponentType, ComponentInput, DropDownComponentInput, EventArgumentInput, EventInput, EventOptionType, Guest, HttpInput, HttpMethod, LayoutInput, PageInput, PageType, User } from '../types'
2+
import { Admin, AttributeInput, ButtonComponentType, ComponentInput, DropDownComponentInput, EventArgumentInput, EventInput, EventOptionType, Guest, HttpInput, HttpMethod, LayoutInput, MyType, MyTypeFooArgs, PageInput, PageType, User } from '../types'
33

44
type Properties<T> = Required<{
55
[K in keyof T]: z.ZodType<T[K], any, T[K]>;
@@ -84,6 +84,22 @@ export function LayoutInputSchema(): z.ZodObject<Properties<LayoutInput>> {
8484
})
8585
}
8686

87+
export function MyTypeSchema(): z.ZodObject<Properties<MyType>> {
88+
return z.object({
89+
__typename: z.literal('MyType').optional(),
90+
foo: z.string().nullish()
91+
})
92+
}
93+
94+
export function MyTypeFooArgsSchema(): z.ZodObject<Properties<MyTypeFooArgs>> {
95+
return z.object({
96+
a: z.string().nullish(),
97+
b: z.number(),
98+
c: z.boolean().nullish(),
99+
d: z.number()
100+
})
101+
}
102+
87103
export function PageInputSchema(): z.ZodObject<Properties<PageInput>> {
88104
return z.object({
89105
attributes: z.array(z.lazy(() => AttributeInputSchema())).nullish(),

0 commit comments

Comments
 (0)