Skip to content

Commit 55ae41a

Browse files
author
erwan-joly
committed
fix Bugs with yup v1 and arrays of non nullable fix Code-Hex#359
1 parent 0018d0d commit 55ae41a

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

example/test.graphql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ type Guest {
1515

1616
union UserKind = Admin | Guest
1717

18+
type InnerType {
19+
testScalar: MyScalar!
20+
}
21+
22+
type OuterType {
23+
inner: InnerType
24+
}
25+
26+
scalar MyScalar
27+
1828
type User {
1929
id: ID
2030
name: String

src/yup/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@ export const YupSchemaVisitor = (schema: GraphQLSchema, config: ValidationSchema
8080
return new DeclarationBlock({})
8181
.export()
8282
.asKind('function')
83-
.withName(`${name}Schema(): yup.ObjectSchema<${name}>`)
83+
.withName(`${name}Schema()`)
8484
.withBlock(
8585
[
8686
indent(`return yup.object({`),
8787
indent(`__typename: yup.string<'${node.name.value}'>().optional(),`, 2),
8888
shape,
89-
indent('})'),
89+
indent(`}) satisfies yup.ObjectSchema<${name}>`),
9090
].join('\n')
9191
).string;
9292
}),
@@ -210,7 +210,7 @@ const generateFieldTypeYupSchema = (
210210
const tsType = tsVisitor.scalars[type.name.value];
211211
if (tsType === 'string') return `${gen}.required()`;
212212
}
213-
return `${gen}.nonNullable()`;
213+
return `${gen}.defined().nonNullable()`;
214214
}
215215
const typ = schema.getType(type.name.value);
216216
if (typ?.astNode?.kind === 'InputObjectTypeDefinition') {

0 commit comments

Comments
 (0)