Comments (2)
Just saw this! Thanks so much for the ideas.
- I don't really see any reason to split up
@trpc/server
and@trpc/client
. I think they should be merged into a singletrpc
module. It makes the out-of-the-box experience so much cleaner.- Then the
@trpc
scope can be used for specific plugins/adapters etc. You could publish the Express adapter as@trpc/express
for instance. That would also let you properly specify all the requisite peerDependencies (which I don't believe are specified using the current@trpc/server/adapters/express
approach since it doesn't have its own package.json.
Prone to agree, the only con is that @trpc/client
requires a lot more polyfilling, @trpc/server is a very clean target of node 12
- I think
import * as
imports are a bad user experience. I submitted a PR with a solution.
Let's keep that discussion in #210
- Simplify the function names:
createTRPCClient
=>createClient
,createNextApiHandler
=>createHandler
,CreateNextContextOptions
=>ContextOptions
. It should be standard across adapters. It's obvious that a function calledcreateHandler
imported from"@trpc/server/adapters/next"
is creating a Next.js API handler. It doesn't need to be in the name.
I actually disagree, I don't like when libraries occupy "generic" namespaces as I just keep on importing the wrong ones. Also for the next adapter it's easier to find it by autocompletion if it's named since we have several adapters.
- The adapters should export a
createContext
function that can automatically typeopts
with the necessary types:
There is already CreateExpressContextFn
etc, I don't use them in the examples as I prefer being able to infer the Context
object from the function than to explicitly declare it. Example
- I think all requests (queries and mutations) should get served from a single URL. The
path
can be added as an additional query parameter for queries and in thebody
for mutations. This would also simplify the Next/Express adapters (no need for a catchall API route).
Strongly disagree, it's much cleaner to read as it is now when working with it (which I've done a lot the last few months) aaand I have some plans on how we would eventually do batching etc using the current structure as well.
Appreciate the input!
from trpc.
All seems reasonable!
A few followups:
the only con is that @trpc/client requires a lot more polyfilling
What are the polyfills for client
? Does that have anything to do with the @babel/runtime dependency? Might be worth standardizing on trpc
for the core library even if that means a few polyfills end up in the package.
I actually disagree, I don't like when libraries occupy "generic" namespaces as I just keep on importing the wrong ones.
That's understandable. A lot of these recommendations stem from the fact that the sample code in the docs just seems to complicated to me. The v0.x syntax was super clean and understandable, no function names to remember. I feel like it's gotten a lot more intimidating. Some of this was unavoidable due to the addition of more features, but in general I think you should prioritize clean, understandable code over collision avoidance. That's why I like the idea of merging @trpc/client
and @trpc/server
, enabling import { trpc } from 'trpc';
syntax, making it easier to define a typed endpoint without input
, etc. It's all about simplifying usage and syntax.
There is already CreateExpressContextFn
Sorry, I forgot to put in a code example. What I'd like to see is a createCreateContext
function (though hopefully you can think of a better name!) that types the inputs and infers the outputs:
const createContext = createCreateContext(opts => {
return {};
});
type Context = ReturnType<typeof createContext>
The point of this is to avoid having to remember the name "CreateNextContextOptions".
Strongly disagree, it's much cleaner to read as it is now when working with it
You mean in the Requests devtools or something? Hadn't thought of that...makes sense.
from trpc.
Related Issues (20)
- bug: Beta versioning is broken HOT 6
- bug(example): CLIENT_FETCH_ERROR on examples-next-prisma-websockets-starter
- docs: `createTRPCQueryUtils` usage docs are incorrect
- bug: `useSubscription` `onData` does not use ref in v11 HOT 2
- bug: Getting "property collision with a built-in method" in client apps when used trpc server with nestjs HOT 6
- feat: support Pusher/Ably/WSaaS for subscriptions
- docs: Current cacheing docs are invalid for NextJS App Router
- feat(v11): make MutationProcedure / QueryProcedure types public HOT 1
- docs: write up content-type docs
- bug: `tsc` fails in example project HOT 2
- feat: support form-data and octet-streams in remaining adapters
- bug: Cannot find module '@web3-storage/multipart-parser' HOT 6
- bug: Update to Set (with superjson) not triggering query HOT 7
- bug: request body read multiple times HOT 2
- bug: initializing websockets HOT 4
- feat: Expose `TRPCBuilder` class or interface HOT 3
- bug: error: NEXT_REDIRECT
- feat: Lazy load WS connection as needed HOT 2
- docs: Add TypeBox to Library integrations
- bug: 'hashQueryKey' is not exported from '@tanstack/react-query' HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from trpc.