Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions execution/engine/execution_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ func (e *internalExecutionContext) setVariables(variables []byte) {
}
}

func (e *internalExecutionContext) reset() {
e.resolveContext.Free()
}

type ExecutionEngine struct {
logger abstractlogger.Logger
config Configuration
Expand Down Expand Up @@ -238,7 +234,7 @@ func (e *ExecutionEngine) Execute(ctx context.Context, operation *graphql.Reques
return err
}
if resp != nil {
operation.ComputeActualCost(costCalculator, e.config.plannerConfig, resp.ActualListSizes)
operation.ComputeActualCost(costCalculator, e.config.plannerConfig, execContext.resolveContext.ActualListSizes)
}
return nil
case *plan.SubscriptionResponsePlan:
Expand Down
6 changes: 6 additions & 0 deletions v2/pkg/engine/resolve/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ type Context struct {

SubgraphHeadersBuilder SubgraphHeadersBuilder

// ActualListSizes is populated by the resolver after resolution completes,
// before the response body is written. Maps JSON path to actual list size.
// Used to compute the actual cost.
ActualListSizes map[string]int
Comment thread
coderabbitai[bot] marked this conversation as resolved.

// GetDeduplicationData is called after the leader of an inbound singleflight request
// finishes resolving. It extracts data from the leader's context (e.g. accumulated
// response headers) that should be shared with all follower requests.
Expand Down Expand Up @@ -315,6 +320,7 @@ func (c *Context) Free() {
c.LoaderHooks = nil
c.GetDeduplicationData = nil
c.SetDeduplicationData = nil
c.ActualListSizes = nil
}

type traceStartKey struct{}
Expand Down
10 changes: 2 additions & 8 deletions v2/pkg/engine/resolve/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,6 @@ type GraphQLResolveInfo struct {

// ResolveDeduplicated indicates whether the resolution of the entire operation was deduplicated via single flight
ResolveDeduplicated bool

// ActualListSizes maps the JSON path to the actual list size in the response.
// Used to compute the actual cost.
ActualListSizes map[string]int
}

func (r *Resolver) ResolveGraphQLResponse(ctx *Context, response *GraphQLResponse, data []byte, writer io.Writer) (*GraphQLResolveInfo, error) {
Expand Down Expand Up @@ -354,7 +350,7 @@ func (r *Resolver) ResolveGraphQLResponse(ctx *Context, response *GraphQLRespons
return nil, err
}

resp.ActualListSizes = t.resolvable.actualListSizes
ctx.ActualListSizes = t.resolvable.actualListSizes

return resp, err
}
Expand Down Expand Up @@ -415,6 +411,7 @@ func (r *Resolver) ArenaResolveGraphQLResponse(ctx *Context, response *GraphQLRe
r.responseBufferPool.Release(responseArena)
return nil, err
}
ctx.ActualListSizes = t.resolvable.actualListSizes

// first release resolverArena
// all data is resolved and written into the response arena
Expand All @@ -436,9 +433,6 @@ func (r *Resolver) ArenaResolveGraphQLResponse(ctx *Context, response *GraphQLRe
// all data is written to the client
// we're safe to release our buffer
r.responseBufferPool.Release(responseArena)

resp.ActualListSizes = t.resolvable.actualListSizes

return resp, err
}

Expand Down