graphql-hive / graphql-hive/envelop

Results modified in setResultAndStopExecution unavailable to onExecuteDone hook which prevents hit cached response from being logged

Open
#1,156 1 comment 2 reactions 0 assignees View on GitHub
kind/bug
Dominant language
No language data
Stars
827
Forks
132
PR merge metrics
No merged PRs in 30d

Description

When using the Response Cache plug-in, when an cached response is returned, the exec union phase "short-circuits" to return the data:

See: https://github.com/dotansimha/envelop/blob/92a7ff710efc7abf19cd0bf8e412328e81103217/packages/plugins/response-cache/src/plugin.ts#L260

```ts
if ((enabled?.(ctx.args.contextValue) ?? true) === true) {
const cachedResponse = await cache.get(operationId);

if (cachedResponse != null) {
if (includeExtensionMetadata) {
ctx.setResultAndStopExecution({
...cachedResponse,
extensions: {
responseCache: {
hit: true,
},
},
});
} else {
ctx.setResultAndStopExecution(cachedResponse);
}
return;
}
}
```

Because `setResultAndStopExecution` is used and also the result is modified by adding extension info (hit, miss, etc) if another plugin that wants to log the extension data on the result (to see if it was a hit) one cannot.

This is because in the case of a miss, the execution phase complete fully and one can retrieve in `onExecuteDone` phase the extension data and see it was a miss.

But, with `setResultAndStopExecution` the `onExecuteDone` is never reached, but bypassed

https://github.com/dotansimha/envelop/blob/92a7ff710efc7abf19cd0bf8e412328e81103217/packages/core/src/orchestrator.ts#L423

and

https://github.com/dotansimha/envelop/blob/92a7ff710efc7abf19cd0bf8e412328e81103217/packages/core/src/orchestrator.ts#L444

as in

```ts
if (stopCalled) {
return result!; <<--short circuit
}

if (after) {
if (after.onExecuteDone) {
afterCalls.push(after.onExecuteDone); <<-- never get here
}
if (after.onResolverCalled) {
onResolversHandlers.push(after.onResolverCalled);
}
}
```

My issue/question is:

Is the another hook that could be added like `OnExecuteStoppedHook` that one could then use in a plugin to get that modified result and be able to see that the response result was a "hit".

Is there another phase where the complete and final result response is available even after execute is done?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the cited stopCalled branch in packages/core/src/orchestrator.ts and the cached-response path in packages/plugins/response-cache/src/plugin.ts. Trace how stopped and normal executions expose results to hooks; done would mean a documented way for a logging plugin to observe the final cached result, including the responseCache hit metadata.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.