Replies: 2 comments 7 replies
-
|
Yes, I am generally open to expand that. What exactly do |
Beta Was this translation helpful? Give feedback.
-
I think the pipeline is the right place for As with decorators, Use decorators:import { Length, MaxLength } from 'class-validator'
import { Field, InputType } from 'type-graphql'
import { type Recipe } from './recipe.type'
@InputType()
export class RecipeInput implements Partial<Recipe> {
@Field()
@MaxLength(30)
title!: string
@Field({ nullable: true })
@Length(30, 255)
description?: string
}Use valibot:import * as v from 'valibot'
import { field, inputType } from './valibot-type-graphql'
export const RecipeInput = v.object(
{
title: v.string([field(), v.maxLength(30)]),
description: v.string([field(), v.length(30, 255)]),
},
[inputType()]
)In fact, Use decorators:import { Field, ID, ObjectType } from 'type-graphql'
import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from 'typeorm'
import { Recipe } from './recipe'
@ObjectType()
@Entity()
export class User {
@Field((_type) => ID)
@PrimaryGeneratedColumn()
readonly id!: number
@Field()
@Column()
email!: string
@Field({ nullable: true })
@Column({ nullable: true })
nickname?: string
@Column()
password!: string
@OneToMany((_type) => Recipe, (recipe) => recipe.author, { lazy: true })
@Field((_type) => [Recipe])
recipes!: Recipe[] | Promise<Recipe[]>
}Use valibot:import * as v from 'valibot'
import { ID } from 'type-graphql'
import { field, objectType } from './valibot-type-graphql'
import {
column,
entity,
oneToMany,
primaryGeneratedColumn,
} from './valibot-typeorm'
import { Recipe } from './recipe'
export const User = v.object(
{
id: v.number([primaryGeneratedColumn(), field(() => ID)]),
email: v.string([column(), field()]),
nickname: v.nullable(v.string([column(), field()])),
password: v.string([column()]),
recipes: v.array(Recipe, [
oneToMany(() => Recipe, { lazy: true }),
field(),
]),
},
[entity(), objectType()]
) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Valibot is a super cool Schema Builder! I am attracted by Valibot's modular design.
I plan to use Valibot as an Entity Schema Builder for MikroORM.
So far, I am using
TypeScript'sclassandDecoratorsto define MikroORM's Entity like this:Because TypeScript's
classdoesn't support multiple inheritance, I have to define thenamefield repeatedly.Maybe I can use Valibot and custom pipelines to solve this problem:
Here I use many custom pipelines:
primaryKey,property,index,unique,description. However, the current version of Valibot's pipeline only supportsValidationandTransformation. I don't think these custom pipes belong to eitherValidationorTransformation.Once
Metadatais supported, Valibot has the ability to shine in all scenarios where a Schema needs to be defined, such as graphql, typegoose, typeorm and not just for data validation likezod. Valibot's modularity, combined withMetadata, makes for a very powerful Schema Builder! All projects using TypeScript can use Valibot to define Schemas, and the development experience will be far superior to that ofclassandDecorators.Beta Was this translation helpful? Give feedback.
All reactions