Skip to content

Commit 9737c9b

Browse files
committed
small cleanups.
1 parent 8e8c6f3 commit 9737c9b

File tree

11 files changed

+22
-22
lines changed

11 files changed

+22
-22
lines changed

lib/graphql/stitching/client.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def initialize(locations: nil, supergraph: nil, composer_options: {})
2525
raise ArgumentError, "Cannot provide both locations and a supergraph."
2626
elsif supergraph && !supergraph.is_a?(Supergraph)
2727
raise ArgumentError, "Provided supergraph must be a GraphQL::Stitching::Supergraph instance."
28-
elsif supergraph && composer_options.any?
28+
elsif supergraph && !composer_options.empty?
2929
raise ArgumentError, "Cannot provide composer options with a pre-built supergraph."
3030
elsif supergraph
3131
supergraph
@@ -50,7 +50,7 @@ def execute(raw_query = nil, query: nil, variables: nil, operation_name: nil, co
5050

5151
if validate
5252
validation_errors = request.validate
53-
return error_result(request, validation_errors) if validation_errors.any?
53+
return error_result(request, validation_errors) unless validation_errors.empty?
5454
end
5555

5656
load_plan(request)

lib/graphql/stitching/composer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ def build_merged_arguments(type_name, members_by_location, owner, field_name: ni
423423
memo[location] = argument.default_value
424424
end
425425

426-
if default_values_by_location.any?
426+
unless default_values_by_location.empty?
427427
kwargs[:default_value] = @default_value_merger.call(default_values_by_location, {
428428
type_name: type_name,
429429
field_name: field_name,

lib/graphql/stitching/composer/type_resolver_config.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class TypeResolverConfig
88

99
class << self
1010
def extract_directive_assignments(schema, location, assignments)
11-
return EMPTY_OBJECT unless assignments && assignments.any?
11+
return EMPTY_OBJECT unless assignments && !assignments.empty?
1212

1313
assignments.each_with_object({}) do |kwargs, memo|
1414
type = kwargs[:parent_type_name] ? schema.get_type(kwargs[:parent_type_name]) : schema.query

lib/graphql/stitching/executor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def exec!(next_steps)
7979

8080
def exec_task(task)
8181
next_steps = task.load.tap(&:compact!)
82-
exec!(next_steps) if next_steps.any?
82+
exec!(next_steps) unless next_steps.empty?
8383
end
8484
end
8585
end

lib/graphql/stitching/executor/root_source.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def fetch(ops)
2121
@executor.query_count += 1
2222

2323
if result["data"]
24-
if op.path.any?
24+
unless op.path.empty?
2525
# Nested root scopes must expand their pathed origin set
2626
origin_set = op.path.reduce([@executor.data]) do |set, ns|
2727
set.flat_map { |obj| obj && obj[ns] }.tap(&:compact!)
@@ -73,7 +73,7 @@ def build_document(op, operation_name = nil, operation_directives = nil)
7373
def format_errors!(errors, path)
7474
errors.each do |err|
7575
err.delete("locations")
76-
err["path"].unshift(*path) if err["path"] && path.any?
76+
err["path"].unshift(*path) if err["path"] && !path.empty?
7777
end
7878
errors
7979
end

lib/graphql/stitching/executor/type_resolver_source.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ def fetch(ops)
2020
origin_set.select! { _1[TypeResolver::TYPENAME_EXPORT_NODE.alias] == op.if_type }
2121
end
2222

23-
memo[op] = origin_set if origin_set.any?
23+
memo[op] = origin_set unless origin_set.empty?
2424
end
2525

26-
if origin_sets_by_operation.any?
26+
unless origin_sets_by_operation.empty?
2727
query_document, variable_names = build_document(
2828
origin_sets_by_operation,
2929
@executor.request.operation_name,
@@ -105,7 +105,7 @@ def build_document(origin_sets_by_operation, operation_name = nil, operation_dir
105105
end
106106
end
107107

108-
if variable_defs.any?
108+
unless variable_defs.empty?
109109
doc_buffer << "("
110110
variable_defs.each_with_index do |(k, v), i|
111111
doc_buffer << "," unless i.zero?
@@ -135,10 +135,11 @@ def merge_results!(origin_sets_by_operation, raw_result)
135135
origin_set.map.with_index { |_, index| raw_result["_#{batch_index}_#{index}_result"] }
136136
end
137137

138-
next unless results&.any?
138+
next if results.nil? || results.empty?
139139

140140
origin_set.each_with_index do |origin_obj, index|
141-
origin_obj.merge!(results[index]) if results[index]
141+
result = results[index]
142+
origin_obj.merge!(result) if result
142143
end
143144
end
144145
end

lib/graphql/stitching/http_executable.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def extract_multipart_form(request, document, variables)
8080

8181
return if files_by_path.none?
8282

83-
map = {}
83+
map = Hash.new { |h, k| h[k] = [] }
8484
files = files_by_path.values.tap(&:uniq!)
8585
variables_copy = variables.dup
8686

@@ -90,7 +90,6 @@ def extract_multipart_form(request, document, variables)
9090
path.each_with_index do |key, i|
9191
if i == path.length - 1
9292
file_index = files.index(copy[key]).to_s
93-
map[file_index] ||= []
9493
map[file_index] << "variables.#{path.join(".")}"
9594
copy[key] = nil
9695
elsif orig[key].object_id == copy[key].object_id

lib/graphql/stitching/planner.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def add_step(
9393
step = @steps_by_entrypoint[entrypoint]
9494
next_index = step ? parent_index : @planning_index += 1
9595

96-
if selections.any?
96+
unless selections.empty?
9797
selections = extract_locale_selections(location, parent_type, next_index, selections, path, variables)
9898
end
9999

lib/graphql/stitching/request.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def operation_name
101101

102102
# @return [String] A string of directives applied to the root operation. These are passed through in all subgraph requests.
103103
def operation_directives
104-
@operation_directives ||= if operation.directives.any?
104+
@operation_directives ||= unless operation.directives.empty?
105105
printer = GraphQL::Language::Printer.new
106106
operation.directives.map { printer.print(_1) }.join(" ")
107107
end

lib/graphql/stitching/request/skip_include.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def render_node(parent_node, variables)
3434
next nil
3535
end
3636

37-
node = render_node(node, variables) if node.selections.any?
37+
node = render_node(node, variables) unless node.selections.empty?
3838
changed ||= node.object_id != original_node.object_id
3939
node
4040
end
@@ -51,7 +51,7 @@ def render_node(parent_node, variables)
5151
end
5252

5353
def prune_node(node, variables)
54-
return node unless node.directives.any?
54+
return node if node.directives.empty?
5555

5656
delete_node = false
5757
filtered_directives = node.directives.reject do |directive|

0 commit comments

Comments
 (0)