-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
588bb58
commit 217b830
Showing
5 changed files
with
51 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
"use client" | ||
import { trpc } from "../_trpc/client" | ||
'use client'; | ||
import { trpc } from '../_trpc/client'; | ||
|
||
export default function TestHook() { | ||
const test = trpc.test.useQuery() | ||
const testMutation = trpc.hello.useMutation() | ||
const test = trpc.test.useQuery(); | ||
const hellothere = trpc.hellothere.useQuery(); | ||
|
||
return ( | ||
<div> | ||
<p>{JSON.stringify(test.data)}</p> | ||
<p>{JSON.stringify(testMutation.data)}</p> | ||
</div> | ||
) | ||
} | ||
return ( | ||
<div> | ||
<p>{JSON.stringify(test.data)}</p> | ||
<p>{JSON.stringify(hellothere.data)}</p> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import { appRouter } from "@/server"; | ||
import { fetchRequestHandler } from "@trpc/server/adapters/fetch"; | ||
import { appRouter } from '@/server'; | ||
import { fetchRequestHandler } from '@trpc/server/adapters/fetch'; | ||
|
||
const handler = (req: Request) => | ||
fetchRequestHandler({ | ||
endpoint: "/api/trpc", | ||
req, | ||
router: appRouter, | ||
createContext: () => ({}) | ||
}) | ||
const handler = (req: Request) => | ||
fetchRequestHandler({ | ||
endpoint: '/api/trpc', | ||
req, | ||
router: appRouter, | ||
createContext: () => ({}), | ||
}); | ||
|
||
export { handler as GET, handler as POST }; | ||
export { handler as DELETE, handler as GET, handler as POST, handler as PUT }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { publicProcedure } from '../trpc'; | ||
|
||
export default function apiSecondTest() { | ||
return { | ||
hellothere: publicProcedure.query(async () => { | ||
return { | ||
data: { status: 200, message: 'Hello world!' }, | ||
}; | ||
}), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { publicProcedure } from '../trpc'; | ||
|
||
export default function apiTest() { | ||
return { | ||
test: publicProcedure.query(async () => { | ||
return { | ||
message: 'Hello world! if you see this, it means that trpc is working!', | ||
}; | ||
}), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,10 @@ | ||
import { z } from 'zod'; | ||
import { publicProcedure, router } from "./trpc"; | ||
import apiSecondTest from './api/secondTestTRPC'; | ||
import apiTest from './api/testTRPC'; | ||
import { router } from './trpc'; | ||
|
||
export const appRouter = router({ | ||
test: publicProcedure.query(async () => { | ||
return { | ||
message: 'Hello world! if you see this, it means that trpc is working!' | ||
} | ||
}), | ||
hello: publicProcedure.input(z.string()).mutation(async (input) => { | ||
return { | ||
message: `Hello, ${input}!` | ||
} | ||
}) | ||
}) | ||
...apiTest(), | ||
...apiSecondTest(), | ||
}); | ||
|
||
export type AppRouter = typeof appRouter; | ||
export type AppRouter = typeof appRouter; |