Skip to content

Commit

Permalink
Merge branch 'master' into postgresql
Browse files Browse the repository at this point in the history
  • Loading branch information
Willianvdv committed Jun 29, 2017
2 parents 6e1de44 + e4d4439 commit 1a30f75
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 12 deletions.
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ gemspec
gem 'ruby-prof', :platform => :ruby
gem 'sqlite3', :platform => :ruby
gem 'pg', :platform => :ruby

gem 'pry'
gem 'pry-stack_explorer', :platform => :ruby
gem 'activerecord-jdbcsqlite3-adapter', :platform => :jruby
8 changes: 6 additions & 2 deletions guides/css/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ $muted-color: #777777;
$subtle-color: #aaaaaa;
$font: 'Rubik', sans-serif;
$font-color: black;
$code-font: 'Source Sans Pro', monospace;
$code-font: 'Monaco', monospace;

body {
font-family: $font;
Expand Down Expand Up @@ -92,10 +92,14 @@ pre {
overflow-x: scroll;
}

p, li, pre {
p, li {
line-height: 1.3rem;
}

pre {
line-height: 1.4rem;
}

p, ul {
margin-bottom: 10px;
}
Expand Down
11 changes: 6 additions & 5 deletions lib/graphql/execution/multiplex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,18 @@ def initialize(schema:, queries:, context:)
end

class << self
def run_all(schema, query_options, *rest)
def run_all(schema, query_options, *args)
queries = query_options.map { |opts| GraphQL::Query.new(schema, nil, opts) }
run_queries(schema, queries, *rest)
run_queries(schema, queries, *args)
end

# @param schema [GraphQL::Schema]
# @param queries [Array<GraphQL::Query>]
# @param context [Hash]
# @param max_complexity [Integer]
# @param max_complexity [Integer, nil]
# @return [Array<Hash>] One result per query
def run_queries(schema, queries, context: {}, max_complexity: nil)
def run_queries(schema, queries, context: {}, max_complexity: schema.max_complexity)

if has_custom_strategy?(schema)
if queries.length != 1
raise ArgumentError, "Multiplexing doesn't support custom execution strategies, run one query at a time instead"
Expand Down Expand Up @@ -161,7 +162,7 @@ def with_instrumentation(schema, queries, context:, max_complexity:)
end

multiplex_analyzers = schema.multiplex_analyzers
if max_complexity ||= schema.max_complexity
if max_complexity
multiplex_analyzers += [GraphQL::Analysis::MaxQueryComplexity.new(max_complexity)]
end

Expand Down
7 changes: 4 additions & 3 deletions lib/graphql/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ def execute(query_str = nil, **kwargs)
if query_str
kwargs[:query] = query_str
end
all_results = multiplex([kwargs])
# Since we're running one query, don't run a multiplex-level complexity analyzer
all_results = multiplex([kwargs], max_complexity: nil)
all_results[0]
end

Expand All @@ -248,9 +249,9 @@ def execute(query_str = nil, **kwargs)
# @param queries [Array<Hash>] Keyword arguments for each query
# @param context [Hash] Multiplex-level context
# @return [Array<Hash>] One result for each query in the input
def multiplex(*args)
def multiplex(queries, **kwargs)
with_definition_error_check {
GraphQL::Execution::Multiplex.run_all(self, *args)
GraphQL::Execution::Multiplex.run_all(self, queries, **kwargs)
}
end

Expand Down
13 changes: 12 additions & 1 deletion spec/graphql/analysis/max_query_complexity_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
end
end

describe "when complexity is overriden at query-level" do
describe "when max_complexity is decreased at query-level" do
before do
Dummy::Schema.max_complexity = 100
end
Expand All @@ -61,6 +61,17 @@
end
end

describe "when max_complexity is increased at query-level" do
before do
Dummy::Schema.max_complexity = 1
end
let(:result) { Dummy::Schema.execute(query_string, max_complexity: 10) }

it "doesn't error" do
assert_equal nil, result["errors"]
end
end

describe "across a multiplex" do
before do
Dummy::Schema.max_complexity = 9
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
require "graphql"
require "graphql/rake_task"
require "benchmark"
require "pry"
require "minitest/autorun"
require "minitest/focus"
require "minitest/reporters"
Expand Down

0 comments on commit 1a30f75

Please sign in to comment.