Skip to content

Yup schema won't add 'nullable' to optional fields. #64

Closed
@adamwdennis

Description

@adamwdennis

When I run the generator, my Yup schema does not add .nullish() to any optional fields.

my-type.ts

@InputType
export class MyTypeInput {

  @Field(() => String)
  @IsString()
  @IsDefined()
  name!: string;

  @Field(() => ID, { nullable: true })
  @IsString()
  @IsOptional()
  imageId?: string;
}

schema.graphql

input MyTypeInput {
  name: String!
  imageId: ID
}

generated-operations.ts

export type MyTypeInput = {
  imageId?: InputMaybe<Scalars['ID']>;
  name: Scalars['String'];
}

Expected Result

generated-validation-schema.ts

export function MyTypeInputSchema(): yup.SchemaOf<MyTypeInput> {
  return yup.object({
    imageId: yup.string().nullable(),  // <----- this `nullable` is missing in the actual, below
    name: yup.string().defined()
  })
}

Actual Result

generated-validation-schema.ts

export function MyTypeInputSchema(): yup.SchemaOf<MyTypeInput> {
  return yup.object({
    imageId: yup.string(),
    name: yup.string().defined()
  })
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueGood for newcomerspendingPending because of dependence on something

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions