@@ -5,146 +5,171 @@ describe('myzod', () => {
5
5
test . each ( [
6
6
[
7
7
'non-null and defined' ,
8
- /* GraphQL */ `
9
- input PrimitiveInput {
10
- a: ID!
11
- b: String!
12
- c: Boolean!
13
- d: Int!
14
- e: Float!
15
- }
16
- ` ,
17
- [
18
- 'export function PrimitiveInputSchema(): myzod.Type<PrimitiveInput> {' ,
19
- 'a: myzod.string()' ,
20
- 'b: myzod.string()' ,
21
- 'c: myzod.boolean()' ,
22
- 'd: myzod.number()' ,
23
- 'e: myzod.number()' ,
24
- ] ,
8
+ {
9
+ textSchema : /* GraphQL */ `
10
+ input PrimitiveInput {
11
+ a: ID!
12
+ b: String!
13
+ c: Boolean!
14
+ d: Int!
15
+ e: Float!
16
+ }
17
+ ` ,
18
+ wantContains : [
19
+ 'export function PrimitiveInputSchema(): myzod.Type<PrimitiveInput> {' ,
20
+ 'a: myzod.string()' ,
21
+ 'b: myzod.string()' ,
22
+ 'c: myzod.boolean()' ,
23
+ 'd: myzod.number()' ,
24
+ 'e: myzod.number()' ,
25
+ ] ,
26
+ scalars : {
27
+ ID : 'string' ,
28
+ } ,
29
+ } ,
25
30
] ,
26
31
[
27
32
'nullish' ,
28
- /* GraphQL */ `
29
- input PrimitiveInput {
30
- a: ID
31
- b: String
32
- c: Boolean
33
- d: Int
34
- e: Float
35
- z: String! # no defined check
36
- }
37
- ` ,
38
- [
39
- 'export function PrimitiveInputSchema(): myzod.Type<PrimitiveInput> {' ,
40
- // alphabet order
41
- 'a: myzod.string().optional().nullable(),' ,
42
- 'b: myzod.string().optional().nullable(),' ,
43
- 'c: myzod.boolean().optional().nullable(),' ,
44
- 'd: myzod.number().optional().nullable(),' ,
45
- 'e: myzod.number().optional().nullable(),' ,
46
- ] ,
33
+ {
34
+ textSchema : /* GraphQL */ `
35
+ input PrimitiveInput {
36
+ a: ID
37
+ b: String
38
+ c: Boolean
39
+ d: Int
40
+ e: Float
41
+ z: String! # no defined check
42
+ }
43
+ ` ,
44
+ wantContains : [
45
+ 'export function PrimitiveInputSchema(): myzod.Type<PrimitiveInput> {' ,
46
+ // alphabet order
47
+ 'a: myzod.string().optional().nullable(),' ,
48
+ 'b: myzod.string().optional().nullable(),' ,
49
+ 'c: myzod.boolean().optional().nullable(),' ,
50
+ 'd: myzod.number().optional().nullable(),' ,
51
+ 'e: myzod.number().optional().nullable(),' ,
52
+ ] ,
53
+ scalars : {
54
+ ID : 'string' ,
55
+ } ,
56
+ } ,
47
57
] ,
48
58
[
49
59
'array' ,
50
- /* GraphQL */ `
51
- input ArrayInput {
52
- a: [String]
53
- b: [String!]
54
- c: [String!]!
55
- d: [[String]]
56
- e: [[String]!]
57
- f: [[String]!]!
58
- }
59
- ` ,
60
- [
61
- 'export function ArrayInputSchema(): myzod.Type<ArrayInput> {' ,
62
- 'a: myzod.array(myzod.string().nullable()).optional().nullable(),' ,
63
- 'b: myzod.array(myzod.string()).optional().nullable(),' ,
64
- 'c: myzod.array(myzod.string()),' ,
65
- 'd: myzod.array(myzod.array(myzod.string().nullable()).optional().nullable()).optional().nullable(),' ,
66
- 'e: myzod.array(myzod.array(myzod.string().nullable())).optional().nullable(),' ,
67
- 'f: myzod.array(myzod.array(myzod.string().nullable()))' ,
68
- ] ,
60
+ {
61
+ textSchema : /* GraphQL */ `
62
+ input ArrayInput {
63
+ a: [String]
64
+ b: [String!]
65
+ c: [String!]!
66
+ d: [[String]]
67
+ e: [[String]!]
68
+ f: [[String]!]!
69
+ }
70
+ ` ,
71
+ wantContains : [
72
+ 'export function ArrayInputSchema(): myzod.Type<ArrayInput> {' ,
73
+ 'a: myzod.array(myzod.string().nullable()).optional().nullable(),' ,
74
+ 'b: myzod.array(myzod.string()).optional().nullable(),' ,
75
+ 'c: myzod.array(myzod.string()),' ,
76
+ 'd: myzod.array(myzod.array(myzod.string().nullable()).optional().nullable()).optional().nullable(),' ,
77
+ 'e: myzod.array(myzod.array(myzod.string().nullable())).optional().nullable(),' ,
78
+ 'f: myzod.array(myzod.array(myzod.string().nullable()))' ,
79
+ ] ,
80
+ scalars : undefined ,
81
+ } ,
69
82
] ,
70
83
[
71
84
'ref input object' ,
72
- /* GraphQL */ `
73
- input AInput {
74
- b: BInput!
75
- }
76
- input BInput {
77
- c: CInput!
78
- }
79
- input CInput {
80
- a: AInput!
81
- }
82
- ` ,
83
- [
84
- 'export function AInputSchema(): myzod.Type<AInput> {' ,
85
- 'b: myzod.lazy(() => BInputSchema())' ,
86
- 'export function BInputSchema(): myzod.Type<BInput> {' ,
87
- 'c: myzod.lazy(() => CInputSchema())' ,
88
- 'export function CInputSchema(): myzod.Type<CInput> {' ,
89
- 'a: myzod.lazy(() => AInputSchema())' ,
90
- ] ,
85
+ {
86
+ textSchema : /* GraphQL */ `
87
+ input AInput {
88
+ b: BInput!
89
+ }
90
+ input BInput {
91
+ c: CInput!
92
+ }
93
+ input CInput {
94
+ a: AInput!
95
+ }
96
+ ` ,
97
+ wantContains : [
98
+ 'export function AInputSchema(): myzod.Type<AInput> {' ,
99
+ 'b: myzod.lazy(() => BInputSchema())' ,
100
+ 'export function BInputSchema(): myzod.Type<BInput> {' ,
101
+ 'c: myzod.lazy(() => CInputSchema())' ,
102
+ 'export function CInputSchema(): myzod.Type<CInput> {' ,
103
+ 'a: myzod.lazy(() => AInputSchema())' ,
104
+ ] ,
105
+ scalars : undefined ,
106
+ } ,
91
107
] ,
92
108
[
93
109
'nested input object' ,
94
- /* GraphQL */ `
95
- input NestedInput {
96
- child: NestedInput
97
- childrens: [NestedInput]
98
- }
99
- ` ,
100
- [
101
- 'export function NestedInputSchema(): myzod.Type<NestedInput> {' ,
102
- 'child: myzod.lazy(() => NestedInputSchema().optional().nullable()),' ,
103
- 'childrens: myzod.array(myzod.lazy(() => NestedInputSchema().nullable())).optional().nullable()' ,
104
- ] ,
110
+ {
111
+ textSchema : /* GraphQL */ `
112
+ input NestedInput {
113
+ child: NestedInput
114
+ childrens: [NestedInput]
115
+ }
116
+ ` ,
117
+ wantContains : [
118
+ 'export function NestedInputSchema(): myzod.Type<NestedInput> {' ,
119
+ 'child: myzod.lazy(() => NestedInputSchema().optional().nullable()),' ,
120
+ 'childrens: myzod.array(myzod.lazy(() => NestedInputSchema().nullable())).optional().nullable()' ,
121
+ ] ,
122
+ scalars : undefined ,
123
+ } ,
105
124
] ,
106
125
[
107
126
'enum' ,
108
- /* GraphQL */ `
109
- enum PageType {
110
- PUBLIC
111
- BASIC_AUTH
112
- }
113
- input PageInput {
114
- pageType: PageType!
115
- }
116
- ` ,
117
- [
118
- 'export const PageTypeSchema = myzod.enum(PageType)' ,
119
- 'export function PageInputSchema(): myzod.Type<PageInput> {' ,
120
- 'pageType: PageTypeSchema' ,
121
- ] ,
127
+ {
128
+ textSchema : /* GraphQL */ `
129
+ enum PageType {
130
+ PUBLIC
131
+ BASIC_AUTH
132
+ }
133
+ input PageInput {
134
+ pageType: PageType!
135
+ }
136
+ ` ,
137
+ wantContains : [
138
+ 'export const PageTypeSchema = myzod.enum(PageType)' ,
139
+ 'export function PageInputSchema(): myzod.Type<PageInput> {' ,
140
+ 'pageType: PageTypeSchema' ,
141
+ ] ,
142
+ scalars : undefined ,
143
+ } ,
122
144
] ,
123
145
[
124
146
'camelcase' ,
125
- /* GraphQL */ `
126
- input HTTPInput {
127
- method: HTTPMethod
128
- url: URL!
129
- }
130
-
131
- enum HTTPMethod {
132
- GET
133
- POST
134
- }
135
-
136
- scalar URL # unknown scalar, should be any (definedNonNullAnySchema)
137
- ` ,
138
- [
139
- 'export function HttpInputSchema(): myzod.Type<HttpInput> {' ,
140
- 'export const HttpMethodSchema = myzod.enum(HttpMethod)' ,
141
- 'method: HttpMethodSchema' ,
142
- 'url: definedNonNullAnySchema' ,
143
- ] ,
147
+ {
148
+ textSchema : /* GraphQL */ `
149
+ input HTTPInput {
150
+ method: HTTPMethod
151
+ url: URL!
152
+ }
153
+
154
+ enum HTTPMethod {
155
+ GET
156
+ POST
157
+ }
158
+
159
+ scalar URL # unknown scalar, should be any (definedNonNullAnySchema)
160
+ ` ,
161
+ wantContains : [
162
+ 'export function HttpInputSchema(): myzod.Type<HttpInput> {' ,
163
+ 'export const HttpMethodSchema = myzod.enum(HttpMethod)' ,
164
+ 'method: HttpMethodSchema' ,
165
+ 'url: definedNonNullAnySchema' ,
166
+ ] ,
167
+ scalars : undefined ,
168
+ } ,
144
169
] ,
145
- ] ) ( '%s' , async ( _ , textSchema , wantContains ) => {
170
+ ] ) ( '%s' , async ( _ , { textSchema, wantContains, scalars } ) => {
146
171
const schema = buildSchema ( textSchema ) ;
147
- const result = await plugin ( schema , [ ] , { schema : 'myzod' } , { } ) ;
172
+ const result = await plugin ( schema , [ ] , { schema : 'myzod' , scalars } , { } ) ;
148
173
expect ( result . prepend ) . toContain ( "import * as myzod from 'myzod'" ) ;
149
174
150
175
for ( const wantContain of wantContains ) {
@@ -232,6 +257,9 @@ describe('myzod', () => {
232
257
{
233
258
schema : 'myzod' ,
234
259
notAllowEmptyString : true ,
260
+ scalars : {
261
+ ID : 'string' ,
262
+ } ,
235
263
} ,
236
264
{ }
237
265
) ;
0 commit comments