-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(subscribe): allow providing custom execute function for subscribe #3071
Conversation
|
cfedc4c
to
0feaedd
Compare
I too have a usecase where I need to invalidate dataloader cache after each execution result. This will be quite helpful. |
@97amarnathk feel also free to check out n1ru4l/envelop#183 which kind of tries to work around this limitation |
Interesting. @IvanGoncharov can you please review this PR? :) |
Since this will probably not be reviewed or released for a long-time, I built a solution that can be easily installed as a envelop plugin: https://www.envelop.dev/docs/guides/resolving-subscription-data-loader-caching-issues |
Question: Is there any reason this does not get merged? |
to safely export buildExecutionContext() as validateExecutionArgs() motivation: this will allow us to: 1. export `executeOperation()` and `executeSubscription()` for those who would like to use directly. 2. add a `perEventExecutor` option to `ExecutionArgs` that allows one to pass a custom context for execution of each execution event, with the opportunity to clean up the context on return, a la #2485 and #3071, addressing #894, which would not require re-coercion of variables. The signature of the `perEventExecutor` option would be: ```ts type SubscriptionEventExecutor = ( validatedExecutionArgs: ValidatedExecutionArgs): PromiseOrValue<ExecutionResult> ``` rather than: ```ts type SubscriptionEventExecutor = ( executionArgs: ExecutionArgs): PromiseOrValue<ExecutionResult> ``` This might be a first step to integrating `subscribe()` completely into `execute()` (see: #3644) but is also a reasonable stopping place.
#4211 solves this slightly differently for v17, avoiding revalidation of arguments/recoercion of variables |
This allows solving #894 and enisdenjo/graphql-ws#180 in user-land by providing a custom execute function for
subscribe
, that creates thecontextValue
per published value (for eachexecute
invocation), instead of once for the whole subscription.