How to define complex update input #2507
-
Hi, I'm quite new to tRPC, I have experience with GraphQL and I'm trying to understand how I can define the I have this model enum ClientType {
INDIVIDUAL
COMPANY
}
enum Category {
IRRIGATION_SYSTEMS
DECKING_FENCING
PLANTS
PAVING
}
enum InvoiceStatus {
PAID
UNPAID
}
model Client {
id String @id @default(uuid())
firstName String
lastName String
street String
postalCode String
city String
email String @unique
type ClientType
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
phoneNumberMobile String?
phoneNumberLandLine String?
invoices Invoice[]
quotations Quotation[]
@@index([email, firstName, lastName, phoneNumberMobile, phoneNumberLandLine])
}
model Stock {
id String @id @default(uuid())
name String
quantity Int
price Float
category Category
}
model Invoice {
id String @id @default(uuid())
number Int @unique
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
status InvoiceStatus
dueOn DateTime
clientId String
client Client @relation(fields: [clientId], references: [id], onDelete: NoAction)
quotationId String? @unique
quotation Quotation? @relation(fields: [quotationId], references: [id], onDelete: NoAction)
sections InvoiceSection[]
@@index([number, dueOn])
}
model Quotation {
id String @id @default(uuid())
number Int @unique
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
validUntil DateTime
clientId String
client Client @relation(fields: [clientId], references: [id], onDelete: NoAction)
invoice Invoice?
sections QuotationSection[]
@@index([number, validUntil])
}
enum SectionUnit {
HOURLY
QUANTITY
}
model InvoiceSectionItem {
id String @id @default(uuid())
name String
price String
description String @db.Text
sectionId String
sections InvoiceSection[]
@@index([sectionId])
}
model InvoiceSection {
id String @id @default(uuid())
name String
category Category
items InvoiceSectionItem[]
unit SectionUnit
invoiceId String
invoice Invoice @relation(fields: [invoiceId], references: [id], onDelete: NoAction)
}
model QuotationSectionItem {
id String @id @default(uuid())
name String
price String
description String @db.Text
sectionId String
sections QuotationSection[]
@@index([sectionId])
}
model QuotationSection {
id String @id @default(uuid())
name String
category Category
items QuotationSectionItem[]
unit SectionUnit
quotationId String?
quotation Quotation? @relation(fields: [quotationId], references: [id], onDelete: NoAction)
} I have a route to update an invoice. In the invoice I want to be able to add/remove/update sections and/or items to these sections. In GraphQL I could use GraphQL code generator to generate the type for the Is there a good example of a more or less complex input for an update mutation or could you guys guide me on what would be the best approach to define this kind of input? Thank you |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
Hi @jlalmes , Thank you for getting back. I'm looking for updates that have relationships. In my example, I have an invoice that has sections that has items. I'm wondering if I need to fully define what kind of object that I'm expecting. This could become quite complex based on the type of relationships you can get. In GraphQL I can create a function that would build the variables to the needed input. I could simply type the function return with the appropriate type and the function would take care of building the input accordingly to the needed output. What are the best practices for complex update inputs? Are we supposed to define the input exactly as the type it's expecting? |
Beta Was this translation helpful? Give feedback.
Hi @jlalmes ,
Thank you for getting back. I'm looking for updates that have relationships. In my example, I have an invoice that has sections that has items. I'm wondering if I need to fully define what kind of object that I'm expecting. This could become quite complex based on the type of relationships you can get.
In GraphQL I can create a function that would build the variables to the needed input. I could simply type the function return with the appropriate type and the function would take care of building the input accordingly to the needed output.
What are the best practices for complex update inputs? Are we supposed to define the input exactly as the type it's expecting?