outis99
outis99
TtRPC
Created by outis99 on 6/16/2023 in #❓-help
Handling errors on the front-end
@s.daniel Let me know if you need anything else
16 replies
TtRPC
Created by outis99 on 6/16/2023 in #❓-help
Handling errors on the front-end
Also previously when I mentioned that settings are default I mean the default t3 stack configuration
16 replies
TtRPC
Created by outis99 on 6/16/2023 in #❓-help
Handling errors on the front-end
On my _app.tsx export default api.withTRPC(MyApp); The api file
/**
* This is the client-side entrypoint for your tRPC API. It is used to create the `api` object which
* contains the Next.js App-wrapper, as well as your type-safe React Query hooks.
*
* We also create a few inference helpers for input and output types.
*/
import { httpBatchLink, loggerLink } from "@trpc/client";
import { createTRPCNext } from "@trpc/next";
import { type inferRouterInputs, type inferRouterOutputs } from "@trpc/server";
import superjson from "superjson";

import { type AppRouter } from "src/server/api/root";

const getBaseUrl = () => {
if (typeof window !== "undefined") return ""; // browser should use relative url
if (process.env.VERCEL_URL) return `https://${process.env.VERCEL_URL}`; // SSR should use vercel url
return `http://localhost:${process.env.PORT ?? 3000}`; // dev SSR should use localhost
};

/** A set of type-safe react-query hooks for your tRPC API. */
export const api = createTRPCNext<AppRouter>({
config() {
return {
/**
* Transformer used for data de-serialization from the server.
*
* @see https://trpc.io/docs/data-transformers
*/
transformer: superjson,

/**
* Links used to determine request flow from client to server.
*
* @see https://trpc.io/docs/links
*/
links: [
httpBatchLink({
url: `${getBaseUrl()}/api/trpc`,
}),
],
};
},
/**
* Whether tRPC should await queries when server rendering pages.
*
* @see https://trpc.io/docs/nextjs#ssr-boolean-default-false
*/
ssr: false,
});

/**
* Inference helper for inputs.
*
* @example type HelloInput = RouterInputs['example']['hello']
*/
export type RouterInputs = inferRouterInputs<AppRouter>;

/**
* Inference helper for outputs.
*
* @example type HelloOutput = RouterOutputs['example']['hello']
*/
export type RouterOutputs = inferRouterOutputs<AppRouter>;
/**
* This is the client-side entrypoint for your tRPC API. It is used to create the `api` object which
* contains the Next.js App-wrapper, as well as your type-safe React Query hooks.
*
* We also create a few inference helpers for input and output types.
*/
import { httpBatchLink, loggerLink } from "@trpc/client";
import { createTRPCNext } from "@trpc/next";
import { type inferRouterInputs, type inferRouterOutputs } from "@trpc/server";
import superjson from "superjson";

import { type AppRouter } from "src/server/api/root";

const getBaseUrl = () => {
if (typeof window !== "undefined") return ""; // browser should use relative url
if (process.env.VERCEL_URL) return `https://${process.env.VERCEL_URL}`; // SSR should use vercel url
return `http://localhost:${process.env.PORT ?? 3000}`; // dev SSR should use localhost
};

/** A set of type-safe react-query hooks for your tRPC API. */
export const api = createTRPCNext<AppRouter>({
config() {
return {
/**
* Transformer used for data de-serialization from the server.
*
* @see https://trpc.io/docs/data-transformers
*/
transformer: superjson,

/**
* Links used to determine request flow from client to server.
*
* @see https://trpc.io/docs/links
*/
links: [
httpBatchLink({
url: `${getBaseUrl()}/api/trpc`,
}),
],
};
},
/**
* Whether tRPC should await queries when server rendering pages.
*
* @see https://trpc.io/docs/nextjs#ssr-boolean-default-false
*/
ssr: false,
});

/**
* Inference helper for inputs.
*
* @example type HelloInput = RouterInputs['example']['hello']
*/
export type RouterInputs = inferRouterInputs<AppRouter>;

