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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

GraphQL JIT – GraphQL execution using a JIT compiler

53 点作者 cheeseface大约 3 年前

5 条评论

gavinray大约 3 年前
I remember seeing graphql-jit on a comparative benchmark of GQL server implementations, and it blowing everything out of the water, really impressive:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;benawad&#x2F;node-graphql-benchmarks" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;benawad&#x2F;node-graphql-benchmarks</a><p>Depending on your usecase, you can go one level further and directly evaluate the query AST without delegating to resolvers.<p>(This generally only makes sense if you do programmatic schema generation. IE, read some metadata about a source and then generate GQL types&#x2F;operations from it.)<p>So a query comes in, say something like:<p><pre><code> query { users(where: { name: { like: &quot;foo&quot; } }) { id email todos(where: { completed: { eq: true } }) { description } } } </code></pre> Rather than having resolvers, and firing the &quot;users&quot; and &quot;users.todos&quot; resolvers, you interpret the AST of the query directly as if it were a regular value<p>In the case of a SQL database, you&#x27;d have a recursive function that takes a level of the query AST and generates a SQL string. Then you&#x27;d execute the query, format the results, and return it to the client.<p>IE, in this case you&#x27;d probably generate something like<p><pre><code> SELECT id, email, JSON_OBJECT(&#x27;todos&#x27;, ...) AS todos FROM users JOIN todos ON todos.user_id = users.id </code></pre> As far as the client can tell, it&#x27;s a &quot;regular&quot; GraphQL server, but the serverside implementation doesn&#x27;t have any kind of real executable schema. It just behaves like it does.<p>The downside of this approach is that you lose the ability to use built-in functionality for things like tracing, query depth&#x2F;complexity limiting, etc. You&#x27;d have to write this on your own.
danpalmer大约 3 年前
It&#x27;s good to see this happening, and happening in the open. In both JS and Python I&#x27;ve seen GraphQL execution take a ridiculous amount of time using the commonly used libraries, so long that we had fall back to raw JSON content in some parts of our schema that previously had a lot of small resolvers. There was a Python semi-JIT experiment a while ago, but it was paid and had some dodgy security implications os we couldn&#x27;t use it, but the concept is a strong one.<p>This has been an effective approach for other areas like templating in Jinja2, so I&#x27;m not surprised that it&#x27;s being used for GraphQL.
jonkoops大约 3 年前
If you need to go to these steps to make optimizations, would it not make more sense to switch to a more bare metal programming language such as Rust for the entire stack?
评论 #31435890 未加载
tmitchel2大约 3 年前
Why not just go with graphql-aot and be done with it, plus it would work on serverless which I guess this wouldn&#x27;t.
spankalee大约 3 年前
It&#x27;d be nice if they talked about what their compilation did.
评论 #31434737 未加载
评论 #31435669 未加载
评论 #31437131 未加载