MCPcopy
hub / github.com/dgraph-io/dgraph / rewriteAndExecute

Method rewriteAndExecute

graphql/resolve/mutation.go:211–527  ·  view source on GitHub ↗
(
	ctx context.Context,
	mutation schema.Mutation)

Source from the content-addressed store, hash-verified

209}
210
211func (mr *dgraphResolver) rewriteAndExecute(
212 ctx context.Context,
213 mutation schema.Mutation) (*Resolved, bool) {
214 var mutResp, qryResp *dgoapi.Response
215 req := &dgoapi.Request{}
216 commit := false
217
218 defer func() {
219 if !commit && mutResp != nil && mutResp.Txn != nil {
220 mutResp.Txn.Aborted = true
221 _, err := mr.executor.CommitOrAbort(ctx, mutResp.Txn)
222 if err != nil {
223 glog.Errorf("Error occurred while aborting transaction: %s", err)
224 }
225 }
226 }()
227
228 dgraphPreMutationQueryDuration := &schema.LabeledOffsetDuration{Label: "preMutationQuery"}
229 dgraphMutationDuration := &schema.LabeledOffsetDuration{Label: "mutation"}
230 dgraphPostMutationQueryDuration := &schema.LabeledOffsetDuration{Label: "query"}
231 ext := &schema.Extensions{
232 Tracing: &schema.Trace{
233 Execution: &schema.ExecutionTrace{
234 Resolvers: []*schema.ResolverTrace{
235 {
236 Dgraph: []*schema.LabeledOffsetDuration{
237 dgraphPreMutationQueryDuration,
238 dgraphMutationDuration,
239 dgraphPostMutationQueryDuration,
240 },
241 },
242 },
243 },
244 },
245 }
246
247 emptyResult := func(err error) *Resolved {
248 return &Resolved{
249 // all the standard mutations are nullable objects, so Data should pretty-much be
250 // {"mutAlias":null} everytime.
251 Data: mutation.NullResponse(),
252 Field: mutation,
253 // there is no completion down the pipeline, so error's path should be prepended with
254 // mutation's alias before returning the response.
255 Err: schema.PrependPath(err, mutation.ResponseName()),
256 Extensions: ext,
257 }
258 }
259
260 // upserts stores rewritten []*UpsertMutation by Rewrite function. These mutations
261 // are then executed and the results processed and returned.
262 var upserts []*UpsertMutation
263 var err error
264 // queries stores rewritten []*dql.GraphQuery by RewriteQueries function. These queries
265 // are then executed and the results are processed
266 var queries []*dql.GraphQuery
267 var filterTypes []string
268 queries, filterTypes, err = mr.mutationRewriter.RewriteQueries(ctx, mutation)

Callers 1

ResolveMethod · 0.95

Calls 15

PrependPathFunction · 0.92
GQLWrapfFunction · 0.92
AsStringFunction · 0.92
GQLWrapLocationfFunction · 0.92
AssertTrueFunction · 0.92
HasStringFunction · 0.92
IsGqlErrorListFunction · 0.92
AppendGQLErrsFunction · 0.92
newtimerFunction · 0.85
completeMutationResultFunction · 0.85
queryAuthSelectorFunction · 0.85
copyTypeMapFunction · 0.85

Tested by

no test coverage detected