/
githubmirror
/
trpc
Обзор
Документация
Войти
/
githubmirror
/
trpc
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
examples/cloudflare-workers/src/client.ts
36 строк
931 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'; const sleep = (ms = 100) => new Promise((resolve) => setTimeout(resolve, ms)); async function main() { const url = 'http://127.0.0.1:8787/trpc'; const proxy = createTRPCClient<AppRouter>({ links: [loggerLink(), httpBatchLink({ url })], }); await sleep(); // parallel queries await Promise.all([ // proxy.hello.query(), proxy.hello.query('client'), ]); await sleep(); const postCreate = await proxy.post.createPost.mutate({ title: 'hello client', }); console.log('created post', postCreate.title); await sleep(); const postList = await proxy.post.listPosts.query(); console.log('has posts', postList, 'first:', postList[0].title); await sleep(); console.log('👌 should be a clean exit if everything is working right'); } main().catch(console.error);