/**
* Inference helper for outputs.
*
* @example type HelloOutput = RouterOutputs['example']['hello']
*/
export type RouterOutputs = inferRouterOutputs<AppRouter>;
16 replies
TtRPC
Created by outis99 on 6/16/2023 in #❓-help
Handling errors on the front-end
Even that doesn't work, I'm sorry but I can't see what I am missing here and why throwing an error from the server is so difficult to handle on the client. All of the tRPC settings and files are default and I haven't changed any error formatters or loggerlinks or whatever, should I post a git issue for this maybe?
16 replies
TtRPC
Created by outis99 on 6/16/2023 in #❓-help
Handling errors on the front-end
I looked through all the files but can't seem to find something that swallows it @nlucas
16 replies
TtRPC
Created by outis99 on 6/16/2023 in #❓-help
Handling errors on the front-end
But as you can see on the image all the error values are false/null
16 replies
TtRPC
Created by outis99 on 6/16/2023 in #❓-help
Handling errors on the front-end
Server-side onError receives it as well as the error formatter
16 replies
TtRPC
Created by outis99 on 6/16/2023 in #❓-help
Handling errors on the front-end
16 replies
TtRPC
Created by outis99 on 10/17/2022 in #❓-help
Mutation type issue
Yes it is, this is my schema
model Project {
id String @id @default(cuid())
updatedAt DateTime @updatedAt @default(now())
slug String
title String

userId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
columns Column[]

@@unique([slug, userId])
}

model Column {
id String @id @default(cuid())
title String

projectId String
project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
cards Card[]
}

model Card {
id String @id @default(cuid())
title String
index Int
description String?

columnId String
column Column @relation(fields: [columnId], references: [id], onDelete: Cascade)
}
model Project {
id String @id @default(cuid())
updatedAt DateTime @updatedAt @default(now())
slug String
title String

userId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
columns Column[]

@@unique([slug, userId])
}

model Column {
id String @id @default(cuid())
title String

projectId String
project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
cards Card[]
}

model Card {
id String @id @default(cuid())
title String
index Int
description String?

columnId String
column Column @relation(fields: [columnId], references: [id], onDelete: Cascade)
}
39 replies
TtRPC
Created by outis99 on 10/17/2022 in #❓-help
Mutation type issue
It works but it has to update each index individually
39 replies
TtRPC
Created by outis99 on 10/17/2022 in #❓-help
Mutation type issue
This is what I came up with
updateColumn: protectedProcedure
.input(
z.object({
colId: z.string(),
cards: z.any(),
})
)
.mutation(async ({ input, ctx }) => {
for (let i = 0; i < input.cards.length; i++) {
const card = input.cards[i] as Card;

const _card = await ctx.prisma.card.update({
where: {
id: card.id,
},
data: {
index: i,
},
});
}

console.log("input cards?", input.cards);
}),
updateColumn: protectedProcedure
.input(
z.object({
colId: z.string(),
cards: z.any(),
})
)
.mutation(async ({ input, ctx }) => {
for (let i = 0; i < input.cards.length; i++) {
const card = input.cards[i] as Card;

const _card = await ctx.prisma.card.update({
where: {
id: card.id,
},
data: {
index: i,
},
});
}

console.log("input cards?", input.cards);
}),
39 replies
TtRPC
Created by outis99 on 10/17/2022 in #❓-help
Mutation type issue
Well I hope so too, appreciate the help
39 replies
TtRPC
Created by outis99 on 10/17/2022 in #❓-help
Mutation type issue
I also tried something like this
const column = await ctx.prisma.column.update({
where: {
id: input.colId,
},
data: {
cards: {
set: input.cards,
},
},
});
const column = await ctx.prisma.column.update({
where: {
id: input.colId,
},
data: {
cards: {
set: input.cards,
},
},
});
But set only takes exactly one arguement, the id
39 replies
TtRPC
Created by outis99 on 10/17/2022 in #❓-help
Mutation type issue
Argument cards: Got invalid value
[
{
id: 'cl9ego52z0001wb0k7ueqykh7',
title: 'Test 2',
index: 1,
description: null,
columnId: 'cl9eftdjm0002wbucv6rjulj0'
},
{
id: 'cl9eg8r4r0000wb0kd9j6cy17',
title: 'Test',
index: 0,
description: null,
columnId: 'cl9eftdjm0002wbucv6rjulj0'
}
]
on prisma.updateOneColumn. Provided List<Json>, expected CardUpdateManyWithoutColumnNestedInput:
type CardUpdateManyWithoutColumnNestedInput {
create?: CardCreateWithoutColumnInput | List<CardCreateWithoutColumnInput> | CardUncheckedCreateWithoutColumnInput | List<CardUncheckedCreateWithoutColumnInput>
connectOrCreate?: CardCreateOrConnectWithoutColumnInput | List<CardCreateOrConnectWithoutColumnInput>
upsert?: CardUpsertWithWhereUniqueWithoutColumnInput | List<CardUpsertWithWhereUniqueWithoutColumnInput>
createMany?: CardCreateManyColumnInputEnvelope
set?: CardWhereUniqueInput | List<CardWhereUniqueInput>
disconnect?: CardWhereUniqueInput | List<CardWhereUniqueInput>
delete?: CardWhereUniqueInput | List<CardWhereUniqueInput>
connect?: CardWhereUniqueInput | List<CardWhereUniqueInput>
update?: CardUpdateWithWhereUniqueWithoutColumnInput | List<CardUpdateWithWhereUniqueWithoutColumnInput>
updateMany?: CardUpdateManyWithWhereWithoutColumnInput | List<CardUpdateManyWithWhereWithoutColumnInput>
deleteMany?: CardScalarWhereInput | List<CardScalarWhereInput>
}
Argument cards: Got invalid value
[
{
id: 'cl9ego52z0001wb0k7ueqykh7',
title: 'Test 2',
index: 1,
description: null,
columnId: 'cl9eftdjm0002wbucv6rjulj0'
},
{
id: 'cl9eg8r4r0000wb0kd9j6cy17',
title: 'Test',
index: 0,
description: null,
columnId: 'cl9eftdjm0002wbucv6rjulj0'
}
]
on prisma.updateOneColumn. Provided List<Json>, expected CardUpdateManyWithoutColumnNestedInput:
type CardUpdateManyWithoutColumnNestedInput {
create?: CardCreateWithoutColumnInput | List<CardCreateWithoutColumnInput> | CardUncheckedCreateWithoutColumnInput | List<CardUncheckedCreateWithoutColumnInput>
connectOrCreate?: CardCreateOrConnectWithoutColumnInput | List<CardCreateOrConnectWithoutColumnInput>
upsert?: CardUpsertWithWhereUniqueWithoutColumnInput | List<CardUpsertWithWhereUniqueWithoutColumnInput>
createMany?: CardCreateManyColumnInputEnvelope
set?: CardWhereUniqueInput | List<CardWhereUniqueInput>
disconnect?: CardWhereUniqueInput | List<CardWhereUniqueInput>
delete?: CardWhereUniqueInput | List<CardWhereUniqueInput>
connect?: CardWhereUniqueInput | List<CardWhereUniqueInput>
update?: CardUpdateWithWhereUniqueWithoutColumnInput | List<CardUpdateWithWhereUniqueWithoutColumnInput>
updateMany?: CardUpdateManyWithWhereWithoutColumnInput | List<CardUpdateManyWithWhereWithoutColumnInput>
deleteMany?: CardScalarWhereInput | List<CardScalarWhereInput>
}
Some more that was missing but I don't think it's of any use
39 replies
TtRPC
Created by outis99 on 10/17/2022 in #❓-help
Mutation type issue
I think it has to do with how updating records works in Prisma when you also have relations
39 replies
TtRPC
Created by outis99 on 10/17/2022 in #❓-help
Mutation type issue
It's exactly the same, I don't it's a type issue
39 replies
TtRPC
Created by outis99 on 10/17/2022 in #❓-help
Mutation type issue
This is the type
39 replies
TtRPC
Created by outis99 on 10/17/2022 in #❓-help
Mutation type issue
export type Card = {
id: string
title: string
index: number
description: string | null
columnId: string
}
export type Card = {
id: string
title: string
index: number
description: string | null
columnId: string
}
39 replies
TtRPC
Created by outis99 on 10/17/2022 in #❓-help
Mutation type issue
39 replies
TtRPC
Created by outis99 on 10/17/2022 in #❓-help
Mutation type issue
You would think it works like that but doesn't
39 replies