Skip to content
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

feat: initial trpc setup #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions apps/xdapp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
# Keep environment variables out of version control
.env
10 changes: 9 additions & 1 deletion apps/xdapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,25 @@
"license": "ISC",
"dependencies": {
"@labxd/gustxd": "^0.8.2",
"@prisma/client": "^4.5.0",
"@tanstack/react-query": "^4.12.0",
"@trpc/client": "10.0.0-proxy-beta.24",
"@trpc/next": "10.0.0-proxy-beta.24",
"@trpc/react-query": "10.0.0-proxy-beta.24",
"@trpc/server": "10.0.0-proxy-beta.24",
"autoprefixer": "^10.4.12",
"next": "^12.3.1",
"postcss": "^8.4.17",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"tailwindcss": "^3.1.8"
"tailwindcss": "^3.1.8",
"zod": "^3.19.1"
},
"devDependencies": {
"@types/node": "16",
"@types/react": "^18.0.21",
"@types/react-dom": "^18.0.6",
"prisma": "^4.5.0",
"typescript": "^4.8.4"
}
}
14 changes: 14 additions & 0 deletions apps/xdapp/src/modules/trpc/api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { initTRPC } from "@trpc/server"

const t = initTRPC.create()

export const router = t.router
export const procedure = t.procedure

export const appRouter = router({
hello: procedure.query(() => {
return "Hello World"
}),
})

export type AppRouter = typeof appRouter
16 changes: 16 additions & 0 deletions apps/xdapp/src/modules/trpc/web/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { httpBatchLink } from "@trpc/client"
import { createTRPCNext } from "@trpc/next"

import type { AppRouter } from "../api"

export const t = createTRPCNext<AppRouter>({
config() {
return {
links: [
httpBatchLink({
url: `/api/trpc`,
}),
],
}
},
})
6 changes: 5 additions & 1 deletion apps/xdapp/src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import "../styles/global.css"

import type { AppProps } from "next/app"

export default function MyApp({ Component, pageProps }: AppProps) {
import { t } from "../modules/trpc/web"

function MyApp({ Component, pageProps }: AppProps) {
return <Component {...pageProps} />
}

export default t.withTRPC(MyApp)
8 changes: 8 additions & 0 deletions apps/xdapp/src/pages/api/trpc/[trpc].ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import * as trpcNext from "@trpc/server/adapters/next"

import { appRouter } from "../../../modules/trpc/api"

export default trpcNext.createNextApiHandler({
router: appRouter,
createContext: () => ({}),
})
10 changes: 9 additions & 1 deletion apps/xdapp/src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import type { NextPage } from "next"
import Head from "next/head"

import { t } from "../modules/trpc/web"

const Home: NextPage = () => {
const { data, isLoading } = t.hello.useQuery()

if (isLoading) {
return <h1>Loading...</h1>
}

return (
<div>
<Head>
<title>XD App</title>
</Head>
<main className="xd-card xd-card-border-l">Hello World!</main>
<main className="xd-card xd-card-border-l">{data}</main>
</div>
)
}
Expand Down
5 changes: 3 additions & 2 deletions apps/xdapp/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"incremental": true,
Expand All @@ -17,7 +17,8 @@
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve"
"jsx": "preserve",
"strictNullChecks": true
},
"include": [
"next-env.d.ts",
Expand Down
129 changes: 129 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.