Skip to content

Commit

Permalink
Address Abhimanyu's comments
Browse files Browse the repository at this point in the history
  • Loading branch information
vmrajas committed Mar 24, 2021
1 parent 97f18ec commit ee6dd6c
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions graphql/resolve/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,20 +472,6 @@ func (r *RequestResolver) Resolve(ctx context.Context, gqlReq *schema.Request) (
}

startTime := time.Now()
ctx = context.WithValue(ctx, resolveStartTime, startTime)

// Pass in GraphQL @auth information
ctx, err := r.schema.Meta().AuthMeta().AttachAuthorizationJwt(ctx, gqlReq.Header)
if err != nil {
return schema.ErrorResponse(err)
}

ctx = x.AttachJWTNamespace(ctx)
op, err := r.schema.Operation(gqlReq)
if err != nil {
return schema.ErrorResponse(err)
}

resp = &schema.Response{
Extensions: &schema.Extensions{
Tracing: &schema.Trace{
Expand All @@ -495,10 +481,33 @@ func (r *RequestResolver) Resolve(ctx context.Context, gqlReq *schema.Request) (
},
}
defer func() {
// Panic Handler for mutation. This ensures that the mutation which causes panic
// gets logged in Alpha logs. This panic handler overrides the default Panic Handler
// used in recoveryHandler in admin/http.go
defer api.PanicHandler(
func(err error) {
resp.Errors = schema.AsGQLErrors(schema.AppendGQLErrs(resp.Errors, err))
}, gqlReq.Query)

endTime := time.Now()
resp.Extensions.Tracing.EndTime = endTime.Format(time.RFC3339Nano)
resp.Extensions.Tracing.Duration = endTime.Sub(startTime).Nanoseconds()
}()
ctx = context.WithValue(ctx, resolveStartTime, startTime)

// Pass in GraphQL @auth information
ctx, err := r.schema.Meta().AuthMeta().AttachAuthorizationJwt(ctx, gqlReq.Header)
if err != nil {
resp.Errors = schema.AsGQLErrors(err)
return
}

ctx = x.AttachJWTNamespace(ctx)
op, err := r.schema.Operation(gqlReq)
if err != nil {
resp.Errors = schema.AsGQLErrors(err)
return
}

if glog.V(3) {
// don't log the introspection queries they are sent too frequently
Expand Down Expand Up @@ -563,13 +572,6 @@ func (r *RequestResolver) Resolve(ctx context.Context, gqlReq *schema.Request) (
}
resolveQueries()
case op.IsMutation():
// Panic Handler for mutation. This ensures that the mutation which causes panic
// gets logged in Alpha logs. This panic handler overrides the default Panic Handler
// used in recoveryHandler in admin/http.go
defer api.PanicHandler(
func(err error) {
resp.Errors = schema.AsGQLErrors(schema.AppendGQLErrs(resp.Errors, err))
}, gqlReq.Query)
// A mutation operation can contain any number of mutation fields. Those should be executed
// serially.
// (spec https://graphql.github.io/graphql-spec/June2018/#sec-Normal-and-Serial-Execution)
Expand Down

0 comments on commit ee6dd6c

Please sign in to comment.