GO/GraphQL for Realtime Apps

agolangf · · 589 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>This might be a silly question but I have never used these technologies before. I wanted to know if there was a good library or service for creating a realtime app with GO and GraphQL. </p> <p>If anyone has any experience with that and would like to share their advice, I would be very grateful. </p> <p>Thanks</p> <hr/>**评论:**<br/><br/>vektah: <pre><p>You should check out <a href="https://github.com/vektah/gqlgen#feature-comparison" rel="nofollow">https://github.com/vektah/gqlgen#feature-comparison</a> for a comparison of the top 4 libraries.</p> <p>gqlgen works around go&#39;s lack of generics by using code generation. Take a look at <a href="https://gqlgen.com/getting-started/" rel="nofollow">https://gqlgen.com/getting-started/</a> </p> <p>Disclaimer: author of gqlgen, may be a little biased.</p></pre>SeerUD: <pre><p>I think I&#39;ve looked at your library before, and while impressive at getting things up and running quickly, it uses the neelance library (now <code>graph-gophers/graphql-go</code> I believe?).</p> <p>Under the hood, this is still using a ton of reflection, so despite being able to generate a lot of nice looking strongly-typed code on the surface, it&#39;s still using a lot of reflection to figure out how to work with those types, right?</p> <p>Interestingly, I did some benchmarks fairly recently and saw that <code>graphql-go/graphql</code> had taken the lead in terms of performance (at least for what I was testing it with).</p> <p>Me and a friend have started our own GraphQL parser, and so far we&#39;re seeing really promising results. We&#39;ve go the fastest lexer we&#39;ve tested by quite a long way, and are moving onto the parser now. From there of course we&#39;d still have the same issue as anything else doing GraphQL in Go - reflection of some kind. So, we plan on writing a code generator too, to generate the whole server with specific types in mind. It won&#39;t be a library like neelance&#39;s or the others, it will specifically make a server for your schema, and will actually be type safe, with no reflection - if we manage to pull it off. All in all, that should mean it&#39;s extremely fast too.</p></pre>lwcd: <pre><p>Afaik it&#39;s only using the parser from graph-gophers, looks like all the actual runtime code is without reflection. </p> <p>I&#39;ve not benchmaked it, but given it supports parallel execution of resolvers and doesn&#39;t rely on reflection, I&#39;d be willing to bet it&#39;s pretty quick in most cases.</p></pre>lwcd: <pre><p>Is your parser available anywhere? I think there&#39;s a fair bit missing from the gophers parser atm. </p> <p>It&#39;d be nice to have a shared contract at the parser level so these projects could share some code etc</p></pre>SeerUD: <pre><p>Aha, I&#39;ll have to give this thing a proper looking at. Just tried the getting started tutorial but got some errors.</p></pre>vektah: <pre><p>That&#39;s a shame, I&#39;ll get it fixed. Unfortunately, because there is so much codegen involved godoc examples don&#39;t work so well. </p></pre>vektah: <pre><p>As lwcd suggests gqlgen doesn&#39;t use any runtime reflection at all. </p> <p>If you take a look at the generated code it unrolls all of the field selection and json encoding.</p> <p><a href="https://github.com/vektah/gqlgen/blob/master/example/todo/generated.go#L189-L219" rel="nofollow">https://github.com/vektah/gqlgen/blob/master/example/todo/generated.go#L189-L219</a></p> <p>If you have some benchmarks somewhere I would love to add gqlgen to it, it should be stupid fast.</p></pre>mike_hman: <pre><p>GraphQL on Go, in general, is very rough due to limitations in the type system. As for realtime, I know less on that topic.</p> <p>If you represent a company who is looking to deploy GraphQL, a better method for today is to spin up an Apollo or Vesper &#34;proxy&#34; as your API, which could even do authentication as well, then have it make requests to a Go backend via a more traditional protocol like REST or RPC.</p> <p>If you&#39;re just a person looking to experiment, there are certainly GraphQL libraries for Go, but its a real pain. Another option is to use AWS AppSync, then write lambda function resolvers in Go. But otherwise: GraphQL is much more mature on Node, Rust, and Elixir. That&#39;s where a lot of the development is happening today. </p></pre>fakintheid: <pre><p>If you mean true real-time, golang isn’t gonna cut it. But for the “real time web” you could certainly use go with some web sockets and graph the points client side. </p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

589 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传