/
githubmirror
/
trpc
Обзор
Документация
Войти
/
githubmirror
/
trpc
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
examples/bun/src/client.ts
39 строк
995 B
Julius Marminge
refactor: rename and deprecate proxy named stuff (#4932)
20 окт 2023, 21:37
Не верифицирован
20 окт 2023, 21:37
7387cde
Код
Авторство
О чём код?
import { createTRPCClient, httpBatchLink, loggerLink } from '@trpc/client'; import type { AppRouter } from './router.ts'; async function delay(ms: number) { return new Promise((resolve) => { setTimeout(resolve, ms); }); } async function main() { const url = 'http://127.0.0.1:3000/trpc'; const proxy = createTRPCClient<AppRouter>({ links: [loggerLink(), httpBatchLink({ url })], }); await delay(100); // parallel queries await Promise.all([proxy.hello.query(), proxy.hello.query('client')]); await delay(100); const postCreate = await proxy.post.createPost.mutate({ title: 'hello client', }); console.log('created post', postCreate.title); await delay(100); const postList = await proxy.post.listPosts.query(); console.log('has posts', postList, 'first:', postList[0].title); await delay(100); console.log('👌 should be a clean exit if everything is working right'); } main().catch((err) => { console.error(err); process.exit(1); });