<p>I've recently switched to a better graphql implementation (playlyfe/graphql), but on their github page seems to be no documentation at all. I'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 (
"net/http"
"github.com/krypton97/HandleGraphQL"
"github.com/playlyfe/go-graphql"
)
var Salutations = map[string]string{
"ro": "Salut",
"en": "Hello",
"fr": "Oui",
"it": "Ciao",
"de": "Hallo",
}
var Students = map[string]map[string]interface{}{
"1": { "typename": "Student", "name": "alex", "age": 18, "id": "1", },
"2": { "typename": "Student", "name": "bob", "age": 19, "id": "2", },
"3": { "__typename": "Student", "name": "john", "age": 20, "id": "3", },
}
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["QueryRoot/hello"] = func(params *graphql.ResolveParams) (interface{}, error) {
return "world", nil
}
resolvers["QueryRoot/salutation"] = func(params *graphql.ResolveParams) (interface{}, error) {
return Salutations[params.Args["lang"].(string)], nil
}
resolvers["QueryRoot/students"] = func(params *graphql.ResolveParams) (interface{}, error) {
return Students, nil
}
resolvers["Student"] = func(params *graphql.ResolveParams) (interface{}, error) {
return Students[params.Args["id"].(string)], nil
}
executor, err := graphql.NewExecutor(schema, "QueryRoot", "", resolvers)
if err != nil {
panic(err)
}
api := handler.New(&handler.Config{
Executor: executor,
Context: "",
Pretty: true,
})
http.Handle("/graphql", api)
http.ListenAndServe(":3000", nil)
}
</code></pre>
<p>Looking to get this working out, but can'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 'better' implementation that does not have any documentation, and you can't get it to work (due to possibly no documentation) might not actually be better.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传