Revision c871ecb7e195c597316a12ca7984a19ea360877e authored by Denys Smirnov on 30 June 2019, 20:10:53 UTC, committed by Denys Smirnov on 30 June 2019, 20:10:53 UTC
1 parent c44b804
http.go
package graphql
import (
"context"
"encoding/json"
"io"
"github.com/dennwc/graphql/gqlerrors"
"github.com/cayleygraph/cayley/graph"
"github.com/cayleygraph/cayley/query"
)
type httpResult struct {
Data interface{} `json:"data"`
Errors []gqlerrors.FormattedError `json:"errors,omitempty"`
}
func httpError(w query.ResponseWriter, err error) {
json.NewEncoder(w).Encode(httpResult{
Errors: []gqlerrors.FormattedError{{
Message: err.Error(),
}},
})
}
func httpQuery(ctx context.Context, qs graph.QuadStore, w query.ResponseWriter, r io.Reader) {
q, err := Parse(r)
if err != nil {
httpError(w, err)
return
}
m, err := q.Execute(ctx, qs)
if err != nil {
httpError(w, err)
return
}
json.NewEncoder(w).Encode(httpResult{Data: m})
}
![swh spinner](/static/img/swh-spinner.gif)
Computing file changes ...