-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(GraphQL::Batch::SetupMultiplex) use multiplex instrumentation to…
… share a batching context (#57)
- Loading branch information
1 parent
bbe92c3
commit 69a14c5
Showing
3 changed files
with
66 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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,14 @@ | ||
module GraphQL::Batch | ||
module SetupMultiplex | ||
extend self | ||
|
||
def before_multiplex(multiplex) | ||
raise NestedError if GraphQL::Batch::Executor.current | ||
GraphQL::Batch::Executor.current = GraphQL::Batch::Executor.new | ||
end | ||
|
||
def after_multiplex(multiplex) | ||
GraphQL::Batch::Executor.current = nil | ||
end | ||
end | ||
end |
This file contains 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,46 @@ | ||
require_relative 'test_helper' | ||
|
||
class GraphQL::MultiplexTest < Minitest::Test | ||
attr_reader :queries | ||
|
||
def setup | ||
@queries = [] | ||
QueryNotifier.subscriber = ->(query) { @queries << query } | ||
end | ||
|
||
def teardown | ||
QueryNotifier.subscriber = nil | ||
end | ||
|
||
def test_batched_find_by_id | ||
query_string = <<-GRAPHQL | ||
query FetchTwoProducts($id1: ID!, $id2: ID!){ | ||
first: product(id: $id1) { id, title } | ||
second: product(id: $id2) { id, title } | ||
} | ||
GRAPHQL | ||
|
||
results = Schema.multiplex([ | ||
{ query: query_string, variables: { "id1" => "1", "id2" => "2"} }, | ||
{ query: query_string, variables: { "id1" => "1", "id2" => "3"}}, | ||
]) | ||
|
||
expected_1 = { | ||
"data" => { | ||
"first" => { "id" => "1", "title" => "Shirt" }, | ||
"second" => { "id" => "2", "title" => "Pants" }, | ||
} | ||
} | ||
|
||
expected_2 = { | ||
"data" => { | ||
"first" => { "id" => "1", "title" => "Shirt" }, | ||
"second" => { "id" => "3", "title" => "Sweater" }, | ||
} | ||
} | ||
|
||
assert_equal expected_1, results.first | ||
assert_equal expected_2, results.last | ||
assert_equal ["Product/1,2,3"], queries | ||
end | ||
end |