graphql 1.9.18 → 1.13.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/generators/graphql/core.rb +21 -10
- data/lib/generators/graphql/enum_generator.rb +4 -10
- data/lib/generators/graphql/field_extractor.rb +31 -0
- data/lib/generators/graphql/input_generator.rb +50 -0
- data/lib/generators/graphql/install/mutation_root_generator.rb +34 -0
- data/lib/generators/graphql/{templates → install/templates}/base_mutation.erb +2 -0
- data/lib/generators/graphql/{templates → install/templates}/mutation_type.erb +2 -0
- data/lib/generators/graphql/install_generator.rb +44 -7
- data/lib/generators/graphql/interface_generator.rb +7 -7
- data/lib/generators/graphql/loader_generator.rb +1 -0
- data/lib/generators/graphql/mutation_create_generator.rb +22 -0
- data/lib/generators/graphql/mutation_delete_generator.rb +22 -0
- data/lib/generators/graphql/mutation_generator.rb +6 -30
- data/lib/generators/graphql/mutation_update_generator.rb +22 -0
- data/lib/generators/graphql/object_generator.rb +28 -12
- data/lib/generators/graphql/orm_mutations_base.rb +40 -0
- data/lib/generators/graphql/relay.rb +63 -0
- data/lib/generators/graphql/relay_generator.rb +21 -0
- data/lib/generators/graphql/scalar_generator.rb +4 -2
- data/lib/generators/graphql/templates/base_argument.erb +2 -0
- data/lib/generators/graphql/templates/base_connection.erb +8 -0
- data/lib/generators/graphql/templates/base_edge.erb +8 -0
- data/lib/generators/graphql/templates/base_enum.erb +2 -0
- data/lib/generators/graphql/templates/base_field.erb +2 -0
- data/lib/generators/graphql/templates/base_input_object.erb +2 -0
- data/lib/generators/graphql/templates/base_interface.erb +2 -0
- data/lib/generators/graphql/templates/base_object.erb +2 -0
- data/lib/generators/graphql/templates/base_scalar.erb +2 -0
- data/lib/generators/graphql/templates/base_union.erb +2 -0
- data/lib/generators/graphql/templates/enum.erb +7 -1
- data/lib/generators/graphql/templates/graphql_controller.erb +16 -12
- data/lib/generators/graphql/templates/input.erb +9 -0
- data/lib/generators/graphql/templates/interface.erb +6 -2
- data/lib/generators/graphql/templates/loader.erb +2 -0
- data/lib/generators/graphql/templates/mutation.erb +3 -1
- data/lib/generators/graphql/templates/mutation_create.erb +20 -0
- data/lib/generators/graphql/templates/mutation_delete.erb +20 -0
- data/lib/generators/graphql/templates/mutation_update.erb +21 -0
- data/lib/generators/graphql/templates/node_type.erb +9 -0
- data/lib/generators/graphql/templates/object.erb +7 -3
- data/lib/generators/graphql/templates/query_type.erb +3 -3
- data/lib/generators/graphql/templates/scalar.erb +5 -1
- data/lib/generators/graphql/templates/schema.erb +22 -27
- data/lib/generators/graphql/templates/union.erb +6 -2
- data/lib/generators/graphql/type_generator.rb +47 -10
- data/lib/generators/graphql/union_generator.rb +5 -5
- data/lib/graphql/analysis/analyze_query.rb +7 -0
- data/lib/graphql/analysis/ast/field_usage.rb +29 -2
- data/lib/graphql/analysis/ast/query_complexity.rb +174 -67
- data/lib/graphql/analysis/ast/visitor.rb +16 -7
- data/lib/graphql/analysis/ast.rb +21 -11
- data/lib/graphql/argument.rb +8 -36
- data/lib/graphql/backtrace/inspect_result.rb +0 -1
- data/lib/graphql/backtrace/legacy_tracer.rb +56 -0
- data/lib/graphql/backtrace/table.rb +44 -5
- data/lib/graphql/backtrace/traced_error.rb +0 -1
- data/lib/graphql/backtrace/tracer.rb +40 -9
- data/lib/graphql/backtrace.rb +28 -19
- data/lib/graphql/backwards_compatibility.rb +2 -1
- data/lib/graphql/base_type.rb +10 -4
- data/lib/graphql/boolean_type.rb +1 -1
- data/lib/graphql/compatibility/execution_specification/specification_schema.rb +2 -2
- data/lib/graphql/compatibility/execution_specification.rb +1 -0
- data/lib/graphql/compatibility/lazy_execution_specification.rb +2 -0
- data/lib/graphql/compatibility/query_parser_specification/parse_error_specification.rb +5 -9
- data/lib/graphql/compatibility/query_parser_specification.rb +2 -0
- data/lib/graphql/compatibility/schema_parser_specification.rb +2 -0
- data/lib/graphql/dataloader/null_dataloader.rb +22 -0
- data/lib/graphql/dataloader/request.rb +19 -0
- data/lib/graphql/dataloader/request_all.rb +19 -0
- data/lib/graphql/dataloader/source.rb +155 -0
- data/lib/graphql/dataloader.rb +308 -0
- data/lib/graphql/date_encoding_error.rb +16 -0
- data/lib/graphql/define/assign_enum_value.rb +1 -1
- data/lib/graphql/define/assign_global_id_field.rb +2 -2
- data/lib/graphql/define/assign_object_field.rb +1 -1
- data/lib/graphql/define/defined_object_proxy.rb +5 -8
- data/lib/graphql/define/instance_definable.rb +60 -110
- data/lib/graphql/define/type_definer.rb +5 -5
- data/lib/graphql/deprecated_dsl.rb +18 -5
- data/lib/graphql/deprecation.rb +9 -0
- data/lib/graphql/directive/deprecated_directive.rb +1 -12
- data/lib/graphql/directive/include_directive.rb +1 -1
- data/lib/graphql/directive/skip_directive.rb +1 -1
- data/lib/graphql/directive.rb +9 -6
- data/lib/graphql/enum_type.rb +14 -74
- data/lib/graphql/execution/directive_checks.rb +2 -2
- data/lib/graphql/execution/errors.rb +110 -8
- data/lib/graphql/execution/execute.rb +8 -1
- data/lib/graphql/execution/instrumentation.rb +1 -1
- data/lib/graphql/execution/interpreter/argument_value.rb +28 -0
- data/lib/graphql/execution/interpreter/arguments.rb +88 -0
- data/lib/graphql/execution/interpreter/arguments_cache.rb +105 -0
- data/lib/graphql/execution/interpreter/handles_raw_value.rb +18 -0
- data/lib/graphql/execution/interpreter/resolve.rb +37 -25
- data/lib/graphql/execution/interpreter/runtime.rb +721 -386
- data/lib/graphql/execution/interpreter.rb +42 -19
- data/lib/graphql/execution/lazy/lazy_method_map.rb +4 -0
- data/lib/graphql/execution/lazy.rb +5 -1
- data/lib/graphql/execution/lookahead.rb +39 -114
- data/lib/graphql/execution/multiplex.rb +50 -25
- data/lib/graphql/field.rb +15 -119
- data/lib/graphql/filter.rb +1 -1
- data/lib/graphql/float_type.rb +1 -1
- data/lib/graphql/function.rb +5 -30
- data/lib/graphql/id_type.rb +1 -1
- data/lib/graphql/input_object_type.rb +9 -25
- data/lib/graphql/int_type.rb +1 -1
- data/lib/graphql/integer_decoding_error.rb +17 -0
- data/lib/graphql/integer_encoding_error.rb +18 -2
- data/lib/graphql/interface_type.rb +10 -24
- data/lib/graphql/internal_representation/document.rb +2 -2
- data/lib/graphql/internal_representation/rewrite.rb +1 -1
- data/lib/graphql/internal_representation/scope.rb +2 -2
- data/lib/graphql/internal_representation/visit.rb +2 -2
- data/lib/graphql/introspection/base_object.rb +2 -5
- data/lib/graphql/introspection/directive_location_enum.rb +2 -2
- data/lib/graphql/introspection/directive_type.rb +12 -6
- data/lib/graphql/introspection/entry_points.rb +9 -9
- data/lib/graphql/introspection/enum_value_type.rb +2 -2
- data/lib/graphql/introspection/field_type.rb +9 -5
- data/lib/graphql/introspection/input_value_type.rb +41 -11
- data/lib/graphql/introspection/introspection_query.rb +6 -92
- data/lib/graphql/introspection/schema_type.rb +12 -12
- data/lib/graphql/introspection/type_type.rb +27 -17
- data/lib/graphql/introspection.rb +99 -0
- data/lib/graphql/invalid_null_error.rb +18 -0
- data/lib/graphql/language/block_string.rb +20 -5
- data/lib/graphql/language/cache.rb +37 -0
- data/lib/graphql/language/definition_slice.rb +21 -10
- data/lib/graphql/language/document_from_schema_definition.rb +116 -63
- data/lib/graphql/language/lexer.rb +53 -27
- data/lib/graphql/language/lexer.rl +5 -3
- data/lib/graphql/language/nodes.rb +67 -93
- data/lib/graphql/language/parser.rb +929 -896
- data/lib/graphql/language/parser.y +125 -102
- data/lib/graphql/language/printer.rb +11 -2
- data/lib/graphql/language/sanitized_printer.rb +222 -0
- data/lib/graphql/language/token.rb +0 -4
- data/lib/graphql/language/visitor.rb +2 -2
- data/lib/graphql/language.rb +3 -1
- data/lib/graphql/name_validator.rb +2 -7
- data/lib/graphql/non_null_type.rb +0 -10
- data/lib/graphql/object_type.rb +47 -58
- data/lib/graphql/pagination/active_record_relation_connection.rb +85 -0
- data/lib/graphql/pagination/array_connection.rb +77 -0
- data/lib/graphql/pagination/connection.rb +226 -0
- data/lib/graphql/pagination/connections.rb +160 -0
- data/lib/graphql/pagination/mongoid_relation_connection.rb +25 -0
- data/lib/graphql/pagination/relation_connection.rb +226 -0
- data/lib/graphql/pagination/sequel_dataset_connection.rb +28 -0
- data/lib/graphql/pagination.rb +6 -0
- data/lib/graphql/parse_error.rb +0 -1
- data/lib/graphql/query/arguments.rb +6 -4
- data/lib/graphql/query/arguments_cache.rb +1 -2
- data/lib/graphql/query/context.rb +52 -7
- data/lib/graphql/query/executor.rb +0 -1
- data/lib/graphql/query/fingerprint.rb +26 -0
- data/lib/graphql/query/input_validation_result.rb +32 -6
- data/lib/graphql/query/literal_input.rb +31 -11
- data/lib/graphql/query/null_context.rb +24 -8
- data/lib/graphql/query/serial_execution/field_resolution.rb +1 -1
- data/lib/graphql/query/serial_execution.rb +1 -0
- data/lib/graphql/query/validation_pipeline.rb +6 -4
- data/lib/graphql/query/variable_validation_error.rb +3 -3
- data/lib/graphql/query/variables.rb +50 -10
- data/lib/graphql/query.rb +77 -18
- data/lib/graphql/railtie.rb +9 -1
- data/lib/graphql/rake_task/validate.rb +3 -0
- data/lib/graphql/rake_task.rb +12 -9
- data/lib/graphql/relay/array_connection.rb +10 -12
- data/lib/graphql/relay/base_connection.rb +30 -13
- data/lib/graphql/relay/connection_instrumentation.rb +4 -4
- data/lib/graphql/relay/connection_type.rb +18 -4
- data/lib/graphql/relay/edge_type.rb +1 -0
- data/lib/graphql/relay/edges_instrumentation.rb +1 -2
- data/lib/graphql/relay/global_id_resolve.rb +1 -2
- data/lib/graphql/relay/mutation.rb +3 -87
- data/lib/graphql/relay/node.rb +3 -0
- data/lib/graphql/relay/page_info.rb +1 -1
- data/lib/graphql/relay/range_add.rb +27 -9
- data/lib/graphql/relay/relation_connection.rb +8 -10
- data/lib/graphql/relay/type_extensions.rb +2 -0
- data/lib/graphql/rubocop/graphql/base_cop.rb +36 -0
- data/lib/graphql/rubocop/graphql/default_null_true.rb +43 -0
- data/lib/graphql/rubocop/graphql/default_required_true.rb +43 -0
- data/lib/graphql/rubocop.rb +4 -0
- data/lib/graphql/scalar_type.rb +18 -60
- data/lib/graphql/schema/addition.rb +247 -0
- data/lib/graphql/schema/argument.rb +274 -18
- data/lib/graphql/schema/base_64_encoder.rb +2 -0
- data/lib/graphql/schema/build_from_definition/resolve_map/default_resolve.rb +1 -1
- data/lib/graphql/schema/build_from_definition/resolve_map.rb +13 -5
- data/lib/graphql/schema/build_from_definition.rb +320 -219
- data/lib/graphql/schema/built_in_types.rb +5 -5
- data/lib/graphql/schema/default_type_error.rb +2 -0
- data/lib/graphql/schema/directive/deprecated.rb +18 -0
- data/lib/graphql/schema/directive/feature.rb +1 -1
- data/lib/graphql/schema/directive/flagged.rb +57 -0
- data/lib/graphql/schema/directive/include.rb +2 -2
- data/lib/graphql/schema/directive/skip.rb +2 -2
- data/lib/graphql/schema/directive/transform.rb +14 -2
- data/lib/graphql/schema/directive.rb +130 -6
- data/lib/graphql/schema/enum.rb +121 -12
- data/lib/graphql/schema/enum_value.rb +24 -7
- data/lib/graphql/schema/field/connection_extension.rb +46 -20
- data/lib/graphql/schema/field/scope_extension.rb +1 -1
- data/lib/graphql/schema/field.rb +465 -181
- data/lib/graphql/schema/field_extension.rb +89 -2
- data/lib/graphql/schema/find_inherited_value.rb +17 -1
- data/lib/graphql/schema/finder.rb +16 -14
- data/lib/graphql/schema/input_object.rb +172 -37
- data/lib/graphql/schema/interface.rb +39 -25
- data/lib/graphql/schema/introspection_system.rb +106 -38
- data/lib/graphql/schema/late_bound_type.rb +3 -2
- data/lib/graphql/schema/list.rb +65 -1
- data/lib/graphql/schema/loader.rb +145 -102
- data/lib/graphql/schema/member/accepts_definition.rb +15 -3
- data/lib/graphql/schema/member/base_dsl_methods.rb +34 -28
- data/lib/graphql/schema/member/build_type.rb +19 -8
- data/lib/graphql/schema/member/cached_graphql_definition.rb +34 -2
- data/lib/graphql/schema/member/has_arguments.rb +206 -13
- data/lib/graphql/schema/member/has_ast_node.rb +20 -0
- data/lib/graphql/schema/member/has_deprecation_reason.rb +25 -0
- data/lib/graphql/schema/member/has_directives.rb +98 -0
- data/lib/graphql/schema/member/has_fields.rb +97 -32
- data/lib/graphql/schema/member/has_interfaces.rb +100 -0
- data/lib/graphql/schema/member/has_unresolved_type_error.rb +15 -0
- data/lib/graphql/schema/member/has_validators.rb +31 -0
- data/lib/graphql/schema/member/instrumentation.rb +0 -1
- data/lib/graphql/schema/member/type_system_helpers.rb +3 -3
- data/lib/graphql/schema/member/validates_input.rb +33 -0
- data/lib/graphql/schema/member.rb +11 -0
- data/lib/graphql/schema/middleware_chain.rb +1 -1
- data/lib/graphql/schema/mutation.rb +4 -0
- data/lib/graphql/schema/non_null.rb +37 -1
- data/lib/graphql/schema/object.rb +51 -38
- data/lib/graphql/schema/possible_types.rb +9 -4
- data/lib/graphql/schema/printer.rb +16 -35
- data/lib/graphql/schema/relay_classic_mutation.rb +40 -4
- data/lib/graphql/schema/resolver/has_payload_type.rb +34 -4
- data/lib/graphql/schema/resolver.rb +133 -79
- data/lib/graphql/schema/scalar.rb +43 -3
- data/lib/graphql/schema/subscription.rb +57 -21
- data/lib/graphql/schema/timeout.rb +29 -15
- data/lib/graphql/schema/timeout_middleware.rb +3 -1
- data/lib/graphql/schema/traversal.rb +2 -2
- data/lib/graphql/schema/type_expression.rb +21 -13
- data/lib/graphql/schema/type_membership.rb +19 -5
- data/lib/graphql/schema/union.rb +44 -3
- data/lib/graphql/schema/unique_within_type.rb +1 -2
- data/lib/graphql/schema/validation.rb +14 -4
- data/lib/graphql/schema/validator/allow_blank_validator.rb +29 -0
- data/lib/graphql/schema/validator/allow_null_validator.rb +26 -0
- data/lib/graphql/schema/validator/exclusion_validator.rb +33 -0
- data/lib/graphql/schema/validator/format_validator.rb +48 -0
- data/lib/graphql/schema/validator/inclusion_validator.rb +35 -0
- data/lib/graphql/schema/validator/length_validator.rb +59 -0
- data/lib/graphql/schema/validator/numericality_validator.rb +82 -0
- data/lib/graphql/schema/validator/required_validator.rb +82 -0
- data/lib/graphql/schema/validator.rb +171 -0
- data/lib/graphql/schema/warden.rb +193 -34
- data/lib/graphql/schema.rb +882 -247
- data/lib/graphql/static_validation/all_rules.rb +2 -0
- data/lib/graphql/static_validation/base_visitor.rb +17 -10
- data/lib/graphql/static_validation/definition_dependencies.rb +0 -1
- data/lib/graphql/static_validation/error.rb +3 -1
- data/lib/graphql/static_validation/literal_validator.rb +51 -26
- data/lib/graphql/static_validation/rules/argument_literals_are_compatible.rb +45 -83
- data/lib/graphql/static_validation/rules/argument_literals_are_compatible_error.rb +22 -6
- data/lib/graphql/static_validation/rules/arguments_are_defined.rb +35 -26
- data/lib/graphql/static_validation/rules/arguments_are_defined_error.rb +4 -2
- data/lib/graphql/static_validation/rules/directives_are_defined.rb +1 -1
- data/lib/graphql/static_validation/rules/directives_are_in_valid_locations.rb +2 -2
- data/lib/graphql/static_validation/rules/fields_are_defined_on_type.rb +4 -4
- data/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb +5 -5
- data/lib/graphql/static_validation/rules/fields_will_merge.rb +94 -51
- data/lib/graphql/static_validation/rules/fields_will_merge_error.rb +25 -4
- data/lib/graphql/static_validation/rules/fragment_spreads_are_possible.rb +3 -3
- data/lib/graphql/static_validation/rules/fragments_are_finite.rb +2 -2
- data/lib/graphql/static_validation/rules/input_object_names_are_unique.rb +30 -0
- data/lib/graphql/static_validation/rules/input_object_names_are_unique_error.rb +30 -0
- data/lib/graphql/static_validation/rules/query_root_exists.rb +17 -0
- data/lib/graphql/static_validation/rules/query_root_exists_error.rb +26 -0
- data/lib/graphql/static_validation/rules/required_arguments_are_present.rb +4 -2
- data/lib/graphql/static_validation/rules/required_input_object_attributes_are_present.rb +9 -10
- data/lib/graphql/static_validation/rules/unique_directives_per_location.rb +1 -1
- data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed.rb +12 -13
- data/lib/graphql/static_validation/rules/variable_usages_are_allowed.rb +19 -14
- data/lib/graphql/static_validation/rules/variables_are_input_types.rb +1 -1
- data/lib/graphql/static_validation/rules/variables_are_used_and_defined.rb +5 -3
- data/lib/graphql/static_validation/type_stack.rb +2 -2
- data/lib/graphql/static_validation/validation_context.rb +13 -3
- data/lib/graphql/static_validation/validation_timeout_error.rb +25 -0
- data/lib/graphql/static_validation/validator.rb +43 -9
- data/lib/graphql/static_validation.rb +1 -0
- data/lib/graphql/string_encoding_error.rb +13 -3
- data/lib/graphql/string_type.rb +1 -1
- data/lib/graphql/subscriptions/action_cable_subscriptions.rb +123 -22
- data/lib/graphql/subscriptions/broadcast_analyzer.rb +81 -0
- data/lib/graphql/subscriptions/default_subscription_resolve_extension.rb +21 -0
- data/lib/graphql/subscriptions/event.rb +84 -30
- data/lib/graphql/subscriptions/instrumentation.rb +10 -6
- data/lib/graphql/subscriptions/serialize.rb +53 -6
- data/lib/graphql/subscriptions/subscription_root.rb +15 -5
- data/lib/graphql/subscriptions.rb +117 -49
- data/lib/graphql/tracing/active_support_notifications_tracing.rb +8 -17
- data/lib/graphql/tracing/appoptics_tracing.rb +173 -0
- data/lib/graphql/tracing/appsignal_tracing.rb +23 -0
- data/lib/graphql/tracing/data_dog_tracing.rb +32 -15
- data/lib/graphql/tracing/new_relic_tracing.rb +9 -12
- data/lib/graphql/tracing/notifications_tracing.rb +59 -0
- data/lib/graphql/tracing/platform_tracing.rb +66 -10
- data/lib/graphql/tracing/prometheus_tracing/graphql_collector.rb +4 -1
- data/lib/graphql/tracing/prometheus_tracing.rb +8 -0
- data/lib/graphql/tracing/scout_tracing.rb +19 -0
- data/lib/graphql/tracing/skylight_tracing.rb +9 -1
- data/lib/graphql/tracing/statsd_tracing.rb +42 -0
- data/lib/graphql/tracing.rb +15 -35
- data/lib/graphql/types/big_int.rb +5 -1
- data/lib/graphql/types/int.rb +10 -3
- data/lib/graphql/types/iso_8601_date.rb +16 -8
- data/lib/graphql/types/iso_8601_date_time.rb +32 -10
- data/lib/graphql/types/relay/base_connection.rb +6 -88
- data/lib/graphql/types/relay/base_edge.rb +2 -34
- data/lib/graphql/types/relay/connection_behaviors.rb +174 -0
- data/lib/graphql/types/relay/default_relay.rb +31 -0
- data/lib/graphql/types/relay/edge_behaviors.rb +64 -0
- data/lib/graphql/types/relay/has_node_field.rb +41 -0
- data/lib/graphql/types/relay/has_nodes_field.rb +41 -0
- data/lib/graphql/types/relay/node.rb +2 -4
- data/lib/graphql/types/relay/node_behaviors.rb +15 -0
- data/lib/graphql/types/relay/node_field.rb +3 -22
- data/lib/graphql/types/relay/nodes_field.rb +16 -18
- data/lib/graphql/types/relay/page_info.rb +2 -14
- data/lib/graphql/types/relay/page_info_behaviors.rb +25 -0
- data/lib/graphql/types/relay.rb +11 -3
- data/lib/graphql/types/string.rb +8 -2
- data/lib/graphql/unauthorized_error.rb +2 -2
- data/lib/graphql/union_type.rb +5 -25
- data/lib/graphql/unresolved_type_error.rb +2 -2
- data/lib/graphql/upgrader/member.rb +1 -0
- data/lib/graphql/upgrader/schema.rb +1 -0
- data/lib/graphql/version.rb +1 -1
- data/lib/graphql.rb +87 -31
- data/readme.md +3 -6
- metadata +126 -124
- data/lib/graphql/execution/interpreter/hash_response.rb +0 -46
- data/lib/graphql/literal_validation_error.rb +0 -6
- data/lib/graphql/types/relay/base_field.rb +0 -22
- data/lib/graphql/types/relay/base_interface.rb +0 -29
- data/lib/graphql/types/relay/base_object.rb +0 -26
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module GraphQL
|
|
4
|
+
module Tracing
|
|
5
|
+
|
|
6
|
+
# This class uses the AppopticsAPM SDK from the appoptics_apm gem to create
|
|
7
|
+
# traces for GraphQL.
|
|
8
|
+
#
|
|
9
|
+
# There are 4 configurations available. They can be set in the
|
|
10
|
+
# appoptics_apm config file or in code. Please see:
|
|
11
|
+
# {https://docs.appoptics.com/kb/apm_tracing/ruby/configure}
|
|
12
|
+
#
|
|
13
|
+
# AppOpticsAPM::Config[:graphql][:enabled] = true|false
|
|
14
|
+
# AppOpticsAPM::Config[:graphql][:transaction_name] = true|false
|
|
15
|
+
# AppOpticsAPM::Config[:graphql][:sanitize_query] = true|false
|
|
16
|
+
# AppOpticsAPM::Config[:graphql][:remove_comments] = true|false
|
|
17
|
+
class AppOpticsTracing < GraphQL::Tracing::PlatformTracing
|
|
18
|
+
# These GraphQL events will show up as 'graphql.prep' spans
|
|
19
|
+
PREP_KEYS = ['lex', 'parse', 'validate', 'analyze_query', 'analyze_multiplex'].freeze
|
|
20
|
+
# These GraphQL events will show up as 'graphql.execute' spans
|
|
21
|
+
EXEC_KEYS = ['execute_multiplex', 'execute_query', 'execute_query_lazy'].freeze
|
|
22
|
+
|
|
23
|
+
# During auto-instrumentation this version of AppOpticsTracing is compared
|
|
24
|
+
# with the version provided in the appoptics_apm gem, so that the newer
|
|
25
|
+
# version of the class can be used
|
|
26
|
+
|
|
27
|
+
def self.version
|
|
28
|
+
Gem::Version.new('1.0.0')
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
self.platform_keys = {
|
|
32
|
+
'lex' => 'lex',
|
|
33
|
+
'parse' => 'parse',
|
|
34
|
+
'validate' => 'validate',
|
|
35
|
+
'analyze_query' => 'analyze_query',
|
|
36
|
+
'analyze_multiplex' => 'analyze_multiplex',
|
|
37
|
+
'execute_multiplex' => 'execute_multiplex',
|
|
38
|
+
'execute_query' => 'execute_query',
|
|
39
|
+
'execute_query_lazy' => 'execute_query_lazy'
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
def platform_trace(platform_key, _key, data)
|
|
43
|
+
return yield if !defined?(AppOpticsAPM) || gql_config[:enabled] == false
|
|
44
|
+
|
|
45
|
+
layer = span_name(platform_key)
|
|
46
|
+
kvs = metadata(data, layer)
|
|
47
|
+
kvs[:Key] = platform_key if (PREP_KEYS + EXEC_KEYS).include?(platform_key)
|
|
48
|
+
|
|
49
|
+
transaction_name(kvs[:InboundQuery]) if kvs[:InboundQuery] && layer == 'graphql.execute'
|
|
50
|
+
|
|
51
|
+
::AppOpticsAPM::SDK.trace(layer, kvs) do
|
|
52
|
+
kvs.clear # we don't have to send them twice
|
|
53
|
+
yield
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def platform_field_key(type, field)
|
|
58
|
+
"graphql.#{type.graphql_name}.#{field.graphql_name}"
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def platform_authorized_key(type)
|
|
62
|
+
"graphql.authorized.#{type.graphql_name}"
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def platform_resolve_type_key(type)
|
|
66
|
+
"graphql.resolve_type.#{type.graphql_name}"
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
private
|
|
70
|
+
|
|
71
|
+
def gql_config
|
|
72
|
+
::AppOpticsAPM::Config[:graphql] ||= {}
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def transaction_name(query)
|
|
76
|
+
return if gql_config[:transaction_name] == false ||
|
|
77
|
+
::AppOpticsAPM::SDK.get_transaction_name
|
|
78
|
+
|
|
79
|
+
split_query = query.strip.split(/\W+/, 3)
|
|
80
|
+
split_query[0] = 'query' if split_query[0].empty?
|
|
81
|
+
name = "graphql.#{split_query[0..1].join('.')}"
|
|
82
|
+
|
|
83
|
+
::AppOpticsAPM::SDK.set_transaction_name(name)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def multiplex_transaction_name(names)
|
|
87
|
+
return if gql_config[:transaction_name] == false ||
|
|
88
|
+
::AppOpticsAPM::SDK.get_transaction_name
|
|
89
|
+
|
|
90
|
+
name = "graphql.multiplex.#{names.join('.')}"
|
|
91
|
+
name = "#{name[0..251]}..." if name.length > 254
|
|
92
|
+
|
|
93
|
+
::AppOpticsAPM::SDK.set_transaction_name(name)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def span_name(key)
|
|
97
|
+
return 'graphql.prep' if PREP_KEYS.include?(key)
|
|
98
|
+
return 'graphql.execute' if EXEC_KEYS.include?(key)
|
|
99
|
+
|
|
100
|
+
key[/^graphql\./] ? key : "graphql.#{key}"
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
|
104
|
+
def metadata(data, layer)
|
|
105
|
+
data.keys.map do |key|
|
|
106
|
+
case key
|
|
107
|
+
when :context
|
|
108
|
+
graphql_context(data[key], layer)
|
|
109
|
+
when :query
|
|
110
|
+
graphql_query(data[key])
|
|
111
|
+
when :query_string
|
|
112
|
+
graphql_query_string(data[key])
|
|
113
|
+
when :multiplex
|
|
114
|
+
graphql_multiplex(data[key])
|
|
115
|
+
when :path
|
|
116
|
+
[key, data[key].join(".")]
|
|
117
|
+
else
|
|
118
|
+
[key, data[key]]
|
|
119
|
+
end
|
|
120
|
+
end.flatten(2).each_slice(2).to_h.merge(Spec: 'graphql')
|
|
121
|
+
end
|
|
122
|
+
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
|
123
|
+
|
|
124
|
+
def graphql_context(context, layer)
|
|
125
|
+
context.errors && context.errors.each do |err|
|
|
126
|
+
AppOpticsAPM::API.log_exception(layer, err)
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
[[:Path, context.path.join('.')]]
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def graphql_query(query)
|
|
133
|
+
return [] unless query
|
|
134
|
+
|
|
135
|
+
query_string = query.query_string
|
|
136
|
+
query_string = remove_comments(query_string) if gql_config[:remove_comments] != false
|
|
137
|
+
query_string = sanitize(query_string) if gql_config[:sanitize_query] != false
|
|
138
|
+
|
|
139
|
+
[[:InboundQuery, query_string],
|
|
140
|
+
[:Operation, query.selected_operation_name]]
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
def graphql_query_string(query_string)
|
|
144
|
+
query_string = remove_comments(query_string) if gql_config[:remove_comments] != false
|
|
145
|
+
query_string = sanitize(query_string) if gql_config[:sanitize_query] != false
|
|
146
|
+
|
|
147
|
+
[:InboundQuery, query_string]
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def graphql_multiplex(data)
|
|
151
|
+
names = data.queries.map(&:operations).map(&:keys).flatten.compact
|
|
152
|
+
multiplex_transaction_name(names) if names.size > 1
|
|
153
|
+
|
|
154
|
+
[:Operations, names.join(', ')]
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
def sanitize(query)
|
|
158
|
+
return unless query
|
|
159
|
+
|
|
160
|
+
# remove arguments
|
|
161
|
+
query.gsub(/"[^"]*"/, '"?"') # strings
|
|
162
|
+
.gsub(/-?[0-9]*\.?[0-9]+e?[0-9]*/, '?') # ints + floats
|
|
163
|
+
.gsub(/\[[^\]]*\]/, '[?]') # arrays
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
def remove_comments(query)
|
|
167
|
+
return unless query
|
|
168
|
+
|
|
169
|
+
query.gsub(/#[^\n\r]*/, '')
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
end
|
|
@@ -14,7 +14,22 @@ module GraphQL
|
|
|
14
14
|
"execute_query_lazy" => "execute.graphql",
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
# @param set_action_name [Boolean] If true, the GraphQL operation name will be used as the transaction name.
|
|
18
|
+
# This is not advised if you run more than one query per HTTP request, for example, with `graphql-client` or multiplexing.
|
|
19
|
+
# It can also be specified per-query with `context[:set_appsignal_action_name]`.
|
|
20
|
+
def initialize(options = {})
|
|
21
|
+
@set_action_name = options.fetch(:set_action_name, false)
|
|
22
|
+
super
|
|
23
|
+
end
|
|
24
|
+
|
|
17
25
|
def platform_trace(platform_key, key, data)
|
|
26
|
+
if key == "execute_query"
|
|
27
|
+
set_this_txn_name = data[:query].context[:set_appsignal_action_name]
|
|
28
|
+
if set_this_txn_name == true || (set_this_txn_name.nil? && @set_action_name)
|
|
29
|
+
Appsignal::Transaction.current.set_action(transaction_name(data[:query]))
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
18
33
|
Appsignal.instrument(platform_key) do
|
|
19
34
|
yield
|
|
20
35
|
end
|
|
@@ -23,6 +38,14 @@ module GraphQL
|
|
|
23
38
|
def platform_field_key(type, field)
|
|
24
39
|
"#{type.graphql_name}.#{field.graphql_name}.graphql"
|
|
25
40
|
end
|
|
41
|
+
|
|
42
|
+
def platform_authorized_key(type)
|
|
43
|
+
"#{type.graphql_name}.authorized.graphql"
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def platform_resolve_type_key(type)
|
|
47
|
+
"#{type.graphql_name}.resolve_type.graphql"
|
|
48
|
+
end
|
|
26
49
|
end
|
|
27
50
|
end
|
|
28
51
|
end
|
|
@@ -15,17 +15,23 @@ module GraphQL
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
def platform_trace(platform_key, key, data)
|
|
18
|
-
tracer.trace(platform_key, service:
|
|
19
|
-
span.
|
|
18
|
+
tracer.trace(platform_key, service: options[:service], type: 'custom') do |span|
|
|
19
|
+
span.set_tag('component', 'graphql')
|
|
20
|
+
span.set_tag('operation', key)
|
|
20
21
|
|
|
21
22
|
if key == 'execute_multiplex'
|
|
22
23
|
operations = data[:multiplex].queries.map(&:selected_operation_name).join(', ')
|
|
23
|
-
span.resource = operations unless operations.empty?
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
resource = if operations.empty?
|
|
26
|
+
first_query = data[:multiplex].queries.first
|
|
27
|
+
fallback_transaction_name(first_query && first_query.context)
|
|
28
|
+
else
|
|
29
|
+
operations
|
|
28
30
|
end
|
|
31
|
+
span.resource = resource if resource
|
|
32
|
+
|
|
33
|
+
# [Deprecated] will be removed in the future
|
|
34
|
+
span.set_metric('_dd1.sr.eausr', analytics_sample_rate) if analytics_enabled?
|
|
29
35
|
end
|
|
30
36
|
|
|
31
37
|
if key == 'execute_query'
|
|
@@ -34,26 +40,29 @@ module GraphQL
|
|
|
34
40
|
span.set_tag(:query_string, data[:query].query_string)
|
|
35
41
|
end
|
|
36
42
|
|
|
43
|
+
prepare_span(key, data, span)
|
|
44
|
+
|
|
37
45
|
yield
|
|
38
46
|
end
|
|
39
47
|
end
|
|
40
48
|
|
|
41
|
-
|
|
42
|
-
|
|
49
|
+
# Implement this method in a subclass to apply custom tags to datadog spans
|
|
50
|
+
# @param key [String] The event being traced
|
|
51
|
+
# @param data [Hash] The runtime data for this event (@see GraphQL::Tracing for keys for each event)
|
|
52
|
+
# @param span [Datadog::Tracing::SpanOperation] The datadog span for this event
|
|
53
|
+
def prepare_span(key, data, span)
|
|
43
54
|
end
|
|
44
55
|
|
|
45
56
|
def tracer
|
|
46
|
-
|
|
47
|
-
end
|
|
57
|
+
default_tracer = defined?(Datadog::Tracing) ? Datadog::Tracing : Datadog.tracer
|
|
48
58
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
&& Datadog::Contrib::Analytics.respond_to?(:enabled?) \
|
|
52
|
-
&& Datadog::Contrib::Analytics.respond_to?(:set_sample_rate)
|
|
59
|
+
# [Deprecated] options[:tracer] will be removed in the future
|
|
60
|
+
options.fetch(:tracer, default_tracer)
|
|
53
61
|
end
|
|
54
62
|
|
|
55
63
|
def analytics_enabled?
|
|
56
|
-
|
|
64
|
+
# [Deprecated] options[:analytics_enabled] will be removed in the future
|
|
65
|
+
options.fetch(:analytics_enabled, false)
|
|
57
66
|
end
|
|
58
67
|
|
|
59
68
|
def analytics_sample_rate
|
|
@@ -63,6 +72,14 @@ module GraphQL
|
|
|
63
72
|
def platform_field_key(type, field)
|
|
64
73
|
"#{type.graphql_name}.#{field.graphql_name}"
|
|
65
74
|
end
|
|
75
|
+
|
|
76
|
+
def platform_authorized_key(type)
|
|
77
|
+
"#{type.graphql_name}.authorized"
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def platform_resolve_type_key(type)
|
|
81
|
+
"#{type.graphql_name}.resolve_type"
|
|
82
|
+
end
|
|
66
83
|
end
|
|
67
84
|
end
|
|
68
85
|
end
|
|
@@ -26,18 +26,7 @@ module GraphQL
|
|
|
26
26
|
if key == "execute_query"
|
|
27
27
|
set_this_txn_name = data[:query].context[:set_new_relic_transaction_name]
|
|
28
28
|
if set_this_txn_name == true || (set_this_txn_name.nil? && @set_transaction_name)
|
|
29
|
-
|
|
30
|
-
# Set the transaction name based on the operation type and name
|
|
31
|
-
selected_op = query.selected_operation
|
|
32
|
-
if selected_op
|
|
33
|
-
op_type = selected_op.operation_type
|
|
34
|
-
op_name = selected_op.name || "anonymous"
|
|
35
|
-
else
|
|
36
|
-
op_type = "query"
|
|
37
|
-
op_name = "anonymous"
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
NewRelic::Agent.set_transaction_name("GraphQL/#{op_type}.#{op_name}")
|
|
29
|
+
NewRelic::Agent.set_transaction_name(transaction_name(data[:query]))
|
|
41
30
|
end
|
|
42
31
|
end
|
|
43
32
|
|
|
@@ -49,6 +38,14 @@ module GraphQL
|
|
|
49
38
|
def platform_field_key(type, field)
|
|
50
39
|
"GraphQL/#{type.graphql_name}/#{field.graphql_name}"
|
|
51
40
|
end
|
|
41
|
+
|
|
42
|
+
def platform_authorized_key(type)
|
|
43
|
+
"GraphQL/Authorize/#{type.graphql_name}"
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def platform_resolve_type_key(type)
|
|
47
|
+
"GraphQL/ResolveType/#{type.graphql_name}"
|
|
48
|
+
end
|
|
52
49
|
end
|
|
53
50
|
end
|
|
54
51
|
end
|
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
#
|
|
9
|
+
# @see KEYS for event names
|
|
10
|
+
class NotificationsTracing
|
|
11
|
+
# A cache of frequently-used keys to avoid needless string allocations
|
|
12
|
+
KEYS = {
|
|
13
|
+
"lex" => "lex.graphql",
|
|
14
|
+
"parse" => "parse.graphql",
|
|
15
|
+
"validate" => "validate.graphql",
|
|
16
|
+
"analyze_multiplex" => "analyze_multiplex.graphql",
|
|
17
|
+
"analyze_query" => "analyze_query.graphql",
|
|
18
|
+
"execute_query" => "execute_query.graphql",
|
|
19
|
+
"execute_query_lazy" => "execute_query_lazy.graphql",
|
|
20
|
+
"execute_field" => "execute_field.graphql",
|
|
21
|
+
"execute_field_lazy" => "execute_field_lazy.graphql",
|
|
22
|
+
"authorized" => "authorized.graphql",
|
|
23
|
+
"authorized_lazy" => "authorized_lazy.graphql",
|
|
24
|
+
"resolve_type" => "resolve_type.graphql",
|
|
25
|
+
"resolve_type_lazy" => "resolve_type.graphql",
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
MAX_KEYS_SIZE = 100
|
|
29
|
+
|
|
30
|
+
# Initialize a new NotificationsTracing instance
|
|
31
|
+
#
|
|
32
|
+
# @param [Object] notifications_engine The notifications engine to use
|
|
33
|
+
def initialize(notifications_engine)
|
|
34
|
+
@notifications_engine = notifications_engine
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Sends a GraphQL tracing event to the notification handler
|
|
38
|
+
#
|
|
39
|
+
# @example
|
|
40
|
+
# . notifications_engine = Dry::Monitor::Notifications.new(:graphql)
|
|
41
|
+
# . tracer = GraphQL::Tracing::NotificationsTracing.new(notifications_engine)
|
|
42
|
+
# . tracer.trace("lex") { ... }
|
|
43
|
+
#
|
|
44
|
+
# @param [string] key The key for the event
|
|
45
|
+
# @param [Hash] metadata The metadata for the event
|
|
46
|
+
# @yield The block to execute for the event
|
|
47
|
+
def trace(key, metadata, &blk)
|
|
48
|
+
prefixed_key = KEYS[key] || "#{key}.graphql"
|
|
49
|
+
|
|
50
|
+
# Cache the new keys while making sure not to induce a memory leak
|
|
51
|
+
if KEYS.size < MAX_KEYS_SIZE
|
|
52
|
+
KEYS[key] ||= prefixed_key
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
@notifications_engine.instrument(prefixed_key, metadata, &blk)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
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 = {})
|
|
@@ -21,7 +25,6 @@ module GraphQL
|
|
|
21
25
|
def trace(key, data)
|
|
22
26
|
case key
|
|
23
27
|
when "lex", "parse", "validate", "analyze_query", "analyze_multiplex", "execute_query", "execute_query_lazy", "execute_multiplex"
|
|
24
|
-
data.fetch(:query).context.namespace(self.class)[:platform_key_cache] = {} if key == "execute_query"
|
|
25
28
|
platform_key = @platform_keys.fetch(key)
|
|
26
29
|
platform_trace(platform_key, key, data) do
|
|
27
30
|
yield
|
|
@@ -33,18 +36,20 @@ module GraphQL
|
|
|
33
36
|
trace_field = true # implemented with instrumenter
|
|
34
37
|
else
|
|
35
38
|
field = data[:field]
|
|
36
|
-
|
|
37
|
-
platform_key = platform_key_cache.fetch(field) do
|
|
38
|
-
platform_key_cache[field] = platform_field_key(data[:owner], field)
|
|
39
|
-
end
|
|
40
|
-
|
|
39
|
+
# HERE
|
|
41
40
|
return_type = field.type.unwrap
|
|
42
|
-
|
|
43
|
-
trace_field = if return_type.respond_to?(:kind) && (return_type.kind.scalar? || return_type.kind.enum?)
|
|
41
|
+
trace_field = if return_type.kind.scalar? || return_type.kind.enum?
|
|
44
42
|
(field.trace.nil? && @trace_scalars) || field.trace
|
|
45
43
|
else
|
|
46
44
|
true
|
|
47
45
|
end
|
|
46
|
+
|
|
47
|
+
platform_key = if trace_field
|
|
48
|
+
context = data.fetch(:query).context
|
|
49
|
+
cached_platform_key(context, field, :field) { platform_field_key(data[:owner], field) }
|
|
50
|
+
else
|
|
51
|
+
nil
|
|
52
|
+
end
|
|
48
53
|
end
|
|
49
54
|
|
|
50
55
|
if platform_key && trace_field
|
|
@@ -54,6 +59,20 @@ module GraphQL
|
|
|
54
59
|
else
|
|
55
60
|
yield
|
|
56
61
|
end
|
|
62
|
+
when "authorized", "authorized_lazy"
|
|
63
|
+
type = data.fetch(:type)
|
|
64
|
+
context = data.fetch(:context)
|
|
65
|
+
platform_key = cached_platform_key(context, type, :authorized) { platform_authorized_key(type) }
|
|
66
|
+
platform_trace(platform_key, key, data) do
|
|
67
|
+
yield
|
|
68
|
+
end
|
|
69
|
+
when "resolve_type", "resolve_type_lazy"
|
|
70
|
+
type = data.fetch(:type)
|
|
71
|
+
context = data.fetch(:context)
|
|
72
|
+
platform_key = cached_platform_key(context, type, :resolve_type) { platform_resolve_type_key(type) }
|
|
73
|
+
platform_trace(platform_key, key, data) do
|
|
74
|
+
yield
|
|
75
|
+
end
|
|
57
76
|
else
|
|
58
77
|
# it's a custom key
|
|
59
78
|
yield
|
|
@@ -81,13 +100,50 @@ module GraphQL
|
|
|
81
100
|
end
|
|
82
101
|
|
|
83
102
|
def self.use(schema_defn, options = {})
|
|
84
|
-
tracer = self.new(options)
|
|
85
|
-
schema_defn.
|
|
103
|
+
tracer = self.new(**options)
|
|
104
|
+
if !schema_defn.is_a?(Class)
|
|
105
|
+
schema_defn.instrument(:field, tracer)
|
|
106
|
+
end
|
|
86
107
|
schema_defn.tracer(tracer)
|
|
87
108
|
end
|
|
88
109
|
|
|
89
110
|
private
|
|
111
|
+
|
|
112
|
+
# Get the transaction name based on the operation type and name if possible, or fall back to a user provided
|
|
113
|
+
# one. Useful for anonymous queries.
|
|
114
|
+
def transaction_name(query)
|
|
115
|
+
selected_op = query.selected_operation
|
|
116
|
+
txn_name = if selected_op
|
|
117
|
+
op_type = selected_op.operation_type
|
|
118
|
+
op_name = selected_op.name || fallback_transaction_name(query.context) || "anonymous"
|
|
119
|
+
"#{op_type}.#{op_name}"
|
|
120
|
+
else
|
|
121
|
+
"query.anonymous"
|
|
122
|
+
end
|
|
123
|
+
"GraphQL/#{txn_name}"
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def fallback_transaction_name(context)
|
|
127
|
+
context[:tracing_fallback_transaction_name]
|
|
128
|
+
end
|
|
129
|
+
|
|
90
130
|
attr_reader :options
|
|
131
|
+
|
|
132
|
+
# Different kind of schema objects have different kinds of keys:
|
|
133
|
+
#
|
|
134
|
+
# - Object types: `.authorized`
|
|
135
|
+
# - Union/Interface types: `.resolve_type`
|
|
136
|
+
# - Fields: execution
|
|
137
|
+
#
|
|
138
|
+
# So, they can all share one cache.
|
|
139
|
+
#
|
|
140
|
+
# If the key isn't present, the given block is called and the result is cached for `key`.
|
|
141
|
+
#
|
|
142
|
+
# @return [String]
|
|
143
|
+
def cached_platform_key(ctx, key, trace_phase)
|
|
144
|
+
cache = ctx.namespace(self.class)[:platform_key_cache] ||= {}
|
|
145
|
+
cache.fetch(key) { cache[key] = yield }
|
|
146
|
+
end
|
|
91
147
|
end
|
|
92
148
|
end
|
|
93
149
|
end
|
|
@@ -16,7 +16,10 @@ module GraphQL
|
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
def collect(object)
|
|
19
|
-
|
|
19
|
+
default_labels = { key: object['key'], platform_key: object['platform_key'] }
|
|
20
|
+
custom = object['custom_labels']
|
|
21
|
+
labels = custom.nil? ? default_labels : default_labels.merge(custom)
|
|
22
|
+
|
|
20
23
|
@graphql_gauge.observe object['duration'], labels
|
|
21
24
|
end
|
|
22
25
|
|
|
@@ -36,6 +36,14 @@ module GraphQL
|
|
|
36
36
|
"#{type.graphql_name}.#{field.graphql_name}"
|
|
37
37
|
end
|
|
38
38
|
|
|
39
|
+
def platform_authorized_key(type)
|
|
40
|
+
"#{type.graphql_name}.authorized"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def platform_resolve_type_key(type)
|
|
44
|
+
"#{type.graphql_name}.resolve_type"
|
|
45
|
+
end
|
|
46
|
+
|
|
39
47
|
private
|
|
40
48
|
|
|
41
49
|
def instrument_execution(platform_key, key, data, &block)
|
|
@@ -16,12 +16,23 @@ module GraphQL
|
|
|
16
16
|
"execute_query_lazy" => "execute.graphql",
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
# @param set_transaction_name [Boolean] If true, the GraphQL operation name will be used as the transaction name.
|
|
20
|
+
# This is not advised if you run more than one query per HTTP request, for example, with `graphql-client` or multiplexing.
|
|
21
|
+
# It can also be specified per-query with `context[:set_scout_transaction_name]`.
|
|
19
22
|
def initialize(options = {})
|
|
20
23
|
self.class.include ScoutApm::Tracer
|
|
24
|
+
@set_transaction_name = options.fetch(:set_transaction_name, false)
|
|
21
25
|
super(options)
|
|
22
26
|
end
|
|
23
27
|
|
|
24
28
|
def platform_trace(platform_key, key, data)
|
|
29
|
+
if key == "execute_query"
|
|
30
|
+
set_this_txn_name = data[:query].context[:set_scout_transaction_name]
|
|
31
|
+
if set_this_txn_name == true || (set_this_txn_name.nil? && @set_transaction_name)
|
|
32
|
+
ScoutApm::Transaction.rename(transaction_name(data[:query]))
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
25
36
|
self.class.instrument("GraphQL", platform_key, INSTRUMENT_OPTS) do
|
|
26
37
|
yield
|
|
27
38
|
end
|
|
@@ -30,6 +41,14 @@ module GraphQL
|
|
|
30
41
|
def platform_field_key(type, field)
|
|
31
42
|
"#{type.graphql_name}.#{field.graphql_name}"
|
|
32
43
|
end
|
|
44
|
+
|
|
45
|
+
def platform_authorized_key(type)
|
|
46
|
+
"#{type.graphql_name}.authorized"
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def platform_resolve_type_key(type)
|
|
50
|
+
"#{type.graphql_name}.resolve_type"
|
|
51
|
+
end
|
|
33
52
|
end
|
|
34
53
|
end
|
|
35
54
|
end
|
|
@@ -18,7 +18,7 @@ module GraphQL
|
|
|
18
18
|
# This is not advised if you run more than one query per HTTP request, for example, with `graphql-client` or multiplexing.
|
|
19
19
|
# It can also be specified per-query with `context[:set_skylight_endpoint_name]`.
|
|
20
20
|
def initialize(options = {})
|
|
21
|
-
warn("GraphQL::Tracing::SkylightTracing is deprecated, please enable Skylight's GraphQL probe instead: https://www.skylight.io/support/getting-more-from-skylight#graphql.")
|
|
21
|
+
GraphQL::Deprecation.warn("GraphQL::Tracing::SkylightTracing is deprecated and will be removed in GraphQL-Ruby 2.0, please enable Skylight's GraphQL probe instead: https://www.skylight.io/support/getting-more-from-skylight#graphql.")
|
|
22
22
|
@set_endpoint_name = options.fetch(:set_endpoint_name, false)
|
|
23
23
|
super
|
|
24
24
|
end
|
|
@@ -57,6 +57,14 @@ module GraphQL
|
|
|
57
57
|
def platform_field_key(type, field)
|
|
58
58
|
"graphql.#{type.graphql_name}.#{field.graphql_name}"
|
|
59
59
|
end
|
|
60
|
+
|
|
61
|
+
def platform_authorized_key(type)
|
|
62
|
+
"graphql.authorized.#{type.graphql_name}"
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def platform_resolve_type_key(type)
|
|
66
|
+
"graphql.resolve_type.#{type.graphql_name}"
|
|
67
|
+
end
|
|
60
68
|
end
|
|
61
69
|
end
|
|
62
70
|
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module GraphQL
|
|
4
|
+
module Tracing
|
|
5
|
+
class StatsdTracing < PlatformTracing
|
|
6
|
+
self.platform_keys = {
|
|
7
|
+
'lex' => "graphql.lex",
|
|
8
|
+
'parse' => "graphql.parse",
|
|
9
|
+
'validate' => "graphql.validate",
|
|
10
|
+
'analyze_query' => "graphql.analyze_query",
|
|
11
|
+
'analyze_multiplex' => "graphql.analyze_multiplex",
|
|
12
|
+
'execute_multiplex' => "graphql.execute_multiplex",
|
|
13
|
+
'execute_query' => "graphql.execute_query",
|
|
14
|
+
'execute_query_lazy' => "graphql.execute_query_lazy",
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
# @param statsd [Object] A statsd client
|
|
18
|
+
def initialize(statsd:, **rest)
|
|
19
|
+
@statsd = statsd
|
|
20
|
+
super(**rest)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def platform_trace(platform_key, key, data)
|
|
24
|
+
@statsd.time(platform_key) do
|
|
25
|
+
yield
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def platform_field_key(type, field)
|
|
30
|
+
"graphql.#{type.graphql_name}.#{field.graphql_name}"
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def platform_authorized_key(type)
|
|
34
|
+
"graphql.authorized.#{type.graphql_name}"
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def platform_resolve_type_key(type)
|
|
38
|
+
"graphql.resolve_type.#{type.graphql_name}"
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|