Skip to content

Commit

Permalink
fix Bugs with yup v1 and arrays of non nullable fix Code-Hex#359
Browse files Browse the repository at this point in the history
  • Loading branch information
erwan-joly committed Jun 8, 2023
1 parent 0018d0d commit 55ae41a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
10 changes: 10 additions & 0 deletions example/test.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ type Guest {

union UserKind = Admin | Guest

type InnerType {
testScalar: MyScalar!
}

type OuterType {
inner: InnerType
}

scalar MyScalar

type User {
id: ID
name: String
Expand Down
6 changes: 3 additions & 3 deletions src/yup/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ export const YupSchemaVisitor = (schema: GraphQLSchema, config: ValidationSchema
return new DeclarationBlock({})
.export()
.asKind('function')
.withName(`${name}Schema(): yup.ObjectSchema<${name}>`)
.withName(`${name}Schema()`)
.withBlock(
[
indent(`return yup.object({`),
indent(`__typename: yup.string<'${node.name.value}'>().optional(),`, 2),
shape,
indent('})'),
indent(`}) satisfies yup.ObjectSchema<${name}>`),
].join('\n')
).string;
}),
Expand Down Expand Up @@ -210,7 +210,7 @@ const generateFieldTypeYupSchema = (
const tsType = tsVisitor.scalars[type.name.value];
if (tsType === 'string') return `${gen}.required()`;
}
return `${gen}.nonNullable()`;
return `${gen}.defined().nonNullable()`;
}
const typ = schema.getType(type.name.value);
if (typ?.astNode?.kind === 'InputObjectTypeDefinition') {
Expand Down

0 comments on commit 55ae41a

Please sign in to comment.