Skip to content
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

More perfetto #5229

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cop/development/trace_calls_super_cop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,28 @@ class TraceCallsSuperCop < RuboCop::Cop::Base
:authorized,
:authorized_lazy,
:begin_analyze_multiplex,
:begin_authorized,
:begin_dataloader,
:begin_dataloader_source,
:begin_execute_field,
:begin_multiplex,
:begin_parse,
:begin_resolve_type,
:begin_validate,
:dataloader_fiber_exit,
:dataloader_fiber_resume,
:dataloader_fiber_yield,
:dataloader_spawn_execution_fiber,
:dataloader_spawn_source_fiber,
:end_analyze_multiplex,
:end_authorized,
:end_dataloader,
:end_dataloader_source,
:end_execute_field,
:end_multiplex,
:end_parse,
:end_resolve_type,
:end_validate,
:execute_field,
:execute_field_lazy,
:execute_multiplex,
Expand Down
4 changes: 2 additions & 2 deletions lib/graphql/execution/interpreter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ def run_all(schema, query_options, context: {}, max_complexity: schema.max_compl
multiplex_analyzers += [GraphQL::Analysis::MaxQueryComplexity]
end

trace.begin_analyze_multiplex(multiplex)
trace.begin_analyze_multiplex(multiplex, multiplex_analyzers)
schema.analysis_engine.analyze_multiplex(multiplex, multiplex_analyzers)
trace.end_analyze_multiplex(multiplex)
trace.end_analyze_multiplex(multiplex, multiplex_analyzers)

begin
# Since this is basically the batching context,
Expand Down
20 changes: 7 additions & 13 deletions lib/graphql/execution/interpreter/runtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ def evaluate_selection_with_resolved_keyword_args(kwarg_arguments, resolved_argu
end
# Actually call the field resolver and capture the result
app_result = begin
@current_trace.begin_execute_field(selection_result, result_name)
@current_trace.begin_execute_field(field_defn, object, kwarg_arguments, query)
@current_trace.execute_field(field: field_defn, ast_node: ast_node, query: query, object: object, arguments: kwarg_arguments) do
field_defn.resolve(object, kwarg_arguments, context)
end
Expand All @@ -388,6 +388,7 @@ def evaluate_selection_with_resolved_keyword_args(kwarg_arguments, resolved_argu
ex_err
end
end
@current_trace.end_execute_field(field_defn, object, kwarg_arguments, query, app_result)
after_lazy(app_result, field: field_defn, ast_node: ast_node, owner_object: object, arguments: resolved_arguments, result_name: result_name, result: selection_result, runtime_state: runtime_state) do |inner_result, runtime_state|
owner_type = selection_result.graphql_result_type
return_type = field_defn.type
Expand All @@ -397,7 +398,6 @@ def evaluate_selection_with_resolved_keyword_args(kwarg_arguments, resolved_argu
runtime_state.was_authorized_by_scope_items = nil
continue_field(continue_value, owner_type, field_defn, return_type, ast_node, next_selections, false, object, resolved_arguments, result_name, selection_result, was_scoped, runtime_state)
else
@current_trace.end_execute_field(selection_result, result_name)
nil
end
end
Expand Down Expand Up @@ -584,7 +584,6 @@ def continue_field(value, owner_type, field, current_type, ast_node, next_select
rescue StandardError => err
query.handle_or_reraise(err)
end
@current_trace.end_execute_field(selection_result, result_name)
set_result(selection_result, result_name, r, false, is_non_null)
r
when "UNION", "INTERFACE"
Expand All @@ -603,7 +602,6 @@ def continue_field(value, owner_type, field, current_type, ast_node, next_select
err_class = current_type::UnresolvedTypeError
type_error = err_class.new(resolved_value, field, parent_type, resolved_type, possible_types)
schema.type_error(type_error, context)
@current_trace.end_execute_field(selection_result, result_name)
set_result(selection_result, result_name, nil, false, is_non_null)
nil
else
Expand All @@ -620,7 +618,6 @@ def continue_field(value, owner_type, field, current_type, ast_node, next_select
continue_value = continue_value(inner_object, field, is_non_null, ast_node, result_name, selection_result)
if HALT != continue_value
response_hash = GraphQLResultHash.new(result_name, current_type, continue_value, selection_result, is_non_null, next_selections, false, ast_node, arguments, field)
@current_trace.end_execute_field(selection_result, result_name)
set_result(selection_result, result_name, response_hash, true, is_non_null)
each_gathered_selections(response_hash) do |selections, is_selection_array|
if is_selection_array
Expand Down Expand Up @@ -651,9 +648,6 @@ def continue_field(value, owner_type, field, current_type, ast_node, next_select
list_value = begin
begin
value.each do |inner_value|
if idx.nil?
@current_trace.end_execute_field(selection_result, result_name)
end
idx ||= 0
this_idx = idx
idx += 1
Expand All @@ -666,10 +660,6 @@ def continue_field(value, owner_type, field, current_type, ast_node, next_select
end
end

if idx.nil? # no entries
@current_trace.end_execute_field(selection_result, result_name)
end

response_list
rescue NoMethodError => err
# Ruby 2.2 doesn't have NoMethodError#receiver, can't check that one in this case. (It's been EOL since 2017.)
Expand Down Expand Up @@ -858,17 +848,21 @@ def delete_all_interpreter_context
end

def resolve_type(type, value)
@current_trace.begin_resolve_type(type, value, context)
resolved_type, resolved_value = @current_trace.resolve_type(query: query, type: type, object: value) do
query.resolve_type(type, value)
end

if lazy?(resolved_type)
GraphQL::Execution::Lazy.new do
@current_trace.resolve_type_lazy(query: query, type: type, object: value) do
schema.sync_lazy(resolved_type)
rt = schema.sync_lazy(resolved_type)
@current_trace.end_resolve_type(type, value, context, rt)
rt
end
end
else
@current_trace.end_resolve_type(type, value, context, resolved_type)
[resolved_type, resolved_value]
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/graphql/schema/object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def wrap(object, context)
def authorized_new(object, context)
maybe_lazy_auth_val = context.query.current_trace.authorized(query: context.query, type: self, object: object) do
begin
context.query.current_trace.begin_authorized(self, object, context)
authorized?(object, context)
rescue GraphQL::UnauthorizedError => err
context.schema.unauthorized_object(err)
Expand All @@ -86,6 +87,7 @@ def authorized_new(object, context)
end

context.query.after_lazy(auth_val) do |is_authorized|
context.query.current_trace.end_authorized(self, object, context, is_authorized)
if is_authorized
self.new(object, context)
else
Expand Down
6 changes: 6 additions & 0 deletions lib/graphql/static_validation/validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ def initialize(schema:, rules: GraphQL::StaticValidation::ALL_RULES)
# @param max_errors [Integer] Maximum number of errors before aborting validation. Any positive number will limit the number of errors. Defaults to nil for no limit.
# @return [Array<Hash>]
def validate(query, validate: true, timeout: nil, max_errors: nil)
query.current_trace.begin_validate(query, validate)
is_valid = false
query.current_trace.validate(validate: validate, query: query) do
begin_t = Time.now
errors = if validate == false
Expand All @@ -51,17 +53,21 @@ def validate(query, validate: true, timeout: nil, max_errors: nil)

context.errors
end
is_valid = errors.size == 0

{
remaining_timeout: timeout ? (timeout - (Time.now - begin_t)) : nil,
errors: errors,
}
end
rescue GraphQL::ExecutionError => e
is_valid = false
{
remaining_timeout: nil,
errors: [e],
}
ensure
query.current_trace.end_validate(query, validate, is_valid)
end

# Invoked when static validation times out.
Expand Down
Loading
Loading