如何在go代码中调用graphql解析器

时间:2018-11-23 03:11:02

标签: go graphql

我尝试了此代码

url := "http://142.77.221.41:8000/graphql"
query := `{
     hello(theme:"HELLO WORLD", html: "<h1>hello</h1>", recipientList: "hello@mail.ua") {theme, html, recipientList} 
}`

body := strings.NewReader(`{"query":` + query + `}`)
//json := `{"query":` + strconv.QuoteToASCII(query) + `}`
req, err := http.NewRequest("POST", url, body)
if err != nil {
    fmt.Println(err)
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
    fmt.Println(err)
}
fmt.Println(resp.Status)

它发送

  

500内部服务器错误

但是当我去http://142.77.221.41:8000/graphql并在操场上键入相同的查询时,它工作正常

0 个答案:

没有答案