MCPcopy
hub / github.com/redwoodjs/graphql / validate

Function validate

packages/api/src/validations/validations.ts:588–610  ·  view source on GitHub ↗
(
  value: unknown,
  labelOrRecipe: string | ValidationWithMessagesRecipe,
  recipe?: ValidationRecipe,
)

Source from the content-addressed store, hash-verified

586 recipe: ValidationRecipe,
587): void
588export function validate(
589 value: unknown,
590 labelOrRecipe: string | ValidationWithMessagesRecipe,
591 recipe?: ValidationRecipe,
592): void {
593 let label, validationRecipe
594
595 if (typeof labelOrRecipe === 'object') {
596 label = ''
597 validationRecipe = labelOrRecipe
598 } else {
599 label = labelOrRecipe
600 validationRecipe = recipe as ValidationRecipe
601 }
602
603 for (const [validator, options] of Object.entries(validationRecipe)) {
604 if (typeof options === 'undefined') {
605 continue
606 }
607
608 VALIDATORS[validator as keyof typeof VALIDATORS](value, label, options)
609 }
610}
611
612// Run a custom validation function which should either throw or return nothing.
613// Why not just write your own function? Because GraphQL will swallow it and

Callers 1

Calls 1

entriesMethod · 0.80

Tested by

no test coverage detected