TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

API typesafety without the tears (or code generation)

2 点作者 colinmcd将近 4 年前

3 条评论

jdauriemma将近 4 年前
I want to acknowledge the great work that has gone into this tool, which seems to be practical and elegant. This blog post, though, has some needlessly provocative statements that distract the reader from the utility of tRPC.<p>The image of GraphQL&#x27;s epitaph implies that tRPC is killing or will GraphQL. This is misleading: as you acknowledge in the text of the article, GraphQL is a specification that is language-agnostic. tRPC is not language-agnostic, nor is it a spec, so why use such stark imagery?<p>I also need to point out this snippet:<p>&gt; But the vast majority of projects that use GraphQL are JavaScript-based. The graphql NPM module has 5M downloads&#x2F;week vs ~300k) for the graphene Python module and ~230k for the graphql Rubygem. It&#x27;s not a perfect metric, but the signal is clear.<p>I disagree that there&#x27;s any clarity or signal to be had from these figures. Node, Python, and Ruby package management paradigms are all different. &quot;It&#x27;s not a perfect metric&quot; is an understatement, and &quot;the signal is clear&quot; is an overstatement.<p>&gt; As TypeScript approaches near-universal adoption in the JS ecosystem, that means most GraphQL-based projects will soon be TypeScript-based (if they aren&#x27;t already).<p>Again, this is overstated. &quot;Near-universal?&quot; How could you possibly substantiate such an outlandish claim? I suggest you scale down the claim to &quot;as TypeScript continues its rise in the JS ecosystem,&quot;.<p>But perhaps the most relevant hand-wavery in the entire article is as follows:<p>&gt; Here&#x27;s the thing: most people use GraphQL as a massively over-engineered way to share the type signature of their API with your client.<p>A citation is sorely needed here. My team is using GraphQL in a production app serving millions of users - its type system is great but only one of many features we&#x27;re interested in.<p>Again, tRPC looks fantastic - it sells itself without the puffery and half-truths you&#x27;ve used in an otherwise excellent article.
colinmcd将近 4 年前
Author here. Most build tools for end-to-end typesafe APIs rely on code generation, notably OpenAPI and GraphQL. Codegen works, but it inevitably introduces lag and friction into the developer workflow. The fact that modern TypeScript makes it easy and safe to share type signatures between <i>any two TypeScript projects</i> is majorly underdiscussed and underutilized. I think some sort of &quot;TypeScript-native&quot; typesafe API library[0] is inevitable as a growing fraction of web projects are fullstack TypeScript. Excited to see how this all pans out!<p>[0] <a href="https:&#x2F;&#x2F;trpc.io&#x2F;" rel="nofollow">https:&#x2F;&#x2F;trpc.io&#x2F;</a>
kevmo314将近 4 年前
Isn&#x27;t not being bound to TypeScript a feature, not a bug?<p>Code generation definitely sucks, but it seems like a real solution would be to (somehow) get schema files importable into the language instead of imposing the language outwards. In js land this isn&#x27;t even unprecedented.