(ctx context.Context, query schema.Query)
| 174 | } |
| 175 | |
| 176 | func (qr *customDQLQueryResolver) rewriteAndExecute(ctx context.Context, |
| 177 | query schema.Query) *Resolved { |
| 178 | dgraphQueryDuration := &schema.LabeledOffsetDuration{Label: "query"} |
| 179 | ext := &schema.Extensions{ |
| 180 | Tracing: &schema.Trace{ |
| 181 | Execution: &schema.ExecutionTrace{ |
| 182 | Resolvers: []*schema.ResolverTrace{ |
| 183 | {Dgraph: []*schema.LabeledOffsetDuration{dgraphQueryDuration}}, |
| 184 | }, |
| 185 | }, |
| 186 | }, |
| 187 | } |
| 188 | |
| 189 | emptyResult := func(err error) *Resolved { |
| 190 | resolved := EmptyResult(query, err) |
| 191 | resolved.Extensions = ext |
| 192 | return resolved |
| 193 | } |
| 194 | |
| 195 | dgQuery := query.DQLQuery() |
| 196 | args := query.Arguments() |
| 197 | vars := make(map[string]string) |
| 198 | for k, v := range args { |
| 199 | // dgoapi.Request{}.Vars accepts only string values for variables, |
| 200 | // so need to convert all variable values to string |
| 201 | vStr, err := convertScalarToString(v) |
| 202 | if err != nil { |
| 203 | return emptyResult(schema.GQLWrapf(err, "couldn't convert argument %s to string", k)) |
| 204 | } |
| 205 | // the keys in dgoapi.Request{}.Vars are assumed to be prefixed with $ |
| 206 | vars["$"+k] = vStr |
| 207 | } |
| 208 | |
| 209 | queryTimer := newtimer(ctx, &dgraphQueryDuration.OffsetDuration) |
| 210 | queryTimer.Start() |
| 211 | resp, err := qr.executor.Execute(ctx, &dgoapi.Request{Query: dgQuery, Vars: vars, |
| 212 | ReadOnly: true}, nil) |
| 213 | queryTimer.Stop() |
| 214 | |
| 215 | if err != nil { |
| 216 | return emptyResult(schema.GQLWrapf(err, "Dgraph query failed")) |
| 217 | } |
| 218 | ext.TouchedUids = resp.GetMetrics().GetNumUids()[touchedUidsKey] |
| 219 | |
| 220 | var respJson map[string]interface{} |
| 221 | if err = schema.Unmarshal(resp.Json, &respJson); err != nil { |
| 222 | return emptyResult(schema.GQLWrapf(err, "couldn't unmarshal Dgraph result")) |
| 223 | } |
| 224 | |
| 225 | resolved := DataResult(query, respJson, nil) |
| 226 | resolved.Extensions = ext |
| 227 | return resolved |
| 228 | } |
| 229 | |
| 230 | func resolveIntrospection(ctx context.Context, q schema.Query) *Resolved { |
| 231 | data, err := schema.Introspect(q) |
no test coverage detected