-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Use a queue for execution #5389
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
Open
rmosolgo
wants to merge
38
commits into
master
Choose a base branch
from
run-queue-3
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
1fdc9cd
Start on a run_queue
rmosolgo 9d5b6da
Add resolve_type step
rmosolgo fdbfd2f
Move #run into Result classes
rmosolgo 8f04cc9
Make a RunQueue object
rmosolgo c45f628
support sequential mutation fields
rmosolgo 32ea55c
Fix dataloader integration
rmosolgo c188312
Implement resolve_each
rmosolgo d9f4ebb
Isolate field resolution in step object
rmosolgo 56f38c0
Add some Lazy support
rmosolgo 186e822
Fix inspect output
rmosolgo caa754b
More lazy support, better mutation eager execution
rmosolgo 0f090cc
Move execute field methods into ResultHash
rmosolgo 325d5d8
use self instead of selection result
rmosolgo b233c92
Move resolution code into FieldResolveStep
rmosolgo 8837fa7
Merge branch 'master' into run-queue-3
rmosolgo d3927b8
Add todos
rmosolgo 123bf35
Merge ResolveTypeStep into ResultHash
rmosolgo 898ba4a
Use named states
rmosolgo 6f6c79e
Move authorized into runtime state machine
rmosolgo 466a80c
Move directive resolution into other steps
rmosolgo bdc1b08
Run dataloader if arguments need it
rmosolgo 7f24a79
Start working on dataloader compat
rmosolgo 805605d
Merge branch 'master' into run-queue-3
rmosolgo 96e5d1c
Share a run queue within a multiplex; run steps inside a dataloader job
rmosolgo 46044fa
Support appending callables directly to dataloader
rmosolgo e3cf018
Improve eager continuation in FieldResolveStep, improve dataloader ba…
rmosolgo b1a8c74
Rework to support lazy arguments
rmosolgo 5be5032
Improve current runtime state
rmosolgo f29cac4
Catch unauthorized errors from field resolution
rmosolgo c4ebc03
Support list scoping
rmosolgo a46bcfa
Start merging RunQueue back into Dataloader
rmosolgo 1f5117e
Remove RunQueue
rmosolgo 77e7485
Remove Interpreter::Resolve which is now needless
rmosolgo a2285cd
Merge branch 'master' into run-queue-3
rmosolgo 7812e22
Return NullDataloader which can be frozen
rmosolgo b386fd6
Rescue some errors; hack to fix double-execute
rmosolgo 7d1b365
Keep working
rmosolgo 1cbc1aa
Merge branch 'master' into run-queue-3
rmosolgo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module GraphQL | ||
| class Dataloader | ||
| class FlatDataloader < Dataloader | ||
| def initialize(*) | ||
| # TODO unify the initialization lazies_at_depth | ||
| @lazies_at_depth ||= Hash.new { |h, k| h[k] = [] } | ||
| @steps_to_rerun_after_lazy = [] | ||
| @queue = [] | ||
| end | ||
|
|
||
| def run(trace_query_lazy: nil) | ||
| while @queue.any? | ||
| while (step = @queue.shift) | ||
| step.call | ||
| end | ||
|
|
||
| while @lazies_at_depth&.any? | ||
| smallest_depth = nil | ||
| @lazies_at_depth.each_key do |depth_key| | ||
| smallest_depth ||= depth_key | ||
| if depth_key < smallest_depth | ||
| smallest_depth = depth_key | ||
| end | ||
| end | ||
|
|
||
| if smallest_depth | ||
| with_trace_query_lazy(trace_query_lazy) do | ||
| lazies = @lazies_at_depth.delete(smallest_depth) | ||
| lazies.each(&:value) # resolve these Lazy instances | ||
| end | ||
| end | ||
| end | ||
|
|
||
| if @steps_to_rerun_after_lazy.any? | ||
| current_srrl = @steps_to_rerun_after_lazy.dup | ||
| @steps_to_rerun_after_lazy.clear | ||
| current_srrl.each(&:call) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| def run_isolated | ||
| prev_queue = @queue | ||
| prev_stral = @steps_to_rerun_after_lazy | ||
| prev_lad = @lazies_at_depth | ||
| @steps_to_rerun_after_lazy = [] | ||
| @queue = [] | ||
| @lazies_at_depth = @lazies_at_depth.dup&.clear | ||
| res = nil | ||
| append_job { | ||
| res = yield | ||
| } | ||
| run | ||
| res | ||
| ensure | ||
| @queue = prev_queue | ||
| @steps_to_rerun_after_lazy = prev_stral | ||
| @lazies_at_depth = prev_lad | ||
| end | ||
|
|
||
| def clear_cache; end | ||
|
|
||
| def yield(_source) | ||
| raise GraphQL::Error, "GraphQL::Dataloader is not running -- add `use GraphQL::Dataloader` to your schema to use Dataloader sources." | ||
| end | ||
|
|
||
| def append_job(callable = nil, &block) | ||
| @queue << (callable || block) | ||
| nil | ||
| end | ||
|
|
||
| def with(*) | ||
| raise GraphQL::Error, "GraphQL::Dataloader is not running -- add `use GraphQL::Dataloader` to your schema to use Dataloader sources." | ||
| end | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What, basically, does
run_isolateddo? I remember it's used in context of mutations, so I presume its a serial execution concern? In Cardinal we address serial constraints by splitting up the root into separate execution scopes that run serially, effectively treating it as N separate executions that happen to run in sequence.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.
It's used in a couple of hacky places where, for legacy reasons ([which ones??]), we need a dataloader-enabled code block to return right away, without running any other enqueued work.
Yeah, it seems like initializing a new dataloader, using it for one thing, then discarding it would do. I'll give that a try sometime.