graphql 1.13.12 → 2.0.21
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/generators/graphql/install_generator.rb +1 -1
- data/lib/generators/graphql/relay.rb +3 -17
- data/lib/generators/graphql/templates/schema.erb +3 -0
- data/lib/graphql/analysis/ast/field_usage.rb +3 -1
- data/lib/graphql/analysis/ast/max_query_complexity.rb +0 -1
- data/lib/graphql/analysis/ast/query_complexity.rb +1 -1
- data/lib/graphql/analysis/ast/query_depth.rb +0 -1
- data/lib/graphql/analysis/ast/visitor.rb +43 -36
- data/lib/graphql/analysis/ast.rb +2 -12
- data/lib/graphql/analysis.rb +0 -7
- data/lib/graphql/backtrace/table.rb +2 -20
- data/lib/graphql/backtrace/trace.rb +96 -0
- data/lib/graphql/backtrace/tracer.rb +2 -3
- data/lib/graphql/backtrace.rb +7 -8
- data/lib/graphql/dataloader/null_dataloader.rb +3 -1
- data/lib/graphql/dataloader/source.rb +9 -0
- data/lib/graphql/dataloader.rb +4 -1
- data/lib/graphql/dig.rb +1 -1
- data/lib/graphql/execution/errors.rb +12 -82
- data/lib/graphql/execution/interpreter/arguments.rb +1 -1
- data/lib/graphql/execution/interpreter/arguments_cache.rb +2 -3
- data/lib/graphql/execution/interpreter/resolve.rb +26 -0
- data/lib/graphql/execution/interpreter/runtime.rb +300 -222
- data/lib/graphql/execution/interpreter.rb +187 -78
- data/lib/graphql/execution/lazy.rb +7 -21
- data/lib/graphql/execution/lookahead.rb +44 -40
- data/lib/graphql/execution/multiplex.rb +3 -174
- data/lib/graphql/execution.rb +11 -4
- data/lib/graphql/filter.rb +7 -2
- data/lib/graphql/introspection/directive_type.rb +2 -2
- data/lib/graphql/introspection/dynamic_fields.rb +3 -8
- data/lib/graphql/introspection/entry_points.rb +2 -15
- data/lib/graphql/introspection/field_type.rb +1 -1
- data/lib/graphql/introspection/schema_type.rb +2 -2
- data/lib/graphql/introspection/type_type.rb +13 -6
- data/lib/graphql/introspection.rb +4 -3
- data/lib/graphql/language/document_from_schema_definition.rb +43 -44
- data/lib/graphql/language/lexer.rb +216 -1488
- data/lib/graphql/language/nodes.rb +66 -40
- data/lib/graphql/language/parser.rb +539 -510
- data/lib/graphql/language/parser.y +53 -44
- data/lib/graphql/language/printer.rb +37 -21
- data/lib/graphql/language/visitor.rb +191 -83
- data/lib/graphql/pagination/active_record_relation_connection.rb +0 -8
- data/lib/graphql/pagination/array_connection.rb +4 -2
- data/lib/graphql/pagination/connection.rb +33 -6
- data/lib/graphql/pagination/connections.rb +3 -28
- data/lib/graphql/pagination/relation_connection.rb +2 -0
- data/lib/graphql/query/context.rb +156 -196
- data/lib/graphql/query/input_validation_result.rb +10 -1
- data/lib/graphql/query/null_context.rb +1 -4
- data/lib/graphql/query/validation_pipeline.rb +12 -37
- data/lib/graphql/query/variable_validation_error.rb +2 -2
- data/lib/graphql/query/variables.rb +35 -21
- data/lib/graphql/query.rb +39 -46
- data/lib/graphql/railtie.rb +0 -104
- data/lib/graphql/rake_task/validate.rb +1 -1
- data/lib/graphql/rake_task.rb +29 -1
- data/lib/graphql/relay/range_add.rb +9 -20
- data/lib/graphql/relay.rb +0 -15
- data/lib/graphql/schema/addition.rb +7 -9
- data/lib/graphql/schema/argument.rb +38 -47
- data/lib/graphql/schema/build_from_definition.rb +47 -21
- data/lib/graphql/schema/directive/one_of.rb +12 -0
- data/lib/graphql/schema/directive/transform.rb +1 -1
- data/lib/graphql/schema/directive.rb +12 -23
- data/lib/graphql/schema/enum.rb +29 -41
- data/lib/graphql/schema/enum_value.rb +2 -25
- data/lib/graphql/schema/field/connection_extension.rb +4 -0
- data/lib/graphql/schema/field.rb +256 -349
- data/lib/graphql/schema/field_extension.rb +1 -4
- data/lib/graphql/schema/find_inherited_value.rb +2 -7
- data/lib/graphql/schema/input_object.rb +57 -69
- data/lib/graphql/schema/interface.rb +0 -35
- data/lib/graphql/schema/introspection_system.rb +3 -8
- data/lib/graphql/schema/late_bound_type.rb +8 -2
- data/lib/graphql/schema/list.rb +18 -9
- data/lib/graphql/schema/loader.rb +1 -2
- data/lib/graphql/schema/member/base_dsl_methods.rb +17 -19
- data/lib/graphql/schema/member/build_type.rb +5 -7
- data/lib/graphql/schema/member/has_arguments.rb +147 -56
- data/lib/graphql/schema/member/has_ast_node.rb +12 -0
- data/lib/graphql/schema/member/has_deprecation_reason.rb +3 -4
- data/lib/graphql/schema/member/has_directives.rb +81 -61
- data/lib/graphql/schema/member/has_fields.rb +97 -40
- data/lib/graphql/schema/member/has_interfaces.rb +49 -10
- data/lib/graphql/schema/member/has_validators.rb +32 -6
- data/lib/graphql/schema/member/relay_shortcuts.rb +47 -2
- data/lib/graphql/schema/member/type_system_helpers.rb +17 -0
- data/lib/graphql/schema/member/validates_input.rb +3 -3
- data/lib/graphql/schema/member.rb +0 -6
- data/lib/graphql/schema/mutation.rb +0 -9
- data/lib/graphql/schema/non_null.rb +3 -9
- data/lib/graphql/schema/object.rb +15 -52
- data/lib/graphql/schema/relay_classic_mutation.rb +53 -42
- data/lib/graphql/schema/resolver/has_payload_type.rb +20 -10
- data/lib/graphql/schema/resolver.rb +43 -44
- data/lib/graphql/schema/scalar.rb +8 -23
- data/lib/graphql/schema/subscription.rb +0 -7
- data/lib/graphql/schema/timeout.rb +24 -28
- data/lib/graphql/schema/type_membership.rb +3 -0
- data/lib/graphql/schema/union.rb +10 -17
- data/lib/graphql/schema/validator.rb +1 -1
- data/lib/graphql/schema/warden.rb +37 -9
- data/lib/graphql/schema/wrapper.rb +0 -5
- data/lib/graphql/schema.rb +265 -968
- data/lib/graphql/static_validation/all_rules.rb +1 -0
- data/lib/graphql/static_validation/base_visitor.rb +4 -21
- data/lib/graphql/static_validation/definition_dependencies.rb +7 -1
- data/lib/graphql/static_validation/error.rb +2 -2
- data/lib/graphql/static_validation/literal_validator.rb +19 -1
- data/lib/graphql/static_validation/rules/directives_are_defined.rb +11 -5
- data/lib/graphql/static_validation/rules/directives_are_in_valid_locations.rb +12 -12
- data/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb +12 -4
- data/lib/graphql/static_validation/rules/fields_will_merge.rb +2 -2
- data/lib/graphql/static_validation/rules/one_of_input_objects_are_valid.rb +66 -0
- data/lib/graphql/static_validation/rules/one_of_input_objects_are_valid_error.rb +29 -0
- data/lib/graphql/static_validation/rules/unique_directives_per_location.rb +12 -6
- data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed.rb +1 -1
- data/lib/graphql/static_validation/validator.rb +3 -25
- data/lib/graphql/static_validation.rb +0 -2
- data/lib/graphql/subscriptions/action_cable_subscriptions.rb +7 -1
- data/lib/graphql/subscriptions/default_subscription_resolve_extension.rb +38 -1
- data/lib/graphql/subscriptions/event.rb +3 -8
- data/lib/graphql/subscriptions/instrumentation.rb +0 -51
- data/lib/graphql/subscriptions.rb +32 -20
- data/lib/graphql/tracing/active_support_notifications_trace.rb +16 -0
- data/lib/graphql/tracing/appoptics_trace.rb +231 -0
- data/lib/graphql/tracing/appsignal_trace.rb +77 -0
- data/lib/graphql/tracing/data_dog_trace.rb +148 -0
- data/lib/graphql/tracing/data_dog_tracing.rb +21 -2
- data/lib/graphql/tracing/legacy_trace.rb +65 -0
- data/lib/graphql/tracing/new_relic_trace.rb +75 -0
- data/lib/graphql/tracing/notifications_trace.rb +42 -0
- data/lib/graphql/tracing/platform_trace.rb +109 -0
- data/lib/graphql/tracing/platform_tracing.rb +33 -43
- data/lib/graphql/tracing/prometheus_trace.rb +89 -0
- data/lib/graphql/tracing/prometheus_tracing/graphql_collector.rb +1 -1
- data/lib/graphql/tracing/prometheus_tracing.rb +3 -3
- data/lib/graphql/tracing/scout_trace.rb +72 -0
- data/lib/graphql/tracing/statsd_trace.rb +56 -0
- data/lib/graphql/tracing/trace.rb +75 -0
- data/lib/graphql/tracing.rb +16 -40
- data/lib/graphql/type_kinds.rb +6 -3
- data/lib/graphql/types/iso_8601_date.rb +4 -1
- data/lib/graphql/types/iso_8601_date_time.rb +4 -0
- data/lib/graphql/types/relay/base_connection.rb +16 -6
- data/lib/graphql/types/relay/connection_behaviors.rb +29 -27
- data/lib/graphql/types/relay/edge_behaviors.rb +16 -5
- data/lib/graphql/types/relay/node_behaviors.rb +12 -2
- data/lib/graphql/types/relay/page_info_behaviors.rb +7 -2
- data/lib/graphql/types/relay.rb +0 -3
- data/lib/graphql/types/string.rb +1 -1
- data/lib/graphql/version.rb +1 -1
- data/lib/graphql.rb +17 -74
- metadata +33 -133
- data/lib/graphql/analysis/analyze_query.rb +0 -98
- data/lib/graphql/analysis/field_usage.rb +0 -45
- data/lib/graphql/analysis/max_query_complexity.rb +0 -26
- data/lib/graphql/analysis/max_query_depth.rb +0 -26
- data/lib/graphql/analysis/query_complexity.rb +0 -88
- data/lib/graphql/analysis/query_depth.rb +0 -43
- data/lib/graphql/analysis/reducer_state.rb +0 -48
- data/lib/graphql/argument.rb +0 -131
- data/lib/graphql/authorization.rb +0 -82
- data/lib/graphql/backtrace/legacy_tracer.rb +0 -56
- data/lib/graphql/backwards_compatibility.rb +0 -61
- data/lib/graphql/base_type.rb +0 -232
- data/lib/graphql/boolean_type.rb +0 -2
- data/lib/graphql/compatibility/execution_specification/counter_schema.rb +0 -53
- data/lib/graphql/compatibility/execution_specification/specification_schema.rb +0 -200
- data/lib/graphql/compatibility/execution_specification.rb +0 -436
- data/lib/graphql/compatibility/lazy_execution_specification/lazy_schema.rb +0 -111
- data/lib/graphql/compatibility/lazy_execution_specification.rb +0 -215
- data/lib/graphql/compatibility/query_parser_specification/parse_error_specification.rb +0 -87
- data/lib/graphql/compatibility/query_parser_specification/query_assertions.rb +0 -79
- data/lib/graphql/compatibility/query_parser_specification.rb +0 -266
- data/lib/graphql/compatibility/schema_parser_specification.rb +0 -682
- data/lib/graphql/compatibility.rb +0 -5
- data/lib/graphql/define/assign_argument.rb +0 -12
- data/lib/graphql/define/assign_connection.rb +0 -13
- data/lib/graphql/define/assign_enum_value.rb +0 -18
- data/lib/graphql/define/assign_global_id_field.rb +0 -11
- data/lib/graphql/define/assign_mutation_function.rb +0 -34
- data/lib/graphql/define/assign_object_field.rb +0 -42
- data/lib/graphql/define/defined_object_proxy.rb +0 -53
- data/lib/graphql/define/instance_definable.rb +0 -255
- data/lib/graphql/define/no_definition_error.rb +0 -7
- data/lib/graphql/define/non_null_with_bang.rb +0 -16
- data/lib/graphql/define/type_definer.rb +0 -31
- data/lib/graphql/define.rb +0 -31
- data/lib/graphql/deprecated_dsl.rb +0 -55
- data/lib/graphql/directive/deprecated_directive.rb +0 -2
- data/lib/graphql/directive/include_directive.rb +0 -2
- data/lib/graphql/directive/skip_directive.rb +0 -2
- data/lib/graphql/directive.rb +0 -107
- data/lib/graphql/enum_type.rb +0 -133
- data/lib/graphql/execution/execute.rb +0 -333
- data/lib/graphql/execution/flatten.rb +0 -40
- data/lib/graphql/execution/instrumentation.rb +0 -92
- data/lib/graphql/execution/lazy/resolve.rb +0 -91
- data/lib/graphql/execution/typecast.rb +0 -50
- data/lib/graphql/field/resolve.rb +0 -59
- data/lib/graphql/field.rb +0 -226
- data/lib/graphql/float_type.rb +0 -2
- data/lib/graphql/function.rb +0 -128
- data/lib/graphql/id_type.rb +0 -2
- data/lib/graphql/input_object_type.rb +0 -138
- data/lib/graphql/int_type.rb +0 -2
- data/lib/graphql/interface_type.rb +0 -72
- data/lib/graphql/internal_representation/document.rb +0 -27
- data/lib/graphql/internal_representation/node.rb +0 -206
- data/lib/graphql/internal_representation/print.rb +0 -51
- data/lib/graphql/internal_representation/rewrite.rb +0 -184
- data/lib/graphql/internal_representation/scope.rb +0 -88
- data/lib/graphql/internal_representation/visit.rb +0 -36
- data/lib/graphql/internal_representation.rb +0 -7
- data/lib/graphql/language/lexer.rl +0 -260
- data/lib/graphql/list_type.rb +0 -80
- data/lib/graphql/non_null_type.rb +0 -71
- data/lib/graphql/object_type.rb +0 -130
- data/lib/graphql/query/arguments.rb +0 -189
- data/lib/graphql/query/arguments_cache.rb +0 -24
- data/lib/graphql/query/executor.rb +0 -52
- data/lib/graphql/query/literal_input.rb +0 -136
- data/lib/graphql/query/serial_execution/field_resolution.rb +0 -92
- data/lib/graphql/query/serial_execution/operation_resolution.rb +0 -19
- data/lib/graphql/query/serial_execution/selection_resolution.rb +0 -23
- data/lib/graphql/query/serial_execution/value_resolution.rb +0 -87
- data/lib/graphql/query/serial_execution.rb +0 -40
- data/lib/graphql/relay/array_connection.rb +0 -83
- data/lib/graphql/relay/base_connection.rb +0 -189
- data/lib/graphql/relay/connection_instrumentation.rb +0 -54
- data/lib/graphql/relay/connection_resolve.rb +0 -43
- data/lib/graphql/relay/connection_type.rb +0 -54
- data/lib/graphql/relay/edge.rb +0 -27
- data/lib/graphql/relay/edge_type.rb +0 -19
- data/lib/graphql/relay/edges_instrumentation.rb +0 -39
- data/lib/graphql/relay/global_id_resolve.rb +0 -17
- data/lib/graphql/relay/mongo_relation_connection.rb +0 -50
- data/lib/graphql/relay/mutation/instrumentation.rb +0 -23
- data/lib/graphql/relay/mutation/resolve.rb +0 -56
- data/lib/graphql/relay/mutation/result.rb +0 -38
- data/lib/graphql/relay/mutation.rb +0 -106
- data/lib/graphql/relay/node.rb +0 -39
- data/lib/graphql/relay/page_info.rb +0 -7
- data/lib/graphql/relay/relation_connection.rb +0 -188
- data/lib/graphql/relay/type_extensions.rb +0 -32
- data/lib/graphql/scalar_type.rb +0 -91
- data/lib/graphql/schema/catchall_middleware.rb +0 -35
- data/lib/graphql/schema/default_parse_error.rb +0 -10
- data/lib/graphql/schema/default_type_error.rb +0 -17
- data/lib/graphql/schema/member/accepts_definition.rb +0 -164
- data/lib/graphql/schema/member/cached_graphql_definition.rb +0 -58
- data/lib/graphql/schema/member/instrumentation.rb +0 -131
- data/lib/graphql/schema/middleware_chain.rb +0 -82
- data/lib/graphql/schema/possible_types.rb +0 -44
- data/lib/graphql/schema/rescue_middleware.rb +0 -60
- data/lib/graphql/schema/timeout_middleware.rb +0 -88
- data/lib/graphql/schema/traversal.rb +0 -228
- data/lib/graphql/schema/validation.rb +0 -313
- data/lib/graphql/static_validation/default_visitor.rb +0 -15
- data/lib/graphql/static_validation/no_validate_visitor.rb +0 -10
- data/lib/graphql/string_type.rb +0 -2
- data/lib/graphql/subscriptions/subscription_root.rb +0 -76
- data/lib/graphql/tracing/skylight_tracing.rb +0 -70
- data/lib/graphql/types/relay/default_relay.rb +0 -31
- data/lib/graphql/types/relay/node_field.rb +0 -24
- data/lib/graphql/types/relay/nodes_field.rb +0 -43
- data/lib/graphql/union_type.rb +0 -115
- data/lib/graphql/upgrader/member.rb +0 -937
- data/lib/graphql/upgrader/schema.rb +0 -38
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module GraphQL
|
3
|
+
module Tracing
|
4
|
+
# This trace class calls legacy-style tracer with payload hashes.
|
5
|
+
# New-style `trace_with` modules significantly reduce the overhead of tracing,
|
6
|
+
# but that advantage is lost when legacy-style tracers are also used (since the payload hashes are still constructed).
|
7
|
+
class LegacyTrace < Trace
|
8
|
+
def lex(query_string:)
|
9
|
+
(@multiplex || @query).trace("lex", { query_string: query_string }) { super }
|
10
|
+
end
|
11
|
+
|
12
|
+
def parse(query_string:)
|
13
|
+
(@multiplex || @query).trace("parse", { query_string: query_string }) { super }
|
14
|
+
end
|
15
|
+
|
16
|
+
def validate(query:, validate:)
|
17
|
+
query.trace("validate", { validate: validate, query: query }) { super }
|
18
|
+
end
|
19
|
+
|
20
|
+
def analyze_multiplex(multiplex:)
|
21
|
+
multiplex.trace("analyze_multiplex", { multiplex: multiplex }) { super }
|
22
|
+
end
|
23
|
+
|
24
|
+
def analyze_query(query:)
|
25
|
+
query.trace("analyze_query", { query: query }) { super }
|
26
|
+
end
|
27
|
+
|
28
|
+
def execute_multiplex(multiplex:)
|
29
|
+
multiplex.trace("execute_multiplex", { multiplex: multiplex }) { super }
|
30
|
+
end
|
31
|
+
|
32
|
+
def execute_query(query:)
|
33
|
+
query.trace("execute_query", { query: query }) { super }
|
34
|
+
end
|
35
|
+
|
36
|
+
def execute_query_lazy(query:, multiplex:)
|
37
|
+
multiplex.trace("execute_query_lazy", { multiplex: multiplex, query: query }) { super }
|
38
|
+
end
|
39
|
+
|
40
|
+
def execute_field(field:, query:, ast_node:, arguments:, object:)
|
41
|
+
query.trace("execute_field", { field: field, query: query, ast_node: ast_node, arguments: arguments, object: object, owner: field.owner, path: query.context[:current_path] }) { super }
|
42
|
+
end
|
43
|
+
|
44
|
+
def execute_field_lazy(field:, query:, ast_node:, arguments:, object:)
|
45
|
+
query.trace("execute_field_lazy", { field: field, query: query, ast_node: ast_node, arguments: arguments, object: object, owner: field.owner, path: query.context[:current_path] }) { super }
|
46
|
+
end
|
47
|
+
|
48
|
+
def authorized(query:, type:, object:)
|
49
|
+
query.trace("authorized", { context: query.context, type: type, object: object, path: query.context[:current_path] }) { super }
|
50
|
+
end
|
51
|
+
|
52
|
+
def authorized_lazy(query:, type:, object:)
|
53
|
+
query.trace("authorized_lazy", { context: query.context, type: type, object: object, path: query.context[:current_path] }) { super }
|
54
|
+
end
|
55
|
+
|
56
|
+
def resolve_type(query:, type:, object:)
|
57
|
+
query.trace("resolve_type", { context: query.context, type: type, object: object, path: query.context[:current_path] }) { super }
|
58
|
+
end
|
59
|
+
|
60
|
+
def resolve_type_lazy(query:, type:, object:)
|
61
|
+
query.trace("resolve_type_lazy", { context: query.context, type: type, object: object, path: query.context[:current_path] }) { super }
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GraphQL
|
4
|
+
module Tracing
|
5
|
+
module NewRelicTrace
|
6
|
+
include PlatformTrace
|
7
|
+
|
8
|
+
# @param set_transaction_name [Boolean] If true, the GraphQL operation name will be used as the transaction name.
|
9
|
+
# This is not advised if you run more than one query per HTTP request, for example, with `graphql-client` or multiplexing.
|
10
|
+
# It can also be specified per-query with `context[:set_new_relic_transaction_name]`.
|
11
|
+
def initialize(set_transaction_name: false, **_rest)
|
12
|
+
@set_transaction_name = set_transaction_name
|
13
|
+
super
|
14
|
+
end
|
15
|
+
|
16
|
+
def execute_query(query:)
|
17
|
+
set_this_txn_name = query.context[:set_new_relic_transaction_name]
|
18
|
+
if set_this_txn_name == true || (set_this_txn_name.nil? && @set_transaction_name)
|
19
|
+
NewRelic::Agent.set_transaction_name(transaction_name(query))
|
20
|
+
end
|
21
|
+
NewRelic::Agent::MethodTracerHelpers.trace_execution_scoped("GraphQL/execute") do
|
22
|
+
super
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
{
|
27
|
+
"lex" => "GraphQL/lex",
|
28
|
+
"parse" => "GraphQL/parse",
|
29
|
+
"validate" => "GraphQL/validate",
|
30
|
+
"analyze_query" => "GraphQL/analyze",
|
31
|
+
"analyze_multiplex" => "GraphQL/analyze",
|
32
|
+
"execute_multiplex" => "GraphQL/execute",
|
33
|
+
"execute_query_lazy" => "GraphQL/execute",
|
34
|
+
}.each do |trace_method, platform_key|
|
35
|
+
module_eval <<-RUBY, __FILE__, __LINE__
|
36
|
+
def #{trace_method}(**_keys)
|
37
|
+
NewRelic::Agent::MethodTracerHelpers.trace_execution_scoped("#{platform_key}") do
|
38
|
+
super
|
39
|
+
end
|
40
|
+
end
|
41
|
+
RUBY
|
42
|
+
end
|
43
|
+
|
44
|
+
def platform_execute_field(platform_key)
|
45
|
+
NewRelic::Agent::MethodTracerHelpers.trace_execution_scoped(platform_key) do
|
46
|
+
yield
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def platform_authorized(platform_key)
|
51
|
+
NewRelic::Agent::MethodTracerHelpers.trace_execution_scoped(platform_key) do
|
52
|
+
yield
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def platform_resolve_type(platform_key)
|
57
|
+
NewRelic::Agent::MethodTracerHelpers.trace_execution_scoped(platform_key) do
|
58
|
+
yield
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def platform_field_key(field)
|
63
|
+
"GraphQL/#{field.owner.graphql_name}/#{field.graphql_name}"
|
64
|
+
end
|
65
|
+
|
66
|
+
def platform_authorized_key(type)
|
67
|
+
"GraphQL/Authorize/#{type.graphql_name}"
|
68
|
+
end
|
69
|
+
|
70
|
+
def platform_resolve_type_key(type)
|
71
|
+
"GraphQL/ResolveType/#{type.graphql_name}"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GraphQL
|
4
|
+
module Tracing
|
5
|
+
# This implementation forwards events to a notification handler (i.e.
|
6
|
+
# ActiveSupport::Notifications or Dry::Monitor::Notifications)
|
7
|
+
# with a `graphql` suffix.
|
8
|
+
module NotificationsTrace
|
9
|
+
# Initialize a new NotificationsTracing instance
|
10
|
+
#
|
11
|
+
# @param engine [#instrument(key, metadata, block)] The notifications engine to use
|
12
|
+
def initialize(engine:, **rest)
|
13
|
+
@notifications_engine = engine
|
14
|
+
super
|
15
|
+
end
|
16
|
+
|
17
|
+
{
|
18
|
+
"lex" => "lex.graphql",
|
19
|
+
"parse" => "parse.graphql",
|
20
|
+
"validate" => "validate.graphql",
|
21
|
+
"analyze_multiplex" => "analyze_multiplex.graphql",
|
22
|
+
"analyze_query" => "analyze_query.graphql",
|
23
|
+
"execute_query" => "execute_query.graphql",
|
24
|
+
"execute_query_lazy" => "execute_query_lazy.graphql",
|
25
|
+
"execute_field" => "execute_field.graphql",
|
26
|
+
"execute_field_lazy" => "execute_field_lazy.graphql",
|
27
|
+
"authorized" => "authorized.graphql",
|
28
|
+
"authorized_lazy" => "authorized_lazy.graphql",
|
29
|
+
"resolve_type" => "resolve_type.graphql",
|
30
|
+
"resolve_type_lazy" => "resolve_type.graphql",
|
31
|
+
}.each do |trace_method, platform_key|
|
32
|
+
module_eval <<-RUBY, __FILE__, __LINE__
|
33
|
+
def #{trace_method}(**metadata, &blk)
|
34
|
+
@notifications_engine.instrument("#{platform_key}", metadata, &blk)
|
35
|
+
end
|
36
|
+
RUBY
|
37
|
+
end
|
38
|
+
|
39
|
+
include PlatformTrace
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GraphQL
|
4
|
+
module Tracing
|
5
|
+
module PlatformTrace
|
6
|
+
def initialize(trace_scalars: false, **_options)
|
7
|
+
@trace_scalars = trace_scalars
|
8
|
+
@platform_field_key_cache = Hash.new { |h, k| h[k] = platform_field_key(k) }
|
9
|
+
@platform_authorized_key_cache = Hash.new { |h, k| h[k] = platform_authorized_key(k) }
|
10
|
+
@platform_resolve_type_key_cache = Hash.new { |h, k| h[k] = platform_resolve_type_key(k) }
|
11
|
+
super
|
12
|
+
end
|
13
|
+
|
14
|
+
def platform_execute_field_lazy(*args, &block)
|
15
|
+
platform_execute_field(*args, &block)
|
16
|
+
end
|
17
|
+
|
18
|
+
def platform_authorized_lazy(key, &block)
|
19
|
+
platform_authorized(key, &block)
|
20
|
+
end
|
21
|
+
|
22
|
+
def platform_resolve_type_lazy(key, &block)
|
23
|
+
platform_resolve_type(key, &block)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.included(child_class)
|
27
|
+
# Don't gather this unless necessary
|
28
|
+
pass_data_to_execute_field = child_class.method_defined?(:platform_execute_field) &&
|
29
|
+
child_class.instance_method(:platform_execute_field).arity != 1
|
30
|
+
|
31
|
+
[:execute_field, :execute_field_lazy].each do |field_trace_method|
|
32
|
+
if !child_class.method_defined?(field_trace_method)
|
33
|
+
child_class.module_eval <<-RUBY, __FILE__, __LINE__
|
34
|
+
def #{field_trace_method}(query:, field:, ast_node:, arguments:, object:)
|
35
|
+
return_type = field.type.unwrap
|
36
|
+
trace_field = if return_type.kind.scalar? || return_type.kind.enum?
|
37
|
+
(field.trace.nil? && @trace_scalars) || field.trace
|
38
|
+
else
|
39
|
+
true
|
40
|
+
end
|
41
|
+
platform_key = if trace_field
|
42
|
+
@platform_field_key_cache[field]
|
43
|
+
else
|
44
|
+
nil
|
45
|
+
end
|
46
|
+
if platform_key && trace_field
|
47
|
+
platform_#{field_trace_method}(platform_key#{pass_data_to_execute_field ? ", { query: query, field: field, ast_node: ast_node, arguments: arguments, object: object }" : ""}) do
|
48
|
+
super
|
49
|
+
end
|
50
|
+
else
|
51
|
+
super
|
52
|
+
end
|
53
|
+
end
|
54
|
+
RUBY
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
[:authorized, :authorized_lazy].each do |auth_trace_method|
|
60
|
+
if !child_class.method_defined?(auth_trace_method)
|
61
|
+
child_class.module_eval <<-RUBY, __FILE__, __LINE__
|
62
|
+
def #{auth_trace_method}(type:, query:, object:)
|
63
|
+
platform_key = @platform_authorized_key_cache[type]
|
64
|
+
platform_#{auth_trace_method}(platform_key) do
|
65
|
+
super
|
66
|
+
end
|
67
|
+
end
|
68
|
+
RUBY
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
[:resolve_type, :resolve_type_lazy].each do |rt_trace_method|
|
73
|
+
if !child_class.method_defined?(rt_trace_method)
|
74
|
+
child_class.module_eval <<-RUBY, __FILE__, __LINE__
|
75
|
+
def #{rt_trace_method}(query:, type:, object:)
|
76
|
+
platform_key = @platform_resolve_type_key_cache[type]
|
77
|
+
platform_#{rt_trace_method}(platform_key) do
|
78
|
+
super
|
79
|
+
end
|
80
|
+
end
|
81
|
+
RUBY
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
private
|
89
|
+
|
90
|
+
# Get the transaction name based on the operation type and name if possible, or fall back to a user provided
|
91
|
+
# one. Useful for anonymous queries.
|
92
|
+
def transaction_name(query)
|
93
|
+
selected_op = query.selected_operation
|
94
|
+
txn_name = if selected_op
|
95
|
+
op_type = selected_op.operation_type
|
96
|
+
op_name = selected_op.name || fallback_transaction_name(query.context) || "anonymous"
|
97
|
+
"#{op_type}.#{op_name}"
|
98
|
+
else
|
99
|
+
"query.anonymous"
|
100
|
+
end
|
101
|
+
"GraphQL/#{txn_name}"
|
102
|
+
end
|
103
|
+
|
104
|
+
def fallback_transaction_name(context)
|
105
|
+
context[:tracing_fallback_transaction_name]
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -10,6 +10,10 @@ module GraphQL
|
|
10
10
|
class PlatformTracing
|
11
11
|
class << self
|
12
12
|
attr_accessor :platform_keys
|
13
|
+
|
14
|
+
def inherited(child_class)
|
15
|
+
child_class.platform_keys = self.platform_keys
|
16
|
+
end
|
13
17
|
end
|
14
18
|
|
15
19
|
def initialize(options = {})
|
@@ -26,25 +30,19 @@ module GraphQL
|
|
26
30
|
yield
|
27
31
|
end
|
28
32
|
when "execute_field", "execute_field_lazy"
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
+
field = data[:field]
|
34
|
+
return_type = field.type.unwrap
|
35
|
+
trace_field = if return_type.kind.scalar? || return_type.kind.enum?
|
36
|
+
(field.trace.nil? && @trace_scalars) || field.trace
|
33
37
|
else
|
34
|
-
|
35
|
-
|
36
|
-
trace_field = if return_type.kind.scalar? || return_type.kind.enum?
|
37
|
-
(field.trace.nil? && @trace_scalars) || field.trace
|
38
|
-
else
|
39
|
-
true
|
40
|
-
end
|
38
|
+
true
|
39
|
+
end
|
41
40
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
end
|
41
|
+
platform_key = if trace_field
|
42
|
+
context = data.fetch(:query).context
|
43
|
+
cached_platform_key(context, field, :field) { platform_field_key(field.owner, field) }
|
44
|
+
else
|
45
|
+
nil
|
48
46
|
end
|
49
47
|
|
50
48
|
if platform_key && trace_field
|
@@ -57,14 +55,14 @@ module GraphQL
|
|
57
55
|
when "authorized", "authorized_lazy"
|
58
56
|
type = data.fetch(:type)
|
59
57
|
context = data.fetch(:context)
|
60
|
-
platform_key = cached_platform_key(context, type) { platform_authorized_key(type) }
|
58
|
+
platform_key = cached_platform_key(context, type, :authorized) { platform_authorized_key(type) }
|
61
59
|
platform_trace(platform_key, key, data) do
|
62
60
|
yield
|
63
61
|
end
|
64
62
|
when "resolve_type", "resolve_type_lazy"
|
65
63
|
type = data.fetch(:type)
|
66
64
|
context = data.fetch(:context)
|
67
|
-
platform_key = cached_platform_key(context, type) { platform_resolve_type_key(type) }
|
65
|
+
platform_key = cached_platform_key(context, type, :resolve_type) { platform_resolve_type_key(type) }
|
68
66
|
platform_trace(platform_key, key, data) do
|
69
67
|
yield
|
70
68
|
end
|
@@ -74,32 +72,21 @@ module GraphQL
|
|
74
72
|
end
|
75
73
|
end
|
76
74
|
|
77
|
-
def
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
75
|
+
def self.use(schema_defn, options = {})
|
76
|
+
if options[:legacy_tracing]
|
77
|
+
tracer = self.new(**options)
|
78
|
+
schema_defn.tracer(tracer)
|
79
|
+
else
|
80
|
+
tracing_name = self.name.split("::").last
|
81
|
+
trace_name = tracing_name.sub("Tracing", "Trace")
|
82
|
+
if GraphQL::Tracing.const_defined?(trace_name, false)
|
83
|
+
trace_module = GraphQL::Tracing.const_get(trace_name)
|
84
|
+
schema_defn.trace_with(trace_module, **options)
|
83
85
|
else
|
84
|
-
|
86
|
+
tracer = self.new(**options)
|
87
|
+
schema_defn.tracer(tracer)
|
85
88
|
end
|
86
|
-
else
|
87
|
-
trace_field(type, field)
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
def trace_field(type, field)
|
92
|
-
new_f = field.redefine
|
93
|
-
new_f.metadata[:platform_key] = platform_field_key(type, field)
|
94
|
-
new_f
|
95
|
-
end
|
96
|
-
|
97
|
-
def self.use(schema_defn, options = {})
|
98
|
-
tracer = self.new(**options)
|
99
|
-
if !schema_defn.is_a?(Class)
|
100
|
-
schema_defn.instrument(:field, tracer)
|
101
89
|
end
|
102
|
-
schema_defn.tracer(tracer)
|
103
90
|
end
|
104
91
|
|
105
92
|
private
|
@@ -134,8 +121,11 @@ module GraphQL
|
|
134
121
|
#
|
135
122
|
# If the key isn't present, the given block is called and the result is cached for `key`.
|
136
123
|
#
|
124
|
+
# @param ctx [GraphQL::Query::Context]
|
125
|
+
# @param key [Class, GraphQL::Field] A part of the schema
|
126
|
+
# @param trace_phase [Symbol] The stage of execution being traced (used by OpenTelementry tracing)
|
137
127
|
# @return [String]
|
138
|
-
def cached_platform_key(ctx, key)
|
128
|
+
def cached_platform_key(ctx, key, trace_phase)
|
139
129
|
cache = ctx.namespace(self.class)[:platform_key_cache] ||= {}
|
140
130
|
cache.fetch(key) { cache[key] = yield }
|
141
131
|
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GraphQL
|
4
|
+
module Tracing
|
5
|
+
module PrometheusTrace
|
6
|
+
include PlatformTrace
|
7
|
+
|
8
|
+
def initialize(client: PrometheusExporter::Client.default, keys_whitelist: ["execute_field", "execute_field_lazy"], collector_type: "graphql", **rest)
|
9
|
+
@client = client
|
10
|
+
@keys_whitelist = keys_whitelist
|
11
|
+
@collector_type = collector_type
|
12
|
+
|
13
|
+
super(**rest)
|
14
|
+
end
|
15
|
+
|
16
|
+
{
|
17
|
+
'lex' => "graphql.lex",
|
18
|
+
'parse' => "graphql.parse",
|
19
|
+
'validate' => "graphql.validate",
|
20
|
+
'analyze_query' => "graphql.analyze",
|
21
|
+
'analyze_multiplex' => "graphql.analyze",
|
22
|
+
'execute_multiplex' => "graphql.execute",
|
23
|
+
'execute_query' => "graphql.execute",
|
24
|
+
'execute_query_lazy' => "graphql.execute",
|
25
|
+
}.each do |trace_method, platform_key|
|
26
|
+
module_eval <<-RUBY, __FILE__, __LINE__
|
27
|
+
def #{trace_method}(**data, &block)
|
28
|
+
instrument_execution("#{platform_key}", "#{trace_method}", &block)
|
29
|
+
end
|
30
|
+
RUBY
|
31
|
+
end
|
32
|
+
|
33
|
+
def platform_execute_field(platform_key, &block)
|
34
|
+
instrument_execution(platform_key, "execute_field", &block)
|
35
|
+
end
|
36
|
+
|
37
|
+
def platform_execute_field_lazy(platform_key, &block)
|
38
|
+
instrument_execution(platform_key, "execute_field_lazy", &block)
|
39
|
+
end
|
40
|
+
|
41
|
+
def platform_authorized(platform_key, &block)
|
42
|
+
instrument_execution(platform_key, "authorized", &block)
|
43
|
+
end
|
44
|
+
|
45
|
+
def platform_authorized_lazy(platform_key, &block)
|
46
|
+
instrument_execution(platform_key, "authorized_lazy", &block)
|
47
|
+
end
|
48
|
+
|
49
|
+
def platform_resolve_type(platform_key, &block)
|
50
|
+
instrument_execution(platform_key, "resolve_type", &block)
|
51
|
+
end
|
52
|
+
|
53
|
+
def platform_resolve_type_lazy(platform_key, &block)
|
54
|
+
instrument_execution(platform_key, "resolve_type_lazy", &block)
|
55
|
+
end
|
56
|
+
|
57
|
+
def platform_field_key(field)
|
58
|
+
field.path
|
59
|
+
end
|
60
|
+
|
61
|
+
def platform_authorized_key(type)
|
62
|
+
"#{type.graphql_name}.authorized"
|
63
|
+
end
|
64
|
+
|
65
|
+
def platform_resolve_type_key(type)
|
66
|
+
"#{type.graphql_name}.resolve_type"
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def instrument_execution(platform_key, key, &block)
|
72
|
+
if @keys_whitelist.include?(key)
|
73
|
+
start = ::Process.clock_gettime ::Process::CLOCK_MONOTONIC
|
74
|
+
result = block.call
|
75
|
+
duration = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC) - start
|
76
|
+
@client.send_json(
|
77
|
+
type: @collector_type,
|
78
|
+
duration: duration,
|
79
|
+
platform_key: platform_key,
|
80
|
+
key: key
|
81
|
+
)
|
82
|
+
result
|
83
|
+
else
|
84
|
+
yield
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -5,7 +5,7 @@ module GraphQL
|
|
5
5
|
class PrometheusTracing < PlatformTracing
|
6
6
|
class GraphQLCollector < ::PrometheusExporter::Server::TypeCollector
|
7
7
|
def initialize
|
8
|
-
@graphql_gauge = PrometheusExporter::Metric::
|
8
|
+
@graphql_gauge = PrometheusExporter::Metric::Base.default_aggregation.new(
|
9
9
|
'graphql_duration_seconds',
|
10
10
|
'Time spent in GraphQL operations, in seconds'
|
11
11
|
)
|
@@ -27,9 +27,9 @@ module GraphQL
|
|
27
27
|
super opts
|
28
28
|
end
|
29
29
|
|
30
|
-
def platform_trace(platform_key, key,
|
30
|
+
def platform_trace(platform_key, key, _data, &block)
|
31
31
|
return yield unless @keys_whitelist.include?(key)
|
32
|
-
instrument_execution(platform_key, key,
|
32
|
+
instrument_execution(platform_key, key, &block)
|
33
33
|
end
|
34
34
|
|
35
35
|
def platform_field_key(type, field)
|
@@ -46,7 +46,7 @@ module GraphQL
|
|
46
46
|
|
47
47
|
private
|
48
48
|
|
49
|
-
def instrument_execution(platform_key, key,
|
49
|
+
def instrument_execution(platform_key, key, &block)
|
50
50
|
start = ::Process.clock_gettime ::Process::CLOCK_MONOTONIC
|
51
51
|
result = block.call
|
52
52
|
duration = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC) - start
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GraphQL
|
4
|
+
module Tracing
|
5
|
+
module ScoutTrace
|
6
|
+
include PlatformTrace
|
7
|
+
|
8
|
+
INSTRUMENT_OPTS = { scope: true }
|
9
|
+
|
10
|
+
# @param set_transaction_name [Boolean] If true, the GraphQL operation name will be used as the transaction name.
|
11
|
+
# This is not advised if you run more than one query per HTTP request, for example, with `graphql-client` or multiplexing.
|
12
|
+
# It can also be specified per-query with `context[:set_scout_transaction_name]`.
|
13
|
+
def initialize(set_transaction_name: false, **_rest)
|
14
|
+
self.class.include(ScoutApm::Tracer)
|
15
|
+
@set_transaction_name = set_transaction_name
|
16
|
+
super
|
17
|
+
end
|
18
|
+
|
19
|
+
{
|
20
|
+
"lex" => "lex.graphql",
|
21
|
+
"parse" => "parse.graphql",
|
22
|
+
"validate" => "validate.graphql",
|
23
|
+
"analyze_query" => "analyze.graphql",
|
24
|
+
"analyze_multiplex" => "analyze.graphql",
|
25
|
+
"execute_multiplex" => "execute.graphql",
|
26
|
+
"execute_query" => "execute.graphql",
|
27
|
+
"execute_query_lazy" => "execute.graphql",
|
28
|
+
}.each do |trace_method, platform_key|
|
29
|
+
module_eval <<-RUBY, __FILE__, __LINE__
|
30
|
+
def #{trace_method}(**data)
|
31
|
+
#{
|
32
|
+
if trace_method == "execute_query"
|
33
|
+
<<-RUBY
|
34
|
+
set_this_txn_name = data[:query].context[:set_scout_transaction_name]
|
35
|
+
if set_this_txn_name == true || (set_this_txn_name.nil? && @set_transaction_name)
|
36
|
+
ScoutApm::Transaction.rename(transaction_name(data[:query]))
|
37
|
+
end
|
38
|
+
RUBY
|
39
|
+
end
|
40
|
+
}
|
41
|
+
|
42
|
+
self.class.instrument("GraphQL", "#{platform_key}", INSTRUMENT_OPTS) do
|
43
|
+
super
|
44
|
+
end
|
45
|
+
end
|
46
|
+
RUBY
|
47
|
+
end
|
48
|
+
|
49
|
+
def platform_execute_field(platform_key, &block)
|
50
|
+
self.class.instrument("GraphQL", platform_key, INSTRUMENT_OPTS, &block)
|
51
|
+
end
|
52
|
+
|
53
|
+
def platform_authorized(platform_key, &block)
|
54
|
+
self.class.instrument("GraphQL", platform_key, INSTRUMENT_OPTS, &block)
|
55
|
+
end
|
56
|
+
|
57
|
+
alias :platform_resolve_type :platform_authorized
|
58
|
+
|
59
|
+
def platform_field_key(field)
|
60
|
+
field.path
|
61
|
+
end
|
62
|
+
|
63
|
+
def platform_authorized_key(type)
|
64
|
+
"#{type.graphql_name}.authorized"
|
65
|
+
end
|
66
|
+
|
67
|
+
def platform_resolve_type_key(type)
|
68
|
+
"#{type.graphql_name}.resolve_type"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GraphQL
|
4
|
+
module Tracing
|
5
|
+
module StatsdTrace
|
6
|
+
include PlatformTrace
|
7
|
+
|
8
|
+
# @param statsd [Object] A statsd client
|
9
|
+
def initialize(statsd:, **rest)
|
10
|
+
@statsd = statsd
|
11
|
+
super(**rest)
|
12
|
+
end
|
13
|
+
|
14
|
+
{
|
15
|
+
'lex' => "graphql.lex",
|
16
|
+
'parse' => "graphql.parse",
|
17
|
+
'validate' => "graphql.validate",
|
18
|
+
'analyze_query' => "graphql.analyze_query",
|
19
|
+
'analyze_multiplex' => "graphql.analyze_multiplex",
|
20
|
+
'execute_multiplex' => "graphql.execute_multiplex",
|
21
|
+
'execute_query' => "graphql.execute_query",
|
22
|
+
'execute_query_lazy' => "graphql.execute_query_lazy",
|
23
|
+
}.each do |trace_method, platform_key|
|
24
|
+
module_eval <<-RUBY, __FILE__, __LINE__
|
25
|
+
def #{trace_method}(**data)
|
26
|
+
@statsd.time("#{platform_key}") do
|
27
|
+
super
|
28
|
+
end
|
29
|
+
end
|
30
|
+
RUBY
|
31
|
+
end
|
32
|
+
|
33
|
+
def platform_execute_field(platform_key, &block)
|
34
|
+
@statsd.time(platform_key, &block)
|
35
|
+
end
|
36
|
+
|
37
|
+
def platform_authorized(key, &block)
|
38
|
+
@statsd.time(key, &block)
|
39
|
+
end
|
40
|
+
|
41
|
+
alias :platform_resolve_type :platform_authorized
|
42
|
+
|
43
|
+
def platform_field_key(field)
|
44
|
+
"graphql.#{field.path}"
|
45
|
+
end
|
46
|
+
|
47
|
+
def platform_authorized_key(type)
|
48
|
+
"graphql.authorized.#{type.graphql_name}"
|
49
|
+
end
|
50
|
+
|
51
|
+
def platform_resolve_type_key(type)
|
52
|
+
"graphql.resolve_type.#{type.graphql_name}"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|