graphql 2.6.12 → 2.6.13
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/.rdoc_options +4 -0
- data/lib/generators/graphql/core.rb +1 -0
- data/lib/generators/graphql/detailed_trace_generator.rb +1 -0
- data/lib/generators/graphql/enum_generator.rb +1 -0
- data/lib/generators/graphql/field_extractor.rb +1 -0
- data/lib/generators/graphql/input_generator.rb +1 -0
- data/lib/generators/graphql/install/mutation_root_generator.rb +1 -0
- data/lib/generators/graphql/install_generator.rb +1 -0
- data/lib/generators/graphql/interface_generator.rb +1 -0
- data/lib/generators/graphql/loader_generator.rb +8 -2
- data/lib/generators/graphql/mutation_create_generator.rb +8 -2
- data/lib/generators/graphql/mutation_delete_generator.rb +8 -2
- data/lib/generators/graphql/mutation_generator.rb +8 -2
- data/lib/generators/graphql/mutation_update_generator.rb +8 -2
- data/lib/generators/graphql/object_generator.rb +1 -0
- data/lib/generators/graphql/orm_mutations_base.rb +8 -2
- data/lib/generators/graphql/relay.rb +1 -0
- data/lib/generators/graphql/relay_generator.rb +1 -0
- data/lib/generators/graphql/scalar_generator.rb +1 -0
- data/lib/generators/graphql/type_generator.rb +38 -8
- data/lib/generators/graphql/union_generator.rb +1 -0
- data/lib/graphql/analysis/analyzer.rb +35 -9
- data/lib/graphql/analysis/field_usage.rb +1 -0
- data/lib/graphql/analysis/max_query_complexity.rb +2 -1
- data/lib/graphql/analysis/max_query_depth.rb +1 -0
- data/lib/graphql/analysis/query_complexity.rb +57 -20
- data/lib/graphql/analysis/query_depth.rb +17 -12
- data/lib/graphql/analysis/visitor.rb +79 -16
- data/lib/graphql/analysis.rb +23 -6
- data/lib/graphql/analysis_error.rb +1 -0
- data/lib/graphql/autoload.rb +30 -7
- data/lib/graphql/backtrace/table.rb +21 -5
- data/lib/graphql/backtrace/traced_error.rb +8 -3
- data/lib/graphql/backtrace.rb +14 -9
- data/lib/graphql/coercion_error.rb +1 -0
- data/lib/graphql/current.rb +44 -19
- data/lib/graphql/dashboard/application_controller.rb +1 -0
- data/lib/graphql/dashboard/detailed_traces.rb +1 -0
- data/lib/graphql/dashboard/installable.rb +1 -0
- data/lib/graphql/dashboard/landings_controller.rb +1 -0
- data/lib/graphql/dashboard/limiters.rb +1 -0
- data/lib/graphql/dashboard/operation_store.rb +1 -0
- data/lib/graphql/dashboard/statics_controller.rb +1 -0
- data/lib/graphql/dashboard/subscriptions.rb +1 -0
- data/lib/graphql/dashboard.rb +36 -22
- data/lib/graphql/dataloader/active_record_association_source.rb +1 -0
- data/lib/graphql/dataloader/active_record_source.rb +1 -0
- data/lib/graphql/dataloader/async_dataloader.rb +8 -7
- data/lib/graphql/dataloader/null_dataloader.rb +4 -3
- data/lib/graphql/dataloader/request.rb +8 -2
- data/lib/graphql/dataloader/request_all.rb +8 -2
- data/lib/graphql/dataloader/source.rb +127 -35
- data/lib/graphql/dataloader.rb +91 -42
- data/lib/graphql/date_encoding_error.rb +2 -1
- data/lib/graphql/dig.rb +12 -3
- data/lib/graphql/duration_encoding_error.rb +2 -1
- data/lib/graphql/execution/directive_checks.rb +8 -3
- data/lib/graphql/execution/errors.rb +20 -6
- data/lib/graphql/execution/field_resolve_step.rb +22 -6
- data/lib/graphql/execution/finalize.rb +12 -6
- data/lib/graphql/execution/input_values.rb +2 -1
- data/lib/graphql/execution/interpreter/argument_value.rb +17 -5
- data/lib/graphql/execution/interpreter/arguments.rb +24 -9
- data/lib/graphql/execution/interpreter/arguments_cache.rb +2 -1
- data/lib/graphql/execution/interpreter/execution_errors.rb +1 -0
- data/lib/graphql/execution/interpreter/handles_raw_value.rb +1 -0
- data/lib/graphql/execution/interpreter/resolve.rb +18 -8
- data/lib/graphql/execution/interpreter/runtime/graphql_result.rb +4 -1
- data/lib/graphql/execution/interpreter/runtime.rb +66 -23
- data/lib/graphql/execution/interpreter.rb +15 -6
- data/lib/graphql/execution/lazy/lazy_method_map.rb +21 -8
- data/lib/graphql/execution/lazy.rb +34 -10
- data/lib/graphql/execution/load_argument_step.rb +1 -0
- data/lib/graphql/execution/lookahead.rb +137 -54
- data/lib/graphql/execution/multiplex.rb +4 -4
- data/lib/graphql/execution/next.rb +7 -0
- data/lib/graphql/execution/prepare_object_step.rb +1 -0
- data/lib/graphql/execution/resolve_type_step.rb +2 -1
- data/lib/graphql/execution/runner.rb +9 -3
- data/lib/graphql/execution/selections_step.rb +3 -2
- data/lib/graphql/execution.rb +2 -2
- data/lib/graphql/execution_error.rb +19 -10
- data/lib/graphql/float_decoding_error.rb +1 -0
- data/lib/graphql/float_encoding_error.rb +7 -2
- data/lib/graphql/integer_decoding_error.rb +2 -1
- data/lib/graphql/integer_encoding_error.rb +8 -3
- data/lib/graphql/introspection/base_object.rb +3 -1
- data/lib/graphql/introspection/directive_location_enum.rb +1 -0
- data/lib/graphql/introspection/directive_type.rb +1 -0
- data/lib/graphql/introspection/dynamic_fields.rb +1 -0
- data/lib/graphql/introspection/entry_points.rb +1 -0
- data/lib/graphql/introspection/enum_value_type.rb +1 -0
- data/lib/graphql/introspection/field_type.rb +1 -0
- data/lib/graphql/introspection/input_value_type.rb +1 -0
- data/lib/graphql/introspection/introspection_query.rb +1 -0
- data/lib/graphql/introspection/schema_type.rb +1 -0
- data/lib/graphql/introspection/type_kind_enum.rb +1 -0
- data/lib/graphql/introspection/type_type.rb +1 -0
- data/lib/graphql/introspection.rb +1 -0
- data/lib/graphql/invalid_name_error.rb +1 -0
- data/lib/graphql/invalid_null_error.rb +19 -6
- data/lib/graphql/language/block_string.rb +2 -1
- data/lib/graphql/language/cache.rb +10 -4
- data/lib/graphql/language/comment.rb +1 -0
- data/lib/graphql/language/definition_slice.rb +1 -0
- data/lib/graphql/language/document_from_schema_definition.rb +9 -10
- data/lib/graphql/language/generation.rb +23 -9
- data/lib/graphql/language/lexer.rb +5 -0
- data/lib/graphql/language/nodes.rb +2094 -419
- data/lib/graphql/language/parser.rb +17 -11
- data/lib/graphql/language/printer.rb +31 -16
- data/lib/graphql/language/sanitized_printer.rb +16 -5
- data/lib/graphql/language/static_visitor.rb +19 -4
- data/lib/graphql/language/visitor.rb +51 -29
- data/lib/graphql/language.rb +13 -7
- data/lib/graphql/load_application_object_failed_error.rb +14 -5
- data/lib/graphql/name_validator.rb +1 -0
- data/lib/graphql/pagination/active_record_relation_connection.rb +1 -0
- data/lib/graphql/pagination/array_connection.rb +20 -6
- data/lib/graphql/pagination/connection.rb +178 -48
- data/lib/graphql/pagination/connections.rb +21 -14
- data/lib/graphql/pagination/mongoid_relation_connection.rb +1 -0
- data/lib/graphql/pagination/relation_connection.rb +118 -21
- data/lib/graphql/pagination/sequel_dataset_connection.rb +1 -0
- data/lib/graphql/pagination.rb +1 -0
- data/lib/graphql/parse_error.rb +1 -0
- data/lib/graphql/query/context/scoped_context.rb +2 -1
- data/lib/graphql/query/context.rb +106 -35
- data/lib/graphql/query/fingerprint.rb +15 -7
- data/lib/graphql/query/input_validation_result.rb +1 -0
- data/lib/graphql/query/null_context.rb +1 -0
- data/lib/graphql/query/partial.rb +28 -15
- data/lib/graphql/query/result.rb +15 -5
- data/lib/graphql/query/validation_pipeline.rb +16 -6
- data/lib/graphql/query/variable_validation_error.rb +1 -0
- data/lib/graphql/query/variables.rb +4 -1
- data/lib/graphql/query.rb +193 -49
- data/lib/graphql/railtie.rb +7 -3
- data/lib/graphql/rake_task/validate.rb +72 -17
- data/lib/graphql/rake_task.rb +55 -23
- data/lib/graphql/relay/range_add.rb +32 -21
- data/lib/graphql/relay.rb +1 -0
- data/lib/graphql/rubocop/graphql/base_cop.rb +1 -0
- data/lib/graphql/rubocop/graphql/default_null_true.rb +9 -6
- data/lib/graphql/rubocop/graphql/default_required_true.rb +9 -6
- data/lib/graphql/rubocop/graphql/field_type_in_block.rb +12 -8
- data/lib/graphql/rubocop/graphql/root_types_in_block.rb +9 -5
- data/lib/graphql/rubocop.rb +1 -0
- data/lib/graphql/runtime_error.rb +1 -0
- data/lib/graphql/runtime_type_error.rb +1 -0
- data/lib/graphql/schema/addition.rb +18 -6
- data/lib/graphql/schema/always_visible.rb +1 -0
- data/lib/graphql/schema/argument.rb +265 -42
- data/lib/graphql/schema/base_64_encoder.rb +2 -2
- data/lib/graphql/schema/build_from_definition/resolve_map/default_resolve.rb +1 -0
- data/lib/graphql/schema/build_from_definition/resolve_map.rb +2 -2
- data/lib/graphql/schema/build_from_definition.rb +94 -27
- data/lib/graphql/schema/built_in_types.rb +1 -0
- data/lib/graphql/schema/directive/deprecated.rb +1 -0
- data/lib/graphql/schema/directive/feature.rb +39 -22
- data/lib/graphql/schema/directive/flagged.rb +6 -1
- data/lib/graphql/schema/directive/include.rb +1 -0
- data/lib/graphql/schema/directive/one_of.rb +1 -0
- data/lib/graphql/schema/directive/skip.rb +1 -0
- data/lib/graphql/schema/directive/specified_by.rb +1 -0
- data/lib/graphql/schema/directive/transform.rb +17 -8
- data/lib/graphql/schema/directive.rb +12 -7
- data/lib/graphql/schema/enum.rb +99 -38
- data/lib/graphql/schema/enum_value.rb +21 -13
- data/lib/graphql/schema/field/connection_extension.rb +10 -2
- data/lib/graphql/schema/field/scope_extension.rb +1 -0
- data/lib/graphql/schema/field.rb +621 -109
- data/lib/graphql/schema/field_extension.rb +89 -34
- data/lib/graphql/schema/find_inherited_value.rb +5 -3
- data/lib/graphql/schema/finder.rb +22 -8
- data/lib/graphql/schema/has_single_input_argument.rb +39 -6
- data/lib/graphql/schema/input_object.rb +40 -13
- data/lib/graphql/schema/interface.rb +33 -17
- data/lib/graphql/schema/introspection_system.rb +7 -3
- data/lib/graphql/schema/late_bound_type.rb +2 -2
- data/lib/graphql/schema/list.rb +15 -4
- data/lib/graphql/schema/loader.rb +23 -12
- data/lib/graphql/schema/member/base_dsl_methods.rb +58 -12
- data/lib/graphql/schema/member/build_type.rb +16 -5
- data/lib/graphql/schema/member/graphql_type_names.rb +10 -6
- data/lib/graphql/schema/member/has_arguments.rb +115 -48
- data/lib/graphql/schema/member/has_ast_node.rb +1 -0
- data/lib/graphql/schema/member/has_authorization.rb +5 -0
- data/lib/graphql/schema/member/has_dataloader.rb +91 -34
- data/lib/graphql/schema/member/has_deprecation_reason.rb +15 -2
- data/lib/graphql/schema/member/has_directives.rb +38 -10
- data/lib/graphql/schema/member/has_fields.rb +151 -70
- data/lib/graphql/schema/member/has_interfaces.rb +10 -2
- data/lib/graphql/schema/member/has_path.rb +14 -5
- data/lib/graphql/schema/member/has_unresolved_type_error.rb +1 -0
- data/lib/graphql/schema/member/has_validators.rb +19 -4
- data/lib/graphql/schema/member/relay_shortcuts.rb +10 -2
- data/lib/graphql/schema/member/scoped.rb +14 -3
- data/lib/graphql/schema/member/type_system_helpers.rb +36 -6
- data/lib/graphql/schema/member/validates_input.rb +1 -0
- data/lib/graphql/schema/member.rb +9 -2
- data/lib/graphql/schema/mutation.rb +50 -46
- data/lib/graphql/schema/non_null.rb +21 -5
- data/lib/graphql/schema/object.rb +33 -12
- data/lib/graphql/schema/printer.rb +52 -31
- data/lib/graphql/schema/ractor_shareable.rb +6 -2
- data/lib/graphql/schema/relay_classic_mutation.rb +3 -3
- data/lib/graphql/schema/resolver/has_payload_type.rb +29 -7
- data/lib/graphql/schema/resolver.rb +156 -45
- data/lib/graphql/schema/scalar.rb +1 -0
- data/lib/graphql/schema/subscription.rb +67 -28
- data/lib/graphql/schema/timeout.rb +65 -25
- data/lib/graphql/schema/type_expression.rb +14 -5
- data/lib/graphql/schema/type_membership.rb +29 -10
- data/lib/graphql/schema/union.rb +4 -2
- data/lib/graphql/schema/unique_within_type.rb +24 -5
- data/lib/graphql/schema/validator/all_validator.rb +17 -9
- data/lib/graphql/schema/validator/allow_blank_validator.rb +8 -2
- data/lib/graphql/schema/validator/allow_null_validator.rb +8 -2
- data/lib/graphql/schema/validator/exclusion_validator.rb +14 -5
- data/lib/graphql/schema/validator/format_validator.rb +21 -10
- data/lib/graphql/schema/validator/inclusion_validator.rb +15 -6
- data/lib/graphql/schema/validator/length_validator.rb +23 -12
- data/lib/graphql/schema/validator/numericality_validator.rb +29 -16
- data/lib/graphql/schema/validator/required_validator.rb +45 -31
- data/lib/graphql/schema/validator.rb +89 -25
- data/lib/graphql/schema/visibility/migration.rb +14 -7
- data/lib/graphql/schema/visibility/profile.rb +20 -17
- data/lib/graphql/schema/visibility/visit.rb +12 -10
- data/lib/graphql/schema/visibility.rb +24 -20
- data/lib/graphql/schema/warden.rb +117 -31
- data/lib/graphql/schema/wrapper.rb +4 -1
- data/lib/graphql/schema.rb +1046 -300
- data/lib/graphql/static_validation/all_rules.rb +2 -1
- data/lib/graphql/static_validation/base_visitor.rb +48 -8
- data/lib/graphql/static_validation/definition_dependencies.rb +27 -7
- data/lib/graphql/static_validation/error.rb +3 -0
- data/lib/graphql/static_validation/interpreter_visitor.rb +1 -0
- data/lib/graphql/static_validation/literal_validator.rb +1 -0
- data/lib/graphql/static_validation/rules/argument_literals_are_compatible.rb +4 -0
- data/lib/graphql/static_validation/rules/argument_literals_are_compatible_error.rb +1 -0
- data/lib/graphql/static_validation/rules/argument_names_are_unique.rb +3 -0
- data/lib/graphql/static_validation/rules/argument_names_are_unique_error.rb +1 -0
- data/lib/graphql/static_validation/rules/arguments_are_defined.rb +3 -0
- data/lib/graphql/static_validation/rules/arguments_are_defined_error.rb +1 -0
- data/lib/graphql/static_validation/rules/directives_are_defined.rb +3 -0
- data/lib/graphql/static_validation/rules/directives_are_defined_error.rb +1 -0
- data/lib/graphql/static_validation/rules/directives_are_in_valid_locations.rb +3 -0
- data/lib/graphql/static_validation/rules/directives_are_in_valid_locations_error.rb +1 -0
- data/lib/graphql/static_validation/rules/fields_are_defined_on_type.rb +3 -0
- data/lib/graphql/static_validation/rules/fields_are_defined_on_type_error.rb +1 -0
- data/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb +9 -1
- data/lib/graphql/static_validation/rules/fields_have_appropriate_selections_error.rb +1 -0
- data/lib/graphql/static_validation/rules/fields_will_merge.rb +295 -134
- data/lib/graphql/static_validation/rules/fields_will_merge_error.rb +14 -2
- data/lib/graphql/static_validation/rules/fragment_names_are_unique.rb +3 -0
- data/lib/graphql/static_validation/rules/fragment_names_are_unique_error.rb +1 -0
- data/lib/graphql/static_validation/rules/fragment_spreads_are_possible.rb +3 -0
- data/lib/graphql/static_validation/rules/fragment_spreads_are_possible_error.rb +1 -0
- data/lib/graphql/static_validation/rules/fragment_types_exist.rb +3 -0
- data/lib/graphql/static_validation/rules/fragment_types_exist_error.rb +1 -0
- data/lib/graphql/static_validation/rules/fragments_are_finite.rb +3 -0
- data/lib/graphql/static_validation/rules/fragments_are_finite_error.rb +1 -0
- data/lib/graphql/static_validation/rules/fragments_are_named.rb +3 -0
- data/lib/graphql/static_validation/rules/fragments_are_named_error.rb +1 -0
- data/lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb +3 -0
- data/lib/graphql/static_validation/rules/fragments_are_on_composite_types_error.rb +1 -0
- data/lib/graphql/static_validation/rules/fragments_are_used.rb +3 -0
- data/lib/graphql/static_validation/rules/fragments_are_used_error.rb +1 -0
- data/lib/graphql/static_validation/rules/input_object_names_are_unique.rb +3 -0
- data/lib/graphql/static_validation/rules/input_object_names_are_unique_error.rb +1 -0
- data/lib/graphql/static_validation/rules/mutation_root_exists.rb +3 -0
- data/lib/graphql/static_validation/rules/mutation_root_exists_error.rb +1 -0
- data/lib/graphql/static_validation/rules/no_definitions_are_present.rb +3 -0
- data/lib/graphql/static_validation/rules/no_definitions_are_present_error.rb +1 -0
- data/lib/graphql/static_validation/rules/not_single_subscription_error.rb +1 -0
- data/lib/graphql/static_validation/rules/one_of_input_objects_are_valid.rb +4 -0
- data/lib/graphql/static_validation/rules/one_of_input_objects_are_valid_error.rb +1 -0
- data/lib/graphql/static_validation/rules/operation_names_are_valid.rb +3 -0
- data/lib/graphql/static_validation/rules/operation_names_are_valid_error.rb +1 -0
- data/lib/graphql/static_validation/rules/query_root_exists.rb +3 -0
- data/lib/graphql/static_validation/rules/query_root_exists_error.rb +1 -0
- data/lib/graphql/static_validation/rules/required_arguments_are_present.rb +4 -1
- data/lib/graphql/static_validation/rules/required_arguments_are_present_error.rb +1 -0
- data/lib/graphql/static_validation/rules/required_input_object_attributes_are_present.rb +4 -0
- data/lib/graphql/static_validation/rules/required_input_object_attributes_are_present_error.rb +1 -0
- data/lib/graphql/static_validation/rules/subscription_root_exists_and_single_subscription_selection.rb +4 -1
- data/lib/graphql/static_validation/rules/subscription_root_exists_error.rb +1 -0
- data/lib/graphql/static_validation/rules/unique_directives_per_location.rb +3 -0
- data/lib/graphql/static_validation/rules/unique_directives_per_location_error.rb +1 -0
- data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed.rb +3 -0
- data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed_error.rb +1 -0
- data/lib/graphql/static_validation/rules/variable_names_are_unique.rb +3 -0
- data/lib/graphql/static_validation/rules/variable_names_are_unique_error.rb +1 -0
- data/lib/graphql/static_validation/rules/variable_usages_are_allowed.rb +207 -51
- data/lib/graphql/static_validation/rules/variable_usages_are_allowed_error.rb +1 -0
- data/lib/graphql/static_validation/rules/variables_are_input_types.rb +3 -0
- data/lib/graphql/static_validation/rules/variables_are_input_types_error.rb +1 -0
- data/lib/graphql/static_validation/rules/variables_are_used_and_defined.rb +6 -3
- data/lib/graphql/static_validation/rules/variables_are_used_and_defined_error.rb +1 -0
- data/lib/graphql/static_validation/validation_context.rb +3 -2
- data/lib/graphql/static_validation/validation_timeout_error.rb +1 -0
- data/lib/graphql/static_validation/validator.rb +41 -16
- data/lib/graphql/static_validation.rb +1 -0
- data/lib/graphql/string_encoding_error.rb +1 -0
- data/lib/graphql/subscriptions/action_cable_subscriptions.rb +85 -65
- data/lib/graphql/subscriptions/broadcast_analyzer.rb +10 -4
- data/lib/graphql/subscriptions/default_subscription_resolve_extension.rb +1 -0
- data/lib/graphql/subscriptions/event.rb +25 -6
- data/lib/graphql/subscriptions/serialize.rb +58 -19
- data/lib/graphql/subscriptions.rb +172 -46
- data/lib/graphql/testing/helpers.rb +17 -4
- data/lib/graphql/testing/mock_action_cable.rb +55 -33
- data/lib/graphql/testing.rb +1 -0
- data/lib/graphql/tracing/active_support_notifications_trace.rb +17 -9
- data/lib/graphql/tracing/active_support_notifications_tracing.rb +2 -1
- data/lib/graphql/tracing/appoptics_trace.rb +2 -1
- data/lib/graphql/tracing/appoptics_tracing.rb +2 -1
- data/lib/graphql/tracing/appsignal_trace.rb +16 -7
- data/lib/graphql/tracing/appsignal_tracing.rb +7 -3
- data/lib/graphql/tracing/call_legacy_tracers.rb +1 -0
- data/lib/graphql/tracing/data_dog_trace.rb +17 -6
- data/lib/graphql/tracing/data_dog_tracing.rb +10 -3
- data/lib/graphql/tracing/detailed_trace/active_record_backend.rb +1 -0
- data/lib/graphql/tracing/detailed_trace/memory_backend.rb +1 -0
- data/lib/graphql/tracing/detailed_trace/redis_backend.rb +1 -0
- data/lib/graphql/tracing/detailed_trace.rb +105 -42
- data/lib/graphql/tracing/legacy_hooks_trace.rb +5 -0
- data/lib/graphql/tracing/legacy_trace.rb +1 -0
- data/lib/graphql/tracing/monitor_trace.rb +17 -11
- data/lib/graphql/tracing/new_relic_trace.rb +17 -8
- data/lib/graphql/tracing/new_relic_tracing.rb +7 -3
- data/lib/graphql/tracing/notifications_trace.rb +11 -8
- data/lib/graphql/tracing/notifications_tracing.rb +23 -7
- data/lib/graphql/tracing/null_trace.rb +1 -0
- data/lib/graphql/tracing/perfetto_trace/trace_pb.rb +1 -0
- data/lib/graphql/tracing/perfetto_trace.rb +41 -19
- data/lib/graphql/tracing/platform_trace.rb +3 -1
- data/lib/graphql/tracing/platform_tracing.rb +16 -7
- data/lib/graphql/tracing/prometheus_trace/graphql_collector.rb +1 -0
- data/lib/graphql/tracing/prometheus_trace.rb +22 -13
- data/lib/graphql/tracing/prometheus_tracing.rb +1 -0
- data/lib/graphql/tracing/scout_trace.rb +10 -4
- data/lib/graphql/tracing/scout_tracing.rb +7 -3
- data/lib/graphql/tracing/sentry_trace.rb +12 -5
- data/lib/graphql/tracing/statsd_trace.rb +12 -6
- data/lib/graphql/tracing/statsd_tracing.rb +7 -1
- data/lib/graphql/tracing/trace.rb +231 -58
- data/lib/graphql/tracing.rb +25 -9
- data/lib/graphql/type_kinds.rb +2 -1
- data/lib/graphql/types/big_int.rb +1 -0
- data/lib/graphql/types/boolean.rb +1 -0
- data/lib/graphql/types/float.rb +1 -0
- data/lib/graphql/types/id.rb +1 -0
- data/lib/graphql/types/int.rb +2 -1
- data/lib/graphql/types/iso_8601_date.rb +21 -4
- data/lib/graphql/types/iso_8601_date_time.rb +33 -6
- data/lib/graphql/types/iso_8601_duration.rb +42 -9
- data/lib/graphql/types/json.rb +1 -0
- data/lib/graphql/types/relay/base_connection.rb +38 -32
- data/lib/graphql/types/relay/base_edge.rb +15 -9
- data/lib/graphql/types/relay/connection_behaviors.rb +19 -3
- data/lib/graphql/types/relay/edge_behaviors.rb +17 -4
- data/lib/graphql/types/relay/has_node_field.rb +6 -1
- data/lib/graphql/types/relay/has_nodes_field.rb +6 -1
- data/lib/graphql/types/relay/node.rb +1 -0
- data/lib/graphql/types/relay/node_behaviors.rb +5 -1
- data/lib/graphql/types/relay/page_info.rb +1 -0
- data/lib/graphql/types/relay/page_info_behaviors.rb +1 -0
- data/lib/graphql/types/relay.rb +4 -3
- data/lib/graphql/types/string.rb +1 -0
- data/lib/graphql/types.rb +1 -0
- data/lib/graphql/unauthorized_enum_value_error.rb +4 -1
- data/lib/graphql/unauthorized_error.rb +11 -4
- data/lib/graphql/unauthorized_field_error.rb +4 -1
- data/lib/graphql/unresolved_type_error.rb +16 -5
- data/lib/graphql/version.rb +2 -1
- data/lib/graphql.rb +37 -9
- data/readme.md +1 -1
- metadata +89 -5
- data/.yardopts +0 -5
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
+
# typed: true
|
|
2
3
|
require "securerandom"
|
|
3
4
|
require "graphql/subscriptions/broadcast_analyzer"
|
|
4
5
|
require "graphql/subscriptions/event"
|
|
@@ -21,7 +22,7 @@ module GraphQL
|
|
|
21
22
|
class SubscriptionScopeMissingError < GraphQL::Error
|
|
22
23
|
end
|
|
23
24
|
|
|
24
|
-
#
|
|
25
|
+
# See [GraphQL::Subscriptions](rdoc-ref:GraphQL::Subscriptions) for the base options; concrete implementations may add options.
|
|
25
26
|
def self.use(defn, options = {})
|
|
26
27
|
schema = defn.is_a?(Class) ? defn : defn.target
|
|
27
28
|
|
|
@@ -35,8 +36,13 @@ module GraphQL
|
|
|
35
36
|
nil
|
|
36
37
|
end
|
|
37
38
|
|
|
38
|
-
#
|
|
39
|
-
#
|
|
39
|
+
# **Parameters**
|
|
40
|
+
#
|
|
41
|
+
# - `schema` (`Class`) — the GraphQL schema this manager belongs to
|
|
42
|
+
# - `validate_update` (`Boolean`) — If false, then validation is skipped when executing updates
|
|
43
|
+
#
|
|
44
|
+
# :call-seq:
|
|
45
|
+
# initialize(Class schema:, bool validate_update:, broadcast:, default_broadcastable:, **rest)
|
|
40
46
|
def initialize(schema:, validate_update: true, broadcast: false, default_broadcastable: false, **rest)
|
|
41
47
|
if broadcast
|
|
42
48
|
schema.query_analyzer(Subscriptions::BroadcastAnalyzer)
|
|
@@ -46,17 +52,28 @@ module GraphQL
|
|
|
46
52
|
@validate_update = validate_update
|
|
47
53
|
end
|
|
48
54
|
|
|
49
|
-
#
|
|
55
|
+
# **Returns**
|
|
56
|
+
#
|
|
57
|
+
# - `Boolean` — Used when fields don't have `broadcastable:` explicitly set
|
|
50
58
|
attr_reader :default_broadcastable
|
|
51
59
|
|
|
52
60
|
# Fetch subscriptions matching this field + arguments pair
|
|
53
61
|
# And pass them off to the queue.
|
|
54
|
-
#
|
|
55
|
-
#
|
|
56
|
-
#
|
|
57
|
-
#
|
|
58
|
-
#
|
|
59
|
-
#
|
|
62
|
+
#
|
|
63
|
+
# **Parameters**
|
|
64
|
+
#
|
|
65
|
+
# - `event_name` (`String`)
|
|
66
|
+
# - `args` (`Hash<String, Symbol => Object>`) — Arguments passed to the subscription resolver
|
|
67
|
+
# - `object` (`Object`)
|
|
68
|
+
# - `scope` (`Symbol, String`)
|
|
69
|
+
# - `context` (`Hash`)
|
|
70
|
+
#
|
|
71
|
+
# **Returns**
|
|
72
|
+
#
|
|
73
|
+
# - `void`
|
|
74
|
+
#
|
|
75
|
+
# :call-seq:
|
|
76
|
+
# trigger(String event_name, Hash[String | Symbol, Object] args, Object object, Symbol | String scope:, Hash context:) -> void
|
|
60
77
|
def trigger(event_name, args, object, scope: nil, context: {})
|
|
61
78
|
# Make something as context-like as possible, even though there isn't a current query:
|
|
62
79
|
dummy_query = @schema.query_class.new(@schema, "{ __typename }", validate: false, context: context)
|
|
@@ -97,10 +114,18 @@ module GraphQL
|
|
|
97
114
|
#
|
|
98
115
|
# Load `subscription_id`'s GraphQL data, re-evaluate the query and return the result.
|
|
99
116
|
#
|
|
100
|
-
#
|
|
101
|
-
#
|
|
102
|
-
#
|
|
103
|
-
#
|
|
117
|
+
# **Parameters**
|
|
118
|
+
#
|
|
119
|
+
# - `subscription_id` (`String`)
|
|
120
|
+
# - `event` (`GraphQL::Subscriptions::Event`) — The event which was triggered
|
|
121
|
+
# - `object` (`Object`) — The value for the subscription field
|
|
122
|
+
#
|
|
123
|
+
# **Returns**
|
|
124
|
+
#
|
|
125
|
+
# - `GraphQL::Query::Result`
|
|
126
|
+
#
|
|
127
|
+
# :call-seq:
|
|
128
|
+
# execute_update(String subscription_id, GraphQL::Subscriptions::Event event, Object object) -> GraphQL::Query::Result
|
|
104
129
|
def execute_update(subscription_id, event, object)
|
|
105
130
|
# Lookup the saved data for this subscription
|
|
106
131
|
query_data = read_subscription(subscription_id)
|
|
@@ -146,15 +171,26 @@ module GraphQL
|
|
|
146
171
|
# Define this method to customize whether to validate
|
|
147
172
|
# this subscription when executing an update.
|
|
148
173
|
#
|
|
149
|
-
#
|
|
174
|
+
# **Returns**
|
|
175
|
+
#
|
|
176
|
+
# - `Boolean` — defaults to `true`, or false if `validate: false` is provided.
|
|
177
|
+
#
|
|
178
|
+
# :call-seq:
|
|
179
|
+
# validate_update?(query:, context:, root_value:, subscription_topic:, operation_name:, variables:) -> bool
|
|
150
180
|
def validate_update?(query:, context:, root_value:, subscription_topic:, operation_name:, variables:)
|
|
151
181
|
@validate_update
|
|
152
182
|
end
|
|
153
183
|
|
|
154
184
|
# Run the update query for this subscription and deliver it
|
|
155
|
-
#
|
|
156
|
-
#
|
|
157
|
-
#
|
|
185
|
+
# See [execute_update](rdoc-ref:#execute_update)
|
|
186
|
+
# See [deliver](rdoc-ref:#deliver)
|
|
187
|
+
#
|
|
188
|
+
# **Returns**
|
|
189
|
+
#
|
|
190
|
+
# - `void`
|
|
191
|
+
#
|
|
192
|
+
# :call-seq:
|
|
193
|
+
# execute(subscription_id, event, object) -> void
|
|
158
194
|
def execute(subscription_id, event, object)
|
|
159
195
|
res = execute_update(subscription_id, event, object)
|
|
160
196
|
if !res.nil?
|
|
@@ -171,48 +207,98 @@ module GraphQL
|
|
|
171
207
|
|
|
172
208
|
# Event `event` occurred on `object`,
|
|
173
209
|
# Update all subscribers.
|
|
174
|
-
#
|
|
175
|
-
#
|
|
176
|
-
#
|
|
210
|
+
#
|
|
211
|
+
# **Parameters**
|
|
212
|
+
#
|
|
213
|
+
# - `event` (`Subscriptions::Event`)
|
|
214
|
+
# - `object` (`Object`)
|
|
215
|
+
#
|
|
216
|
+
# **Returns**
|
|
217
|
+
#
|
|
218
|
+
# - `void`
|
|
219
|
+
#
|
|
220
|
+
# :call-seq:
|
|
221
|
+
# execute_all(Subscriptions::Event event, Object object) -> void
|
|
177
222
|
def execute_all(event, object)
|
|
178
223
|
raise GraphQL::RequiredImplementationMissingError
|
|
179
224
|
end
|
|
180
225
|
|
|
181
226
|
# The system wants to send an update to this subscription.
|
|
182
227
|
# Read its data and return it.
|
|
183
|
-
#
|
|
184
|
-
#
|
|
228
|
+
#
|
|
229
|
+
# **Parameters**
|
|
230
|
+
#
|
|
231
|
+
# - `subscription_id` (`String`)
|
|
232
|
+
#
|
|
233
|
+
# **Returns**
|
|
234
|
+
#
|
|
235
|
+
# - `Hash` — Containing required keys
|
|
236
|
+
#
|
|
237
|
+
# :call-seq:
|
|
238
|
+
# read_subscription(String subscription_id) -> Hash
|
|
185
239
|
def read_subscription(subscription_id)
|
|
186
240
|
raise GraphQL::RequiredImplementationMissingError
|
|
187
241
|
end
|
|
188
242
|
|
|
189
243
|
# A subscription query was re-evaluated, returning `result`.
|
|
190
244
|
# The result should be send to `subscription_id`.
|
|
191
|
-
#
|
|
192
|
-
#
|
|
193
|
-
#
|
|
245
|
+
#
|
|
246
|
+
# **Parameters**
|
|
247
|
+
#
|
|
248
|
+
# - `subscription_id` (`String`)
|
|
249
|
+
# - `result` (`Hash`)
|
|
250
|
+
#
|
|
251
|
+
# **Returns**
|
|
252
|
+
#
|
|
253
|
+
# - `void`
|
|
254
|
+
#
|
|
255
|
+
# :call-seq:
|
|
256
|
+
# deliver(String subscription_id, Hash result) -> void
|
|
194
257
|
def deliver(subscription_id, result)
|
|
195
258
|
raise GraphQL::RequiredImplementationMissingError
|
|
196
259
|
end
|
|
197
260
|
|
|
198
261
|
# `query` was executed and found subscriptions to `events`.
|
|
199
262
|
# Update the database to reflect this new state.
|
|
200
|
-
#
|
|
201
|
-
#
|
|
202
|
-
#
|
|
263
|
+
#
|
|
264
|
+
# **Parameters**
|
|
265
|
+
#
|
|
266
|
+
# - `query` (`GraphQL::Query`)
|
|
267
|
+
# - `events` (`Array<GraphQL::Subscriptions::Event>`)
|
|
268
|
+
#
|
|
269
|
+
# **Returns**
|
|
270
|
+
#
|
|
271
|
+
# - `void`
|
|
272
|
+
#
|
|
273
|
+
# :call-seq:
|
|
274
|
+
# write_subscription(GraphQL::Query query, Array[GraphQL::Subscriptions::Event] events) -> void
|
|
203
275
|
def write_subscription(query, events)
|
|
204
276
|
raise GraphQL::RequiredImplementationMissingError
|
|
205
277
|
end
|
|
206
278
|
|
|
207
279
|
# A subscription was terminated server-side.
|
|
208
280
|
# Clean up the database.
|
|
209
|
-
#
|
|
210
|
-
#
|
|
281
|
+
#
|
|
282
|
+
# **Parameters**
|
|
283
|
+
#
|
|
284
|
+
# - `subscription_id` (`String`)
|
|
285
|
+
#
|
|
286
|
+
# **Returns**
|
|
287
|
+
#
|
|
288
|
+
# - `Object` — void.
|
|
289
|
+
#
|
|
290
|
+
# :call-seq:
|
|
291
|
+
# delete_subscription(String subscription_id) -> Object
|
|
211
292
|
def delete_subscription(subscription_id)
|
|
212
293
|
raise GraphQL::RequiredImplementationMissingError
|
|
213
294
|
end
|
|
214
295
|
|
|
215
|
-
#
|
|
296
|
+
# **Returns**
|
|
297
|
+
#
|
|
298
|
+
# - `String` — A new unique identifier for a subscription
|
|
299
|
+
#
|
|
300
|
+
# :call-seq:
|
|
301
|
+
# build_id() -> String
|
|
216
302
|
def build_id
|
|
217
303
|
SecureRandom.uuid
|
|
218
304
|
end
|
|
@@ -223,13 +309,26 @@ module GraphQL
|
|
|
223
309
|
# By default, it converts the identifier to camelcase.
|
|
224
310
|
# Override this in a subclass to change the transformation.
|
|
225
311
|
#
|
|
226
|
-
#
|
|
227
|
-
#
|
|
312
|
+
# **Parameters**
|
|
313
|
+
#
|
|
314
|
+
# - `event_or_arg_name` (`String, Symbol`)
|
|
315
|
+
#
|
|
316
|
+
# **Returns**
|
|
317
|
+
#
|
|
318
|
+
# - `String`
|
|
319
|
+
#
|
|
320
|
+
# :call-seq:
|
|
321
|
+
# normalize_name(String | Symbol event_or_arg_name) -> String
|
|
228
322
|
def normalize_name(event_or_arg_name)
|
|
229
323
|
Schema::Member::BuildType.camelize(event_or_arg_name.to_s)
|
|
230
324
|
end
|
|
231
325
|
|
|
232
|
-
#
|
|
326
|
+
# **Returns**
|
|
327
|
+
#
|
|
328
|
+
# - `Boolean` — if true, then a query like this one would be broadcasted
|
|
329
|
+
#
|
|
330
|
+
# :call-seq:
|
|
331
|
+
# broadcastable?(query_str, **query_options) -> bool
|
|
233
332
|
def broadcastable?(query_str, **query_options)
|
|
234
333
|
query = @schema.query_class.new(@schema, query_str, **query_options)
|
|
235
334
|
if !query.valid?
|
|
@@ -240,8 +339,17 @@ module GraphQL
|
|
|
240
339
|
end
|
|
241
340
|
|
|
242
341
|
# Called during execution when a new `subscription ...` operation is received
|
|
243
|
-
#
|
|
244
|
-
#
|
|
342
|
+
#
|
|
343
|
+
# **Parameters**
|
|
344
|
+
#
|
|
345
|
+
# - `query` (`GraphQL::Query`)
|
|
346
|
+
#
|
|
347
|
+
# **Returns**
|
|
348
|
+
#
|
|
349
|
+
# - `void`
|
|
350
|
+
#
|
|
351
|
+
# :call-seq:
|
|
352
|
+
# initialize_subscriptions(GraphQL::Query query) -> void
|
|
245
353
|
def initialize_subscriptions(query)
|
|
246
354
|
subs_namespace = query.context.namespace(:subscriptions)
|
|
247
355
|
subs_namespace[:events] = []
|
|
@@ -250,8 +358,17 @@ module GraphQL
|
|
|
250
358
|
end
|
|
251
359
|
|
|
252
360
|
# Called during execution when a subscription operation has finished
|
|
253
|
-
#
|
|
254
|
-
#
|
|
361
|
+
#
|
|
362
|
+
# **Parameters**
|
|
363
|
+
#
|
|
364
|
+
# - `query` (`GraphQL::Query`)
|
|
365
|
+
#
|
|
366
|
+
# **Returns**
|
|
367
|
+
#
|
|
368
|
+
# - `void`
|
|
369
|
+
#
|
|
370
|
+
# :call-seq:
|
|
371
|
+
# finish_subscriptions(GraphQL::Query query) -> void
|
|
255
372
|
def finish_subscriptions(query)
|
|
256
373
|
if (events = query.context.namespace(:subscriptions)[:events]) && !events.empty?
|
|
257
374
|
write_subscription(query, events)
|
|
@@ -278,19 +395,30 @@ module GraphQL
|
|
|
278
395
|
|
|
279
396
|
# Recursively normalize `args` as belonging to `arg_owner`:
|
|
280
397
|
# - convert symbols to strings,
|
|
281
|
-
# - if needed, camelize the string (using
|
|
282
|
-
#
|
|
283
|
-
#
|
|
284
|
-
#
|
|
398
|
+
# - if needed, camelize the string (using [normalize name](rdoc-ref:#normalize_name))
|
|
399
|
+
#
|
|
400
|
+
# **Parameters**
|
|
401
|
+
#
|
|
402
|
+
# - `arg_owner` (`GraphQL::Field, GraphQL::BaseType`)
|
|
403
|
+
# - `args` (`Hash, Array, Any`) — some GraphQL input value to coerce as `arg_owner`
|
|
404
|
+
#
|
|
405
|
+
# **Returns**
|
|
406
|
+
#
|
|
407
|
+
# - `Any` — normalized arguments value
|
|
408
|
+
#
|
|
409
|
+
# :call-seq:
|
|
410
|
+
# normalize_arguments(event_name, GraphQL::Field | GraphQL::BaseType arg_owner, Hash | Array | Any args, context) -> Any
|
|
285
411
|
def normalize_arguments(event_name, arg_owner, args, context)
|
|
286
412
|
case arg_owner
|
|
287
413
|
when GraphQL::Schema::Field, Class
|
|
288
414
|
return args if args.nil?
|
|
289
415
|
|
|
416
|
+
arg_owner = arg_owner #: as GraphQL::Schema::Field | GraphQL::Schema::Member::type_definition
|
|
290
417
|
if arg_owner.is_a?(Class) && !arg_owner.kind.input_object?
|
|
291
418
|
# it's a type, but not an input object
|
|
292
419
|
return args
|
|
293
420
|
end
|
|
421
|
+
arg_owner = arg_owner #: as GraphQL::Schema::Field | singleton(GraphQL::Schema::InputObject)
|
|
294
422
|
normalized_args = {}
|
|
295
423
|
missing_arg_names = []
|
|
296
424
|
args.each do |k, v|
|
|
@@ -329,10 +457,8 @@ module GraphQL
|
|
|
329
457
|
if !missing_arg_names.empty?
|
|
330
458
|
arg_owner_name = if arg_owner.is_a?(GraphQL::Schema::Field)
|
|
331
459
|
arg_owner.path
|
|
332
|
-
elsif arg_owner.is_a?(Class)
|
|
333
|
-
arg_owner.graphql_name
|
|
334
460
|
else
|
|
335
|
-
arg_owner.
|
|
461
|
+
arg_owner.graphql_name
|
|
336
462
|
end
|
|
337
463
|
raise InvalidTriggerError, "Can't trigger Subscription.#{event_name}, received undefined arguments: #{missing_arg_names.join(", ")}. (Should match arguments of #{arg_owner_name}.)"
|
|
338
464
|
end
|
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
+
# typed: true
|
|
2
3
|
module GraphQL
|
|
3
4
|
module Testing
|
|
5
|
+
#--
|
|
6
|
+
# @requires_ancestor: Kernel
|
|
4
7
|
module Helpers
|
|
5
|
-
#
|
|
6
|
-
#
|
|
8
|
+
# **Parameters**
|
|
9
|
+
#
|
|
10
|
+
# - `schema_class` (`Class<GraphQL::Schema>`)
|
|
11
|
+
#
|
|
12
|
+
# **Returns**
|
|
13
|
+
#
|
|
14
|
+
# - `Module` — A helpers module which always uses the given schema
|
|
15
|
+
#
|
|
16
|
+
# :call-seq:
|
|
17
|
+
# for(Class[GraphQL::Schema] schema_class) -> Module
|
|
7
18
|
def self.for(schema_class)
|
|
8
19
|
SchemaHelpers.for(schema_class)
|
|
9
20
|
end
|
|
@@ -40,6 +51,8 @@ module GraphQL
|
|
|
40
51
|
end
|
|
41
52
|
|
|
42
53
|
def run_graphql_field(schema, field_path, object, arguments: {}, context: {}, ast_node: nil, lookahead: nil, visibility_profile: nil)
|
|
54
|
+
ast_node = ast_node #: GraphQL::Language::Nodes::Field?
|
|
55
|
+
lookahead = lookahead #: GraphQL::Execution::Lookahead?
|
|
43
56
|
type_name, *field_names = field_path.split(".")
|
|
44
57
|
dummy_query = GraphQL::Query.new(schema, "{ __typename }", context: context, visibility_profile: visibility_profile)
|
|
45
58
|
query_context = dummy_query.context
|
|
@@ -144,9 +157,9 @@ module GraphQL
|
|
|
144
157
|
super(@@schema_class_for_helpers, field_path, object, arguments: arguments, context: context, visibility_profile: visibility_profile)
|
|
145
158
|
end
|
|
146
159
|
|
|
147
|
-
def with_resolution_context(
|
|
160
|
+
def with_resolution_context(**kwargs, &block)
|
|
148
161
|
# schema will be added later
|
|
149
|
-
super(nil,
|
|
162
|
+
super(nil, **kwargs, &block)
|
|
150
163
|
end
|
|
151
164
|
|
|
152
165
|
def self.for(schema_class)
|
|
@@ -1,49 +1,62 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
+
# typed: true
|
|
2
3
|
module GraphQL
|
|
3
4
|
module Testing
|
|
4
5
|
# A stub implementation of ActionCable.
|
|
5
6
|
# Any methods to support the mock backend have `mock` in the name.
|
|
6
7
|
#
|
|
7
|
-
#
|
|
8
|
-
# class MySchema < GraphQL::Schema
|
|
9
|
-
# # Use MockActionCable in test:
|
|
10
|
-
# use GraphQL::Subscriptions::ActionCableSubscriptions,
|
|
11
|
-
# action_cable: Rails.env.test? ? GraphQL::Testing::MockActionCable : ActionCable
|
|
12
|
-
# end
|
|
8
|
+
# **Examples**
|
|
13
9
|
#
|
|
14
|
-
#
|
|
15
|
-
# setup do
|
|
16
|
-
# GraphQL::Testing::MockActionCable.clear_mocks
|
|
17
|
-
# end
|
|
10
|
+
# **Example: Configuring your schema to use MockActionCable in the test environment**
|
|
18
11
|
#
|
|
19
|
-
#
|
|
20
|
-
#
|
|
21
|
-
#
|
|
22
|
-
#
|
|
12
|
+
# ```ruby
|
|
13
|
+
# class MySchema < GraphQL::Schema
|
|
14
|
+
# # Use MockActionCable in test:
|
|
15
|
+
# use GraphQL::Subscriptions::ActionCableSubscriptions,
|
|
16
|
+
# action_cable: Rails.env.test? ? GraphQL::Testing::MockActionCable : ActionCable
|
|
17
|
+
# end
|
|
18
|
+
# ```
|
|
23
19
|
#
|
|
24
|
-
#
|
|
25
|
-
# ActionCableTestSchema.subscriptions.trigger(:news_flash, {}, {text: "After yesterday's rain, someone stopped on Rio Road to help a box turtle across five lanes of traffic"})
|
|
20
|
+
# **Example: Clearing old data before each test**
|
|
26
21
|
#
|
|
27
|
-
#
|
|
28
|
-
#
|
|
29
|
-
#
|
|
30
|
-
#
|
|
31
|
-
#
|
|
32
|
-
#
|
|
33
|
-
#
|
|
34
|
-
#
|
|
35
|
-
#
|
|
36
|
-
#
|
|
37
|
-
#
|
|
38
|
-
#
|
|
22
|
+
# ```ruby
|
|
23
|
+
# setup do
|
|
24
|
+
# GraphQL::Testing::MockActionCable.clear_mocks
|
|
25
|
+
# end
|
|
26
|
+
# ```
|
|
27
|
+
#
|
|
28
|
+
# **Example: Using MockActionCable in a test case**
|
|
29
|
+
#
|
|
30
|
+
# ```ruby
|
|
31
|
+
# # Create a channel to use in the test, pass it to GraphQL
|
|
32
|
+
# mock_channel = GraphQL::Testing::MockActionCable.get_mock_channel
|
|
33
|
+
# ActionCableTestSchema.execute("subscription { newsFlash { text } }", context: { channel: mock_channel })
|
|
39
34
|
#
|
|
35
|
+
# # Trigger a subscription update
|
|
36
|
+
# ActionCableTestSchema.subscriptions.trigger(:news_flash, {}, {text: "After yesterday's rain, someone stopped on Rio Road to help a box turtle across five lanes of traffic"})
|
|
37
|
+
#
|
|
38
|
+
# # Check messages on the channel
|
|
39
|
+
# expected_msg = {
|
|
40
|
+
# result: {
|
|
41
|
+
# "data" => {
|
|
42
|
+
# "newsFlash" => {
|
|
43
|
+
# "text" => "After yesterday's rain, someone stopped on Rio Road to help a box turtle across five lanes of traffic"
|
|
44
|
+
# }
|
|
45
|
+
# }
|
|
46
|
+
# },
|
|
47
|
+
# more: true,
|
|
48
|
+
# }
|
|
49
|
+
# assert_equal [expected_msg], mock_channel.mock_broadcasted_messages
|
|
50
|
+
# ```
|
|
40
51
|
class MockActionCable
|
|
41
52
|
class MockChannel
|
|
42
53
|
def initialize
|
|
43
54
|
@mock_broadcasted_messages = []
|
|
44
55
|
end
|
|
45
56
|
|
|
46
|
-
#
|
|
57
|
+
# **Returns**
|
|
58
|
+
#
|
|
59
|
+
# - `Array<Hash>` — Payloads "sent" to this channel by GraphQL-Ruby
|
|
47
60
|
attr_reader :mock_broadcasted_messages
|
|
48
61
|
|
|
49
62
|
# Called by ActionCableSubscriptions. Implements a Rails API.
|
|
@@ -55,8 +68,7 @@ module GraphQL
|
|
|
55
68
|
end
|
|
56
69
|
|
|
57
70
|
# Used by mock code
|
|
58
|
-
#
|
|
59
|
-
class MockStream
|
|
71
|
+
class MockStream # :nodoc:
|
|
60
72
|
def initialize
|
|
61
73
|
@mock_channels = {}
|
|
62
74
|
end
|
|
@@ -96,12 +108,22 @@ module GraphQL
|
|
|
96
108
|
|
|
97
109
|
# Use this as `context[:channel]` to simulate an ActionCable channel
|
|
98
110
|
#
|
|
99
|
-
#
|
|
111
|
+
# **Returns**
|
|
112
|
+
#
|
|
113
|
+
# - `GraphQL::Testing::MockActionCable::MockChannel`
|
|
114
|
+
#
|
|
115
|
+
# :call-seq:
|
|
116
|
+
# get_mock_channel() -> GraphQL::Testing::MockActionCable::MockChannel
|
|
100
117
|
def get_mock_channel
|
|
101
118
|
MockChannel.new
|
|
102
119
|
end
|
|
103
120
|
|
|
104
|
-
#
|
|
121
|
+
# **Returns**
|
|
122
|
+
#
|
|
123
|
+
# - `Array<String>` — Streams that currently have subscribers
|
|
124
|
+
#
|
|
125
|
+
# :call-seq:
|
|
126
|
+
# mock_stream_names() -> Array[String]
|
|
105
127
|
def mock_stream_names
|
|
106
128
|
@mock_streams.keys
|
|
107
129
|
end
|
data/lib/graphql/testing.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
+
# typed: ignore
|
|
2
3
|
|
|
3
4
|
require "graphql/tracing/notifications_trace"
|
|
4
5
|
|
|
@@ -6,17 +7,24 @@ module GraphQL
|
|
|
6
7
|
module Tracing
|
|
7
8
|
# This implementation forwards events to ActiveSupport::Notifications with a `graphql` suffix.
|
|
8
9
|
#
|
|
9
|
-
#
|
|
10
|
-
# class MySchema < GraphQL::Schema
|
|
11
|
-
# trace_with(GraphQL::Tracing::ActiveSupportNotificationsTrace)
|
|
12
|
-
# end
|
|
10
|
+
# **Examples**
|
|
13
11
|
#
|
|
14
|
-
#
|
|
15
|
-
# ActiveSupport::Notifications.subscribe(/graphql/) do |event|
|
|
16
|
-
# pp event.name
|
|
17
|
-
# pp event.payload
|
|
18
|
-
# end
|
|
12
|
+
# **Example: Sending execution events to ActiveSupport::Notifications**
|
|
19
13
|
#
|
|
14
|
+
# ```ruby
|
|
15
|
+
# class MySchema < GraphQL::Schema
|
|
16
|
+
# trace_with(GraphQL::Tracing::ActiveSupportNotificationsTrace)
|
|
17
|
+
# end
|
|
18
|
+
# ```
|
|
19
|
+
#
|
|
20
|
+
# **Example: Subscribing to GraphQL events with ActiveSupport::Notifications**
|
|
21
|
+
#
|
|
22
|
+
# ```ruby
|
|
23
|
+
# ActiveSupport::Notifications.subscribe(/graphql/) do |event|
|
|
24
|
+
# pp event.name
|
|
25
|
+
# pp event.payload
|
|
26
|
+
# end
|
|
27
|
+
# ```
|
|
20
28
|
module ActiveSupportNotificationsTrace
|
|
21
29
|
include NotificationsTrace
|
|
22
30
|
def initialize(engine: ActiveSupport::Notifications, **rest)
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
+
# typed: true
|
|
2
3
|
|
|
3
4
|
require "graphql/tracing/notifications_tracing"
|
|
4
5
|
|
|
@@ -7,7 +8,7 @@ module GraphQL
|
|
|
7
8
|
# This implementation forwards events to ActiveSupport::Notifications
|
|
8
9
|
# with a `graphql` suffix.
|
|
9
10
|
#
|
|
10
|
-
#
|
|
11
|
+
# See [KEYS](rdoc-ref:KEYS) for event names
|
|
11
12
|
module ActiveSupportNotificationsTracing
|
|
12
13
|
# A cache of frequently-used keys to avoid needless string allocations
|
|
13
14
|
KEYS = NotificationsTracing::KEYS
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
+
# typed: ignore
|
|
2
3
|
|
|
3
4
|
require "graphql/tracing/platform_trace"
|
|
4
5
|
|
|
@@ -10,7 +11,7 @@ module GraphQL
|
|
|
10
11
|
#
|
|
11
12
|
# There are 4 configurations available. They can be set in the
|
|
12
13
|
# appoptics_apm config file or in code. Please see:
|
|
13
|
-
#
|
|
14
|
+
# https://docs.appoptics.com/kb/apm_tracing/ruby/configure
|
|
14
15
|
#
|
|
15
16
|
# AppOpticsAPM::Config[:graphql][:enabled] = true|false
|
|
16
17
|
# AppOpticsAPM::Config[:graphql][:transaction_name] = true|false
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
+
# typed: ignore
|
|
2
3
|
|
|
3
4
|
require "graphql/tracing/platform_tracing"
|
|
4
5
|
|
|
@@ -10,7 +11,7 @@ module GraphQL
|
|
|
10
11
|
#
|
|
11
12
|
# There are 4 configurations available. They can be set in the
|
|
12
13
|
# appoptics_apm config file or in code. Please see:
|
|
13
|
-
#
|
|
14
|
+
# https://docs.appoptics.com/kb/apm_tracing/ruby/configure
|
|
14
15
|
#
|
|
15
16
|
# AppOpticsAPM::Config[:graphql][:enabled] = true|false
|
|
16
17
|
# AppOpticsAPM::Config[:graphql][:transaction_name] = true|false
|
|
@@ -1,19 +1,28 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
+
# typed: ignore
|
|
2
3
|
require "graphql/tracing/monitor_trace"
|
|
3
4
|
|
|
4
5
|
module GraphQL
|
|
5
6
|
module Tracing
|
|
6
7
|
# Instrumentation for reporting GraphQL-Ruby times to Appsignal.
|
|
7
8
|
#
|
|
8
|
-
#
|
|
9
|
-
#
|
|
10
|
-
#
|
|
11
|
-
#
|
|
9
|
+
# **Examples**
|
|
10
|
+
#
|
|
11
|
+
# **Example: Installing the tracer**
|
|
12
|
+
#
|
|
13
|
+
# ```ruby
|
|
14
|
+
# class MySchema < GraphQL::Schema
|
|
15
|
+
# trace_with GraphQL::Tracing::AppsignalTrace
|
|
16
|
+
# end
|
|
17
|
+
# ```
|
|
12
18
|
AppsignalTrace = MonitorTrace.create_module("appsignal")
|
|
13
19
|
module AppsignalTrace
|
|
14
|
-
#
|
|
15
|
-
#
|
|
16
|
-
#
|
|
20
|
+
# **Parameters**
|
|
21
|
+
#
|
|
22
|
+
# - `set_action_name` (`Boolean`) — If true, the GraphQL operation name will be used as the transaction name. This is not advised if you run more than one query per HTTP request, for example, with `graphql-client` or multiplexing. It can also be specified per-query with `context[:set_appsignal_action_name]`.
|
|
23
|
+
#
|
|
24
|
+
# :call-seq:
|
|
25
|
+
# initialize(bool set_action_name:, **rest)
|
|
17
26
|
def initialize(set_action_name: false, **rest)
|
|
18
27
|
rest[:set_transaction_name] ||= set_action_name
|
|
19
28
|
setup_appsignal_monitor(**rest)
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
+
# typed: true
|
|
2
3
|
|
|
3
4
|
require "graphql/tracing/platform_tracing"
|
|
4
5
|
|
|
@@ -16,9 +17,12 @@ module GraphQL
|
|
|
16
17
|
"execute_query_lazy" => "execute.graphql",
|
|
17
18
|
}
|
|
18
19
|
|
|
19
|
-
#
|
|
20
|
-
#
|
|
21
|
-
#
|
|
20
|
+
# **Parameters**
|
|
21
|
+
#
|
|
22
|
+
# - `set_action_name` (`Boolean`) — If true, the GraphQL operation name will be used as the transaction name. This is not advised if you run more than one query per HTTP request, for example, with `graphql-client` or multiplexing. It can also be specified per-query with `context[:set_appsignal_action_name]`.
|
|
23
|
+
#
|
|
24
|
+
# :call-seq:
|
|
25
|
+
# initialize(options)
|
|
22
26
|
def initialize(options = {})
|
|
23
27
|
@set_action_name = options.fetch(:set_action_name, false)
|
|
24
28
|
super
|