Skip to content

Commit

Permalink
Merge pull request #4637 from gmac/gmac/tidy_chained_array_xforms
Browse files Browse the repository at this point in the history
Tidy chained array transforms
  • Loading branch information
rmosolgo authored Sep 18, 2023
2 parents 999ff4b + 121ce8e commit 0f987e5
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/graphql/analysis/ast.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def analyze_query(query, analyzers, multiplex_analyzers: [])
end

def analysis_errors(results)
results.flatten.select { |r| r.is_a?(GraphQL::AnalysisError) }
results.flatten.tap { _1.select! { |r| r.is_a?(GraphQL::AnalysisError) } }
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/graphql/execution/lookahead.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def selection(field_name, selected_type: @selected_type, arguments: nil)
@query.warden
.possible_types(selected_type)
.map { |t| @query.warden.fields(t) }
.flatten
.tap(&:flatten!)
end

if (match_by_orig_name = all_fields.find { |f| f.original_name == field_name })
Expand Down
2 changes: 1 addition & 1 deletion lib/graphql/language/nodes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ class Argument < AbstractNode
# @return [String, Float, Integer, Boolean, Array, InputObject, VariableIdentifier] The value passed for this key

def children
@children ||= Array(value).flatten.select { |v| v.is_a?(AbstractNode) }
@children ||= Array(value).flatten.tap { _1.select! { |v| v.is_a?(AbstractNode) } }
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/graphql/static_validation/literal_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def required_input_fields_are_present(type, ast_node)
# that required fields are missing
required_field_names = @warden.arguments(type)
.select { |argument| argument.type.kind.non_null? && @warden.get_argument(type, argument.name) }
.map(&:name)
.map!(&:name)

present_field_names = ast_node.arguments.map(&:name)
missing_required_field_names = required_field_names - present_field_names
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def assert_required_args(ast_node, defn)
present_argument_names = ast_node.arguments.map(&:name)
required_argument_names = context.warden.arguments(defn)
.select { |a| a.type.kind.non_null? && !a.default_value? && context.warden.get_argument(defn, a.name) }
.map(&:name)
.map!(&:name)

missing_names = required_argument_names - present_argument_names
if missing_names.any?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def validate_input_object(ast_node, context, parent)

required_fields = context.warden.arguments(parent_type)
.select{|arg| arg.type.kind.non_null?}
.map(&:graphql_name)
.map!(&:graphql_name)

present_fields = ast_node.arguments.map(&:name)
missing_fields = required_fields - present_fields
Expand Down
4 changes: 2 additions & 2 deletions lib/graphql/tracing/appoptics_trace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def metadata(data, layer)
else
[key, data[key]]
end
end.flatten(2).each_slice(2).to_h.merge(Spec: 'graphql')
end.tap { _1.flatten!(2) }.each_slice(2).to_h.merge(Spec: 'graphql')
end
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength

Expand Down Expand Up @@ -226,7 +226,7 @@ def graphql_query_string(query_string)
end

def graphql_multiplex(data)
names = data.queries.map(&:operations).map(&:keys).flatten.compact
names = data.queries.map(&:operations).map!(&:keys).tap(&:flatten!).tap(&:compact!)
multiplex_transaction_name(names) if names.size > 1

[:Operations, names.join(', ')]
Expand Down
4 changes: 2 additions & 2 deletions lib/graphql/tracing/appoptics_tracing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def metadata(data, layer)
else
[key, data[key]]
end
end.flatten(2).each_slice(2).to_h.merge(Spec: 'graphql')
end.tap { _1.flatten!(2) }.each_slice(2).to_h.merge(Spec: 'graphql')
end
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength

Expand Down Expand Up @@ -148,7 +148,7 @@ def graphql_query_string(query_string)
end

def graphql_multiplex(data)
names = data.queries.map(&:operations).map(&:keys).flatten.compact
names = data.queries.map(&:operations).map!(&:keys).tap(&:flatten!).tap(&:compact!)
multiplex_transaction_name(names) if names.size > 1

[:Operations, names.join(', ')]
Expand Down

0 comments on commit 0f987e5

Please sign in to comment.