Skip to content

Commit d7751ef

Browse files
committed
updated example for interface
1 parent 4684976 commit d7751ef

File tree

6 files changed

+34
-5
lines changed

6 files changed

+34
-5
lines changed

codegen.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ generates:
1313
schema: yup
1414
importFrom: ../types
1515
withObjectType: true
16+
withInterfaceType: true
1617
directives:
1718
required:
1819
msg: required
@@ -49,6 +50,7 @@ generates:
4950
schema: zod
5051
importFrom: ../types
5152
withObjectType: true
53+
withInterfaceType: true
5254
directives:
5355
# Write directives like
5456
#
@@ -72,6 +74,7 @@ generates:
7274
schema: myzod
7375
importFrom: ../types
7476
withObjectType: true
77+
withInterfaceType: true
7578
directives:
7679
constraint:
7780
minLength: min

example/myzod/schemas.ts

Lines changed: 7 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, MyType, MyTypeFooArgs, PageInput, PageType, User } from '../types'
2+
import { Admin, AttributeInput, ButtonComponentType, ComponentInput, DropDownComponentInput, EventArgumentInput, EventInput, EventOptionType, Guest, HttpInput, HttpMethod, LayoutInput, MyType, MyTypeFooArgs, Namer, PageInput, PageType, User } from '../types'
33

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

@@ -92,6 +92,12 @@ export function MyTypeFooArgsSchema(): myzod.Type<MyTypeFooArgs> {
9292
})
9393
}
9494

95+
export function NamerSchema(): myzod.Type<Namer> {
96+
return myzod.object({
97+
name: myzod.string().optional().nullable()
98+
})
99+
}
100+
95101
export function PageInputSchema(): myzod.Type<PageInput> {
96102
return myzod.object({
97103
attributes: myzod.array(myzod.lazy(() => AttributeInputSchema())).optional().nullable(),

example/test.graphql

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type Guest {
1515

1616
union UserKind = Admin | Guest
1717

18-
type User {
18+
type User implements Namer {
1919
id: ID
2020
name: String
2121
email: String
@@ -25,6 +25,10 @@ type User {
2525
updatedAt: Date
2626
}
2727

28+
interface Namer {
29+
name: String
30+
}
31+
2832
input PageInput {
2933
id: ID!
3034
title: String!

example/types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ export type MyTypeFooArgs = {
9191
d: Scalars['Float']['input'];
9292
};
9393

94+
export type Namer = {
95+
name?: Maybe<Scalars['String']['output']>;
96+
};
97+
9498
export type PageInput = {
9599
attributes?: InputMaybe<Array<AttributeInput>>;
96100
date?: InputMaybe<Scalars['Date']['input']>;
@@ -112,7 +116,7 @@ export enum PageType {
112116
Service = 'SERVICE'
113117
}
114118

115-
export type User = {
119+
export type User = Namer & {
116120
__typename?: 'User';
117121
createdAt?: Maybe<Scalars['Date']['output']>;
118122
email?: Maybe<Scalars['String']['output']>;

example/yup/schemas.ts

Lines changed: 7 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, MyType, MyTypeFooArgs, PageInput, PageType, User, UserKind } from '../types'
2+
import { Admin, AttributeInput, ButtonComponentType, ComponentInput, DropDownComponentInput, EventArgumentInput, EventInput, EventOptionType, Guest, HttpInput, HttpMethod, LayoutInput, MyType, MyTypeFooArgs, Namer, PageInput, PageType, User, UserKind } from '../types'
33

44
export const ButtonComponentTypeSchema = yup.string<ButtonComponentType>().oneOf(Object.values(ButtonComponentType)).defined();
55

@@ -96,6 +96,12 @@ export function MyTypeFooArgsSchema(): yup.ObjectSchema<MyTypeFooArgs> {
9696
})
9797
}
9898

99+
export function NamerSchema(): yup.ObjectSchema<Namer> {
100+
return yup.object({
101+
name: yup.string().defined().nullable().optional()
102+
})
103+
}
104+
99105
export function PageInputSchema(): yup.ObjectSchema<PageInput> {
100106
return yup.object({
101107
attributes: yup.array(yup.lazy(() => AttributeInputSchema().nonNullable())).defined().nullable().optional(),

example/zod/schemas.ts

Lines changed: 7 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, MyType, MyTypeFooArgs, PageInput, PageType, User } from '../types'
2+
import { Admin, AttributeInput, ButtonComponentType, ComponentInput, DropDownComponentInput, EventArgumentInput, EventInput, EventOptionType, Guest, HttpInput, HttpMethod, LayoutInput, MyType, MyTypeFooArgs, Namer, PageInput, PageType, User } from '../types'
33

44
type Properties<T> = Required<{
55
[K in keyof T]: z.ZodType<T[K], any, T[K]>;
@@ -100,6 +100,12 @@ export function MyTypeFooArgsSchema(): z.ZodObject<Properties<MyTypeFooArgs>> {
100100
})
101101
}
102102

103+
export function NamerSchema(): z.ZodObject<Properties<Namer>> {
104+
return z.object({
105+
name: z.string().nullish()
106+
})
107+
}
108+
103109
export function PageInputSchema(): z.ZodObject<Properties<PageInput>> {
104110
return z.object({
105111
attributes: z.array(z.lazy(() => AttributeInputSchema())).nullish(),

0 commit comments

Comments
 (0)