New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add tRPC #614
add tRPC #614
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/cal/calendso/G7paS6JjV9W3rAsQsMoutExWi7sQ |
This reverts commit e6f2d25.
# Conflicts: # pages/[user].tsx # prisma/schema.prisma # tsconfig.json # yarn.lock
# Conflicts: # lib/app-providers.tsx # pages/_app.tsx # pages/availability/index.tsx # pages/bookings/index.tsx
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't tested this locally but the code looks great :)
const bookings = bookingsQuery.reverse().map((booking) => { | ||
return { | ||
...booking, | ||
startTime: booking.startTime.toISOString(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this necessary (tRPC has issues dealing with Date/Dayjs objects?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just copy-pasted what was already in getServerSideProps
.
In tRPC we could actually just use a Date
-object if we add superjson.
}, | ||
}); | ||
}) | ||
.query("me", { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How should we go about splitting these into files?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same way we do on the app/root router to separate viewer
in it's own file
One can either do
export const myRouter = createRouter()
.merge("sub.", subRouter); // <-- prefixes all procedures with `sub.`
Or
export const myRouter = createRouter()
.merge(subRouter); // <-- does not prefix any procedures
And this works on the viewerRouter
too, so if that file got insanely big or if we wanted to do distinct parts separately, they could be handled in their own file
# Conflicts: # lib/app-providers.tsx # yarn.lock
This PR adds tRPC which automatically infers the types from your API-function into the frontend.
As a reference I rewrote
/bookings
+/availability
-pages/bookings
-page andShell
to usetrpc.useQuery()
rather than custom fetch hook andgetServerSideProps
getServerSideProps
into a function inroutes
Benefits
Extra fixes on this branch
callbackUrl
on login so it redirects to the right page after signing inHow to test it
yarn dx
to startNext steps
#615 depends on this branch (will make everything lightning fast ⚡️)
More info
for more info on tRPC have a look at https://trpc.io or for a deep-dive look at https://www.youtube.com/watch?v=-_GZJ3xwYOw
feel free to ping me on Slack - maybe I should make a loom?