Working with nested types in graphql

agolangf · · 403 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I&#39;ve recently switched to a better graphql implementation (playlyfe/graphql), but on their github page seems to be no documentation at all. I&#39;ve been trying to figure it out for my own, but nothing seems to work. I have the following code:</p> <pre><code>package main import ( &#34;net/http&#34; &#34;github.com/krypton97/HandleGraphQL&#34; &#34;github.com/playlyfe/go-graphql&#34; ) var Salutations = map[string]string{ &#34;ro&#34;: &#34;Salut&#34;, &#34;en&#34;: &#34;Hello&#34;, &#34;fr&#34;: &#34;Oui&#34;, &#34;it&#34;: &#34;Ciao&#34;, &#34;de&#34;: &#34;Hallo&#34;, } var Students = map[string]map[string]interface{}{ &#34;1&#34;: { &#34;typename&#34;: &#34;Student&#34;, &#34;name&#34;: &#34;alex&#34;, &#34;age&#34;: 18, &#34;id&#34;: &#34;1&#34;, }, &#34;2&#34;: { &#34;typename&#34;: &#34;Student&#34;, &#34;name&#34;: &#34;bob&#34;, &#34;age&#34;: 19, &#34;id&#34;: &#34;2&#34;, }, &#34;3&#34;: { &#34;__typename&#34;: &#34;Student&#34;, &#34;name&#34;: &#34;john&#34;, &#34;age&#34;: 20, &#34;id&#34;: &#34;3&#34;, }, } func main() { schema := ` type StudentInfo { name: String age: Int id: String } type Student{ student(id: String!) : StudentInfo } type QueryRoot { hello: String salutation(lang: String!): String students: Student } ` resolvers := map[string]interface{}{} resolvers[&#34;QueryRoot/hello&#34;] = func(params *graphql.ResolveParams) (interface{}, error) { return &#34;world&#34;, nil } resolvers[&#34;QueryRoot/salutation&#34;] = func(params *graphql.ResolveParams) (interface{}, error) { return Salutations[params.Args[&#34;lang&#34;].(string)], nil } resolvers[&#34;QueryRoot/students&#34;] = func(params *graphql.ResolveParams) (interface{}, error) { return Students, nil } resolvers[&#34;Student&#34;] = func(params *graphql.ResolveParams) (interface{}, error) { return Students[params.Args[&#34;id&#34;].(string)], nil } executor, err := graphql.NewExecutor(schema, &#34;QueryRoot&#34;, &#34;&#34;, resolvers) if err != nil { panic(err) } api := handler.New(&amp;handler.Config{ Executor: executor, Context: &#34;&#34;, Pretty: true, }) http.Handle(&#34;/graphql&#34;, api) http.ListenAndServe(&#34;:3000&#34;, nil) } </code></pre> <p>Looking to get this working out, but can&#39;t find out anything.</p> <hr/>**评论:**<br/><br/>HectorJ: <pre><blockquote> <p>better graphql implementation</p> </blockquote> <p> </p> <blockquote> <p>no documentation at all</p> </blockquote> <p> </p> <blockquote> <p>nothing seems to work</p> </blockquote></pre>shark1337: <pre><p>What do you mean??</p></pre>natdm: <pre><p>He is pointing out your &#39;better&#39; implementation that does not have any documentation, and you can&#39;t get it to work (due to possibly no documentation) might not actually be better.</p></pre>

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

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