-
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
refactor: subscribe: introduce buildPerEventExecutionContext
#3639
Conversation
✅ Deploy Preview for compassionate-pike-271cb3 ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
Hi @yaacovCR, I'm @github-actions bot happy to help you with this PR 👋 Supported commandsPlease post this commands in separate comments and only one per comment:
|
d566dfe
to
c0a2b54
Compare
Not the best diagrams (fault my own) screenshotted from yEd: Original:New:Note that per event, we are now no longer re-performing the portions of |
Note that these changes do imply that the But that is already implied by the passing of These functions may be renamed/reorganized in later refactoring! |
Offline, @IvanGoncharov added a few notes:
|
I rebased this on top of the simpler changes introduced in #3654 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change solves the real issue.
I don't like some of the solutions here like "executeImpl" or "per even context", but I can't propose any other solution that doesn't involve bigger refactoring.
P.S. I'm working on such bigger refactoring in parallel
= introduces `buildPerEventExecutionContext` that creates an `ExecutionContext` for each subscribe event from the original `ExecutionContext` used to create the event stream = `subscribe` now directly builds the `ExecutionContext` instead of relying on `createSourceEventStream` = introduces `createSourceEventStreamImpl` and `executeImpl` functions that operate on the built `ExecutionContext` rather the `ExecutionArgs` = `subscribe` calls the `createSourceEventStreamImpl` function on the original context and eventuallys calls `executeImpl` on the per event context created by `buildEventExecutionContext`. Motivation: 1. remove unnecessary `buildExecutionContext` call, reducing duplicate work 2. paves the way for easily enhancing the `buildPerEventExecutionContext` to add a new `perEventContextFactory` argument to augment the context argument passed to resolvers as need per event. depends on graphql#3638
...now that subscribe and createSourceEventStream both call buildExecutionContext, build errors must be tested separately
The `execute`/`executeImpl` and `createSourceEventStream`/`createSourceEventStreamImpl` functions follow the same basic pattern of building the contet and using it to run a function. This PR extracts that pattern into a separate function. For good measure, the same pattern in applied to the soon-to-be-deprecated `subscribe` function. Hheavier refactoring is on the way from @IvanGoncharov (see #3639 (review)), but in the meantime, this consolidates the common pattern without any breaking changes.
The `execute`/`executeImpl` and `createSourceEventStream`/`createSourceEventStreamImpl` functions follow the same basic pattern of building the contet and using it to run a function. This PR extracts that pattern into a separate function. For good measure, the same pattern in applied to the soon-to-be-deprecated `subscribe` function. Hheavier refactoring is on the way from @IvanGoncharov (see graphql#3639 (review)), but in the meantime, this consolidates the common pattern without any breaking changes.
The `execute`/`executeImpl` and `createSourceEventStream`/`createSourceEventStreamImpl` functions follow the same basic pattern of building the contet and using it to run a function. This PR extracts that pattern into a separate function. For good measure, the same pattern in applied to the soon-to-be-deprecated `subscribe` function. Hheavier refactoring is on the way from @IvanGoncharov (see graphql#3639 (review)), but in the meantime, this consolidates the common pattern without any breaking changes.
= introduces
buildPerEventExecutionContext
that creates anExecutionContext
for each subscribe event from the originalExecutionContext
used to create the event stream=
subscribe
now directly builds theExecutionContext
instead of relying oncreateSourceEventStream
= introduces
createSourceEventStreamImpl
andexecuteImpl
functions that operate on the builtExecutionContext
rather theExecutionArgs
=
subscribe
calls thecreateSourceEventStreamImpl
function on the original context and eventuallys callsexecuteImpl
on the per event context created bybuildEventExecutionContext
.Motivation:
buildExecutionContext
call, reducing duplicate workbuildPerEventExecutionContext
to add a newperEventContextFactory
argument to augment the context argument passed to resolvers as need per event.depends on #3654