MCPcopy
hub / github.com/cayleygraph/cayley / ServeV1Shape

Method ServeV1Shape

internal/http/query.go:144–184  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request, params httprouter.Params)

Source from the content-addressed store, hash-verified

142}
143
144func (api *API) ServeV1Shape(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
145 ctx, cancel := api.contextForRequest(r)
146 defer cancel()
147 select {
148 case <-ctx.Done():
149 jsonResponse(w, http.StatusBadRequest, "Cancelled")
150 return
151 default:
152 }
153 h, err := api.GetHandleForRequest(r)
154 if err != nil {
155 jsonResponse(w, http.StatusBadRequest, err)
156 return
157 }
158 l := query.GetLanguage(params.ByName("query_lang"))
159 if l == nil {
160 jsonResponse(w, http.StatusBadRequest, "Unknown query language.")
161 return
162 } else if l.HTTP == nil {
163 jsonResponse(w, http.StatusBadRequest, "HTTP interface is not supported for this query language.")
164 return
165 }
166 ses := l.HTTP(h.QuadStore)
167 bodyBytes, err := ioutil.ReadAll(r.Body)
168 if err != nil {
169 jsonResponse(w, http.StatusBadRequest, err)
170 return
171 }
172 code := string(bodyBytes)
173
174 output, err := GetQueryShape(code, ses)
175 if err == query.ErrParseMore {
176 jsonResponse(w, http.StatusBadRequest, "Incomplete data?")
177 return
178 } else if err != nil {
179 w.WriteHeader(http.StatusBadRequest)
180 WriteError(w, err)
181 return
182 }
183 w.Write(output)
184}

Callers

nothing calls this directly

Calls 8

contextForRequestMethod · 0.95
GetHandleForRequestMethod · 0.95
GetLanguageFunction · 0.92
GetQueryShapeFunction · 0.85
WriteErrorFunction · 0.85
jsonResponseFunction · 0.70
WriteHeaderMethod · 0.65
WriteMethod · 0.65

Tested by

no test coverage detected