outis99
outis99
Explore posts from servers
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
TTCTheo's Typesafe Cult
Created by ᲼᲼᲼ on 4/19/2023 in #questions
In create-t3-app how to get tRPC zod schema on client?
I'm not sure this is what you want but check this out https://github.com/chrishoermann/zod-prisma-types
9 replies
TTCTheo's Typesafe Cult
Created by Sofiane on 4/18/2023 in #questions
Eslint bug or am I missing something ?
@Sofiane
21 replies
TTCTheo's Typesafe Cult
Created by Sofiane on 4/18/2023 in #questions
Eslint bug or am I missing something ?
like void signIn() for example
21 replies
TTCTheo's Typesafe Cult
Created by Sofiane on 4/18/2023 in #questions
Eslint bug or am I missing something ?
Try looking at some of their examples they use void on functions that return nothing I think
21 replies
TTCTheo's Typesafe Cult
Created by code_sanchu on 3/30/2023 in #questions
Keep order of a list of items in prisma
So something like
{
items: array of albums
order: [1, 3, 4, 2, 5]
}
{
items: array of albums
order: [1, 3, 4, 2, 5]
}
And just set the order array every time an item is added, moved, or deleted?
10 replies
TTCTheo's Typesafe Cult
Created by outis99 on 3/20/2023 in #questions
ctx.user.session.email possibly null | undefined
That's the weird thing it is non-nullable in my schema but whatever the other solution works
9 replies
TTCTheo's Typesafe Cult
Created by outis99 on 3/20/2023 in #questions
ctx.user.session.email possibly null | undefined
Well it works but eslint throws a warning for it so I removed the warning in my eslint
9 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