POST Example #420
POST Example #420
Comments
|
You have to unmarshal it yourself, as apparently this library doesn't have that: type postData struct {
Query string `json:"query"`
Operation string `json:"operation"`
Variables map[string]interface{} `json:"variables"`
}
// ...
mux.Post("/graphql", func(w http.ResponseWriter, req *http.Request) {
var p postData
if err := json.NewDecoder(req.Body).Decode(&p); err != nil {
w.WriteHeader(400)
return
}
result := graphql.Do(graphql.Params{
Context: req.Context(),
Schema: schema,
RequestString: p.Query,
VariableValues: p.Variables,
OperationName: p.Operation,
})
if err := json.NewEncoder(w).Encode(result); err != nil {
srv.logger.Debugf("could not write result to response: %s", err)
}
}) |
|
what is the mux variable? Google search for 'golang mux' returns 'gorrilla mux' as a likely candidate, thought the router returned from mux.NewRouter() doesn't have a Post method. |
|
I use Chi, but you can use the Go HTTP server. |
|
Weird to see only Get examples. All implementations are Post (security) . So first thing i did was updating playground to latest https://github.com/graphql/graphql-playground/blob/master/packages/graphql-playground-html/minimal.html and then found the above issue and thought ... |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

How I can send a request by POST-Method with the following shema?
Under examples can I find only GET-Requests!
with :
currently have I a error: "Syntax Error GraphQL request (2:3) Expected Name, found String "query...."
What's my problem? :)
The text was updated successfully, but these errors were encountered: