MCPcopy
hub / github.com/dosco/graphjin / explainQueryForDatabase

Method explainQueryForDatabase

core/api.go:2225–2286  ·  view source on GitHub ↗
(database, query string, vars json.RawMessage, role string)

Source from the content-addressed store, hash-verified

2223}
2224
2225func (gj *graphjinEngine) explainQueryForDatabase(database, query string, vars json.RawMessage, role string) (*QueryExplanation, error) {
2226 if !gj.anyDatabaseReady() {
2227 return nil, fmt.Errorf("schema not initialized")
2228 }
2229
2230 dbCtx, ok := gj.GetDatabase(database)
2231 if !ok {
2232 return nil, fmt.Errorf("database not found: %s", database)
2233 }
2234
2235 queryBytes := []byte(query)
2236 h, err := graph.FastParseBytes(queryBytes)
2237 if err != nil {
2238 return &QueryExplanation{
2239 Database: database,
2240 Errors: []string{fmt.Sprintf("parse error: %s", err.Error())},
2241 }, nil
2242 }
2243
2244 r := gj.newGraphqlReq(nil, h.Operation, h.Name, queryBytes, vars)
2245 s, err := newGState(context.Background(), gj, r)
2246 if err != nil {
2247 return &QueryExplanation{
2248 Database: database,
2249 Errors: []string{fmt.Sprintf("state error: %s", err.Error())},
2250 }, nil
2251 }
2252 if role != "" {
2253 s.role = role
2254 }
2255
2256 st := stmt{role: s.role}
2257 var found bool
2258 if st.roc, found = gj.roles[s.role]; !found {
2259 return &QueryExplanation{
2260 Operation: h.Operation,
2261 Name: h.Name,
2262 Role: s.role,
2263 Database: database,
2264 Errors: []string{fmt.Sprintf(`roles '%s' not defined in c.gj.config`, s.role)},
2265 }, nil
2266 }
2267
2268 var compileVars map[string]json.RawMessage
2269 if len(s.r.aschema) != 0 {
2270 compileVars = s.r.aschema
2271 } else {
2272 compileVars = s.vmap
2273 }
2274
2275 if err := s.compileForDatabase(st, compileVars, dbCtx); err != nil {
2276 return &QueryExplanation{
2277 Operation: h.Operation,
2278 Name: h.Name,
2279 Role: s.role,
2280 Database: database,
2281 Errors: []string{err.Error()},
2282 }, nil

Callers 1

Calls 7

anyDatabaseReadyMethod · 0.95
GetDatabaseMethod · 0.95
newGraphqlReqMethod · 0.95
newGStateFunction · 0.85
compileForDatabaseMethod · 0.80
ErrorMethod · 0.65

Tested by

no test coverage detected