Graphql browser

blov · · 492 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I was hoping to write a graphql browser in go, but I can&#39;t figure out how to deal with not knowing the queries of responses in advance to create the requisite structs.</p> <p>Am I thinking about this wrong, or am I missing an obvious solution?</p> <hr/>**评论:**<br/><br/>sh41: <pre><p>What do you have in mind when you say a GraphQL browser? Can you describe it in more detail... do you mean like <a href="https://github.com/graphql/graphiql" rel="nofollow">Graph<em>i</em>QL</a>, or something else?</p></pre>wy100101: <pre><p>More or less exactly like GraphiQL.</p></pre>snail_34: <pre><p>Isn&#39;t GraphiQL 100% frontend?</p></pre>ematvey: <pre><p>If I understand you correctly, you&#39;re thinking about creating Go types for GraphQL schema types. It is not possible with statically typed languages like Go, unless you know schema at the compile time (then you&#39;d be able to do some codegen).</p> <p>Instead, you have to treat GraphQL schema types as data.</p></pre>wy100101: <pre><p>OK, that is sort of what I expected, but I wanted to make sure I wasn&#39;t missing something obvious. thanks.</p></pre>014a: <pre><p>Not 100% sure what you&#39;re asking, but:</p> <p>All GraphQL servers support <a href="http://graphql.org/learn/introspection/" rel="nofollow">an introspection query</a> to determine the types, queries, mutations, etc that it offers.</p> <p>Forming structs based on the generic response of a GraphQL server is impossible, even if you know all of the types ahead of time. Main reason being that queries allow you to remap field names at will. You can certainly form structs based on the responses of specific pre-compiled queries.</p></pre>wy100101: <pre><p>I was looking for something that would be able to work generically with any GraphQL server where I would just startup my client with the GraphQL endpoint and then explore the queries it supports and play with those. That feels like it needs to be able to create queries and handle responses dynamically.</p></pre>014a: <pre><p>If you&#39;re writing this because you think it doesn&#39;t exist, I&#39;d point you to <a href="https://github.com/graphcool/graphql-playground" rel="nofollow">Graphql Playground</a> or <a href="https://github.com/skevy/graphiql-app" rel="nofollow">Graphiql-app</a>.</p> <p>If its just for fun or practice; you&#39;re gonna have to do something like</p> <ol> <li><p>Load all of the types, queries, and mutation the server supports into structures so you know how to parse responses, via introspection.</p></li> <li><p>Use map[string]interface{} and traverse it via the structures you have from (1) at runtime.</p></li> </ol></pre>wy100101: <pre><p>OK, I kind of assumed it was something along those lines, but I wanted to make sure I was missing a language feature.</p></pre>

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

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