Code-Hex/graphql-codegen-typescript-validation-schema

`.defined()` on input fields that has default value in schema

moander opened this issue · 2 comments

Version: 0.12.0

The following query is accepted by the server, but .validate() fail with displayName must be defined.

The expected behavior is to allow the undefined value and let the server take care of the default as defined in the SDL.

mutation {
  createLocation(input: {
    model: {
      description: ""
    }
  }) { id }
}
input LocationCreateInput {
  description: String
  displayName: String! = ""
}
yup.object({
  description: yup.string().trim().defined().nullable().optional(), 
  displayName: yup.string().trim().defined().nonNullable(), // ERROR: displayName must be defined
})

@moander I'm sorry, this library hasn't been supported yet for default values.
See: #449

Thank you @Code-Hex. This generator is really cool btw!

My workaround for now is to use .deepPartial() on the schema to get rid of .defined() validation errors.