Qwik City adapter for trpc.io

Overview

tRPC qwik-city

tRPC 🤝 Qwik City

End-to-end typesafe APIs made easy with
tRPC.io in Qwik City applications.
Build & consume fully typesafe APIs, without schemas or code generation.


Working example: tRPC Qwik City


Getting started


Install trpc-qwik-city package


npm install trpc-qwik-city

or

yarn add trpc-qwik-city

Create tRPC routes

e.g.

// src/server/trpc/index.ts

import type { inferAsyncReturnType } from '@trpc/server';
import * as trpc from '@trpc/server';
import trpcTransformer from 'trpc-transformer';
import authors from './authors';

export const createContext = async () => ({});

export const router = trpc
  .router<inferAsyncReturnType<typeof createContext>>()
  .transformer(trpcTransformer)
  .merge('authors:', authors);

export type Router = typeof router;

Expose tRPC Api


// src/routes/api/trpc/[whatever]/index.ts

import type { EndpointHandler } from '@builder.io/qwik-city';
import { resolveTRPCResponse } from 'trpc-qwik-city';
import { createContext, router } from '../../../../server/trpc';

// GET manage queries
export const onGet: EndpointHandler = async ({ request, params }) => {
  const response = await resolveTRPCResponse({
    request,
    params,
    router,
    createContext,
  });
  const json = await response.json();
  return json;
};

// POST manage mutations
export const onPost: EndpointHandler = async ({ request, params }) => {
  const response = await resolveTRPCResponse({
    request,
    params,
    router,
    createContext,
  });
  const json = await response.json();
  return json;
};

Use tRPC inside component


e.g.

import trpc from '~/client/trpc';
...
...
const authors = await trpc(fetch.bind(window)).query('authors:list');

License

The ISC License.

You might also like...

A smart city community centered application I am building for the Hackers In Residence under the Nkwashi program

A smart city community centered application I am building for the Hackers In Residence under the Nkwashi program. Implementing solutions and automation for potential future problems in the city.

Apr 25, 2022

From the Linux Foundation office in New York City, welcome to The Untold Stories of Open Source

From the Linux Foundation office in New York City, welcome to The Untold Stories of Open Source

From the Linux Foundation office in New York City, welcome to The Untold Stories of Open Source. Each week we explore the people who are supporting Open Source projects, how they became involved with it, and the problems they faced along the way.

Jan 5, 2023

Simba is a city like Florence, Vienna, or San Francisco but built via the internet.

Simba is a city like Florence, Vienna, or San Francisco but built via the internet.

Simba City Project setup Duplicate env.example and .env.test.example and rename to .env and .env.test Firebase Authentication We are going to use fire

Dec 15, 2022

An adapter where you can define which function to run

Switch Functions An adapter where you can define which function to run Installation This is a Node.js module available through the npm registry. Befor

Jun 17, 2022

A Feathers service adapter for Prisma ORM.

feathers-prisma A Feathers service adapter for Prisma ORM. Installation npm install feathers-prisma --save Documentation This adapter supports all me

Dec 9, 2022

🔨 A more engineered, highly customizable, standard output format commitizen adapter.

🔨 A more engineered, highly customizable, standard output format commitizen adapter.

cz-git Github | Installation | Website | 简体中文文档 Introduction A more engineered, highly customizable, standard output format commitizen adapter. What i

Dec 31, 2022

An example on how to use Solana Wallet Adapter as a Web Authentication Method.

An example on how to use Solana Wallet Adapter as a Web Authentication Method.

Solana Wallet Auth: A FullStack example This example uses Solana's wallet adapter to sign messages and verifies their signatures on the backend, allow

Dec 20, 2022

Adapter application for consuming web3 messages from ie. wallets, and passing them on to starknet

🐍 StarknNet web3 account Development setup Clone deps with submodules git clone --recurse-submodules [email protected]:software-mansion-labs/starknet-we

Nov 21, 2022

Debug Adapter Protocol for Amiga development with FS-UAE or WinUAE

UAE Debug Adapter Protocol Debug Adapter Protocol for Amiga assembly development with FS-UAE or WinUAE. Adapted from @prb28's vscode-amiga-assembly ex

Jul 7, 2022
Releases(0.0.1)
Owner
Giorgio Boa
💻 Full stack developer @claranet-it 🔧 @ItalianCoders community admin 🇮🇹 Public Speaker 🔊 I love pizza🍕and good music 🎧
Giorgio Boa
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
An e-commerce storefront starter built with Qwik and Vendure

Vendure Qwik Storefront Starter️ An e-commerce storefront for Vendure built with Qwik & Qwik City. ?? qwik-storefront.vendure.io To do Cart ✅ Checkout

Vendure 81 Dec 31, 2022
qwik.wrong-lang.click website source code

Qwik App ⚡️ Qwik Docs Discord Qwik Github @QwikDev Vite Partytown Mitosis Builder.io Project Structure Inside of you project, you'll see the following

Wrong Lang 3 Oct 7, 2022
BETA partytown-qwik

Qwik Partytown ?? This is a package that facilitates the implementation of PartyTown in Qwik. If you don't know what Qwik is See The implementation is

Leifer Mendez 7 Dec 20, 2022
Generate translated routes for your qwik project.

qwik-translate-routes Generate translated routes for your qwik project. Installation // npm npm install -D qwik-translate-routes // yarn yarn add -D q

Alexandre Fernandez 5 Dec 28, 2022
Urql support for Qwik projects.

Qwik Urql ⚡️ A small library to use Urql with Qwik. ✅ Query & mutation hooks ✅ SSR ✅ Lazy loaded client ✅ Auth tokens ✅ Abort signals ✅ Re-execute que

null 15 Dec 21, 2022
科技风智慧城市 Demo: http://stonerao.com/public/city/

Three.js Setup Download Node.js. Run this followed commands: # Install dependencies (only the first time) npm install # Run the local server at local

rao_yan 120 Dec 2, 2022
SafeCycle—a tool that keeps cyclists safe. Gone are days of weaving through busy city streets, SafeCycle finds all the bike routes for you to ensure a smooth ride wherever you want to go.

Inspiration Biking—an everyday form of travel for students and professionals across the globe. On-campus, back home, and with the people that we know

Ryan Hu 2 May 2, 2022