MCPcopy Index your code
hub / github.com/dosco/graphjin / explainQuery

Method explainQuery

core/api.go:2115–2223  ·  view source on GitHub ↗

explainQuery compiles a query through the full pipeline without executing it.

(query string, vars json.RawMessage, role string)

Source from the content-addressed store, hash-verified

2113
2114// explainQuery compiles a query through the full pipeline without executing it.
2115func (gj *graphjinEngine) explainQuery(query string, vars json.RawMessage, role string) (*QueryExplanation, error) {
2116 if !gj.anyDatabaseReady() {
2117 return nil, fmt.Errorf("schema not initialized")
2118 }
2119
2120 queryBytes := []byte(query)
2121
2122 h, err := graph.FastParseBytes(queryBytes)
2123 if err != nil {
2124 return &QueryExplanation{
2125 Errors: []string{fmt.Sprintf("parse error: %s", err.Error())},
2126 }, nil
2127 }
2128
2129 r := gj.newGraphqlReq(nil, h.Operation, h.Name, queryBytes, vars)
2130
2131 s, err := newGState(context.Background(), gj, r)
2132 if err != nil {
2133 return &QueryExplanation{
2134 Errors: []string{fmt.Sprintf("state error: %s", err.Error())},
2135 }, nil
2136 }
2137
2138 if role != "" {
2139 s.role = role
2140 }
2141
2142 err = s.compileQueryForRole()
2143 if err != nil {
2144 return &QueryExplanation{
2145 Operation: h.Operation,
2146 Name: h.Name,
2147 Role: s.role,
2148 Errors: []string{err.Error()},
2149 }, nil
2150 }
2151
2152 // Handle multi-DB queries by compiling each per-database sub-query
2153 if s.multiDB && len(s.dbGroups) > 0 {
2154 exp := &QueryExplanation{
2155 Operation: h.Operation,
2156 Name: h.Name,
2157 Role: s.role,
2158 MultiDatabase: true,
2159 }
2160 for dbName, rootFields := range s.dbGroups {
2161 subExp := gj.explainForDatabase(&s, dbName, rootFields)
2162 exp.Queries = append(exp.Queries, *subExp)
2163 }
2164 return exp, nil
2165 }
2166
2167 exp := &QueryExplanation{
2168 CompiledQuery: s.cs.st.sql,
2169 Operation: s.cs.st.qc.Type.String(),
2170 Name: s.cs.st.qc.Name,
2171 Role: s.cs.st.role,
2172 Database: s.database,

Callers 1

ExplainQueryMethod · 0.80

Calls 8

anyDatabaseReadyMethod · 0.95
newGraphqlReqMethod · 0.95
explainForDatabaseMethod · 0.95
newGStateFunction · 0.85
compileQueryForRoleMethod · 0.80
ParamsMethod · 0.80
ErrorMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected