Skip to content
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

Closed

Conversation

n1ru4l
Copy link
Contributor

@n1ru4l n1ru4l commented May 10, 2021

This allows solving #894 and enisdenjo/graphql-ws#180 in user-land by providing a custom execute function for subscribe, that creates the contextValue per published value (for each execute invocation), instead of once for the whole subscription.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented May 10, 2021

CLA Signed

The committers are authorized under a signed CLA.

@97amarnathk
Copy link

I too have a usecase where I need to invalidate dataloader cache after each execution result. This will be quite helpful.

@n1ru4l
Copy link
Contributor Author

n1ru4l commented Jun 4, 2021

@97amarnathk feel also free to check out n1ru4l/envelop#183 which kind of tries to work around this limitation

@dotansimha
Copy link
Member

Interesting. @IvanGoncharov can you please review this PR? :)

@dotansimha dotansimha self-requested a review June 30, 2021 10:53
@n1ru4l
Copy link
Contributor Author

n1ru4l commented Jul 25, 2021

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

@pantajoe
Copy link

Question: Is there any reason this does not get merged?
It'd be great to be able to use dataloader's cache again when using subscriptions.

yaacovCR added a commit that referenced this pull request Oct 1, 2024
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.
yaacovCR added a commit that referenced this pull request Oct 6, 2024
by exporting executeSubscriptionEvent()

and adding option for to provide a custom fn

addresses #894

cf. #2485 , #3071
@yaacovCR
Copy link
Contributor

#4211 solves this slightly differently for v17, avoiding revalidation of arguments/recoercion of variables

@yaacovCR yaacovCR closed this Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants