graphql 2.0.32 → 2.5.22
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/detailed_trace_generator.rb +77 -0
- data/lib/generators/graphql/install/mutation_root_generator.rb +2 -2
- data/lib/generators/graphql/install/templates/base_mutation.erb +2 -0
- data/lib/generators/graphql/install/templates/mutation_type.erb +2 -0
- data/lib/generators/graphql/install_generator.rb +49 -0
- data/lib/generators/graphql/orm_mutations_base.rb +1 -1
- data/lib/generators/graphql/templates/base_argument.erb +2 -0
- data/lib/generators/graphql/templates/base_connection.erb +2 -0
- data/lib/generators/graphql/templates/base_edge.erb +2 -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_resolver.erb +8 -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/create_graphql_detailed_traces.erb +10 -0
- data/lib/generators/graphql/templates/graphql_controller.erb +2 -0
- data/lib/generators/graphql/templates/loader.erb +2 -0
- data/lib/generators/graphql/templates/mutation.erb +2 -0
- data/lib/generators/graphql/templates/node_type.erb +2 -0
- data/lib/generators/graphql/templates/query_type.erb +2 -0
- data/lib/generators/graphql/templates/schema.erb +5 -0
- data/lib/generators/graphql/type_generator.rb +1 -1
- data/lib/graphql/analysis/analyzer.rb +90 -0
- data/lib/graphql/analysis/field_usage.rb +82 -0
- data/lib/graphql/analysis/max_query_complexity.rb +20 -0
- data/lib/graphql/analysis/max_query_depth.rb +20 -0
- data/lib/graphql/analysis/query_complexity.rb +263 -0
- data/lib/graphql/analysis/query_depth.rb +58 -0
- data/lib/graphql/analysis/visitor.rb +280 -0
- data/lib/graphql/analysis.rb +95 -1
- data/lib/graphql/autoload.rb +38 -0
- data/lib/graphql/backtrace/table.rb +118 -55
- data/lib/graphql/backtrace.rb +1 -19
- data/lib/graphql/coercion_error.rb +1 -9
- data/lib/graphql/current.rb +57 -0
- data/lib/graphql/dashboard/application_controller.rb +41 -0
- data/lib/graphql/dashboard/detailed_traces.rb +47 -0
- data/lib/graphql/dashboard/installable.rb +22 -0
- data/lib/graphql/dashboard/landings_controller.rb +9 -0
- data/lib/graphql/dashboard/limiters.rb +93 -0
- data/lib/graphql/dashboard/operation_store.rb +199 -0
- data/lib/graphql/dashboard/statics/bootstrap-5.3.3.min.css +6 -0
- data/lib/graphql/dashboard/statics/bootstrap-5.3.3.min.js +7 -0
- data/lib/graphql/dashboard/statics/charts.min.css +1 -0
- data/lib/graphql/dashboard/statics/dashboard.css +30 -0
- data/lib/graphql/dashboard/statics/dashboard.js +143 -0
- data/lib/graphql/dashboard/statics/header-icon.png +0 -0
- data/lib/graphql/dashboard/statics/icon.png +0 -0
- data/lib/graphql/dashboard/statics_controller.rb +31 -0
- data/lib/graphql/dashboard/subscriptions.rb +97 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/detailed_traces/traces/index.html.erb +45 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/landings/show.html.erb +18 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/limiters/limiters/show.html.erb +62 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/not_installed.html.erb +18 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/operation_store/clients/_form.html.erb +24 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/operation_store/clients/edit.html.erb +21 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/operation_store/clients/index.html.erb +69 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/operation_store/clients/new.html.erb +7 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/operation_store/index_entries/index.html.erb +39 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/operation_store/index_entries/show.html.erb +32 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/operation_store/operations/index.html.erb +81 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/operation_store/operations/show.html.erb +71 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/subscriptions/subscriptions/show.html.erb +41 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/subscriptions/topics/index.html.erb +55 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/subscriptions/topics/show.html.erb +40 -0
- data/lib/graphql/dashboard/views/layouts/graphql/dashboard/application.html.erb +108 -0
- data/lib/graphql/dashboard.rb +96 -0
- data/lib/graphql/dataloader/active_record_association_source.rb +84 -0
- data/lib/graphql/dataloader/active_record_source.rb +47 -0
- data/lib/graphql/dataloader/async_dataloader.rb +112 -0
- data/lib/graphql/dataloader/null_dataloader.rb +55 -10
- data/lib/graphql/dataloader/request.rb +5 -0
- data/lib/graphql/dataloader/source.rb +35 -12
- data/lib/graphql/dataloader.rb +224 -149
- data/lib/graphql/date_encoding_error.rb +1 -1
- data/lib/graphql/dig.rb +2 -1
- data/lib/graphql/duration_encoding_error.rb +16 -0
- data/lib/graphql/execution/interpreter/argument_value.rb +5 -1
- data/lib/graphql/execution/interpreter/arguments_cache.rb +5 -10
- data/lib/graphql/execution/interpreter/resolve.rb +23 -25
- data/lib/graphql/execution/interpreter/runtime/graphql_result.rb +228 -0
- data/lib/graphql/execution/interpreter/runtime.rb +363 -434
- data/lib/graphql/execution/interpreter.rb +91 -164
- data/lib/graphql/execution/lookahead.rb +105 -31
- data/lib/graphql/execution/multiplex.rb +7 -6
- data/lib/graphql/execution/next/field_resolve_step.rb +711 -0
- data/lib/graphql/execution/next/load_argument_step.rb +60 -0
- data/lib/graphql/execution/next/prepare_object_step.rb +129 -0
- data/lib/graphql/execution/next/runner.rb +389 -0
- data/lib/graphql/execution/next/selections_step.rb +37 -0
- data/lib/graphql/execution/next.rb +70 -0
- data/lib/graphql/execution.rb +1 -0
- data/lib/graphql/execution_error.rb +13 -10
- data/lib/graphql/introspection/directive_location_enum.rb +1 -1
- data/lib/graphql/introspection/directive_type.rb +7 -3
- data/lib/graphql/introspection/dynamic_fields.rb +5 -1
- data/lib/graphql/introspection/entry_points.rb +20 -6
- data/lib/graphql/introspection/enum_value_type.rb +5 -5
- data/lib/graphql/introspection/field_type.rb +13 -5
- data/lib/graphql/introspection/input_value_type.rb +21 -13
- data/lib/graphql/introspection/schema_type.rb +8 -11
- data/lib/graphql/introspection/type_type.rb +64 -28
- data/lib/graphql/invalid_name_error.rb +1 -1
- data/lib/graphql/invalid_null_error.rb +26 -17
- data/lib/graphql/language/block_string.rb +34 -18
- data/lib/graphql/language/cache.rb +13 -0
- data/lib/graphql/language/comment.rb +18 -0
- data/lib/graphql/language/definition_slice.rb +1 -1
- data/lib/graphql/language/document_from_schema_definition.rb +90 -61
- data/lib/graphql/language/lexer.rb +319 -193
- data/lib/graphql/language/nodes.rb +136 -77
- data/lib/graphql/language/parser.rb +807 -1985
- data/lib/graphql/language/printer.rb +324 -151
- data/lib/graphql/language/sanitized_printer.rb +21 -23
- data/lib/graphql/language/static_visitor.rb +171 -0
- data/lib/graphql/language/visitor.rb +23 -83
- data/lib/graphql/language.rb +71 -1
- data/lib/graphql/load_application_object_failed_error.rb +5 -1
- data/lib/graphql/pagination/array_connection.rb +6 -6
- data/lib/graphql/pagination/connection.rb +30 -1
- data/lib/graphql/pagination/connections.rb +32 -0
- data/lib/graphql/pagination/mongoid_relation_connection.rb +1 -2
- data/lib/graphql/query/context/scoped_context.rb +101 -0
- data/lib/graphql/query/context.rb +82 -144
- data/lib/graphql/query/null_context.rb +15 -18
- data/lib/graphql/query/partial.rb +179 -0
- data/lib/graphql/query/validation_pipeline.rb +4 -4
- data/lib/graphql/query/variable_validation_error.rb +1 -1
- data/lib/graphql/query/variables.rb +3 -3
- data/lib/graphql/query.rb +126 -81
- data/lib/graphql/railtie.rb +16 -6
- data/lib/graphql/rake_task.rb +3 -12
- data/lib/graphql/rubocop/graphql/base_cop.rb +1 -1
- data/lib/graphql/rubocop/graphql/field_type_in_block.rb +144 -0
- data/lib/graphql/rubocop/graphql/root_types_in_block.rb +38 -0
- data/lib/graphql/rubocop.rb +2 -0
- data/lib/graphql/schema/addition.rb +26 -13
- data/lib/graphql/schema/always_visible.rb +7 -2
- data/lib/graphql/schema/argument.rb +75 -9
- data/lib/graphql/schema/base_64_encoder.rb +3 -5
- data/lib/graphql/schema/build_from_definition.rb +123 -60
- data/lib/graphql/schema/directive/flagged.rb +4 -2
- data/lib/graphql/schema/directive/one_of.rb +12 -0
- data/lib/graphql/schema/directive/specified_by.rb +14 -0
- data/lib/graphql/schema/directive.rb +54 -2
- data/lib/graphql/schema/enum.rb +110 -27
- data/lib/graphql/schema/enum_value.rb +10 -2
- data/lib/graphql/schema/field/connection_extension.rb +15 -49
- data/lib/graphql/schema/field/scope_extension.rb +23 -7
- data/lib/graphql/schema/field.rb +245 -118
- data/lib/graphql/schema/field_extension.rb +34 -1
- data/lib/graphql/schema/has_single_input_argument.rb +160 -0
- data/lib/graphql/schema/input_object.rb +116 -60
- data/lib/graphql/schema/interface.rb +34 -16
- data/lib/graphql/schema/introspection_system.rb +8 -17
- data/lib/graphql/schema/late_bound_type.rb +4 -0
- data/lib/graphql/schema/list.rb +3 -3
- data/lib/graphql/schema/loader.rb +3 -4
- data/lib/graphql/schema/member/base_dsl_methods.rb +18 -2
- data/lib/graphql/schema/member/has_arguments.rb +132 -100
- data/lib/graphql/schema/member/has_authorization.rb +35 -0
- data/lib/graphql/schema/member/has_dataloader.rb +99 -0
- data/lib/graphql/schema/member/has_deprecation_reason.rb +15 -0
- data/lib/graphql/schema/member/has_directives.rb +4 -4
- data/lib/graphql/schema/member/has_fields.rb +115 -15
- data/lib/graphql/schema/member/has_interfaces.rb +26 -12
- data/lib/graphql/schema/member/has_unresolved_type_error.rb +5 -1
- data/lib/graphql/schema/member/has_validators.rb +1 -1
- data/lib/graphql/schema/member/relay_shortcuts.rb +1 -1
- data/lib/graphql/schema/member/scoped.rb +19 -0
- data/lib/graphql/schema/member/type_system_helpers.rb +17 -4
- data/lib/graphql/schema/member/validates_input.rb +3 -3
- data/lib/graphql/schema/member.rb +6 -0
- data/lib/graphql/schema/mutation.rb +7 -0
- data/lib/graphql/schema/object.rb +34 -8
- data/lib/graphql/schema/printer.rb +9 -7
- data/lib/graphql/schema/ractor_shareable.rb +79 -0
- data/lib/graphql/schema/relay_classic_mutation.rb +6 -129
- data/lib/graphql/schema/resolver.rb +90 -32
- data/lib/graphql/schema/scalar.rb +4 -9
- data/lib/graphql/schema/subscription.rb +63 -10
- data/lib/graphql/schema/timeout.rb +19 -2
- data/lib/graphql/schema/type_expression.rb +2 -2
- data/lib/graphql/schema/union.rb +2 -2
- data/lib/graphql/schema/unique_within_type.rb +1 -1
- data/lib/graphql/schema/validator/all_validator.rb +62 -0
- data/lib/graphql/schema/validator/required_validator.rb +92 -11
- data/lib/graphql/schema/validator.rb +3 -1
- data/lib/graphql/schema/visibility/migration.rb +188 -0
- data/lib/graphql/schema/visibility/profile.rb +445 -0
- data/lib/graphql/schema/visibility/visit.rb +190 -0
- data/lib/graphql/schema/visibility.rb +311 -0
- data/lib/graphql/schema/warden.rb +275 -103
- data/lib/graphql/schema.rb +950 -210
- data/lib/graphql/static_validation/all_rules.rb +3 -3
- data/lib/graphql/static_validation/base_visitor.rb +7 -6
- data/lib/graphql/static_validation/literal_validator.rb +6 -7
- data/lib/graphql/static_validation/rules/argument_literals_are_compatible.rb +1 -1
- data/lib/graphql/static_validation/rules/argument_names_are_unique.rb +1 -1
- data/lib/graphql/static_validation/rules/arguments_are_defined.rb +3 -2
- data/lib/graphql/static_validation/rules/directives_are_defined.rb +3 -3
- data/lib/graphql/static_validation/rules/directives_are_in_valid_locations.rb +2 -0
- data/lib/graphql/static_validation/rules/fields_are_defined_on_type.rb +12 -2
- data/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb +47 -13
- data/lib/graphql/static_validation/rules/fields_will_merge.rb +88 -25
- data/lib/graphql/static_validation/rules/fields_will_merge_error.rb +10 -2
- data/lib/graphql/static_validation/rules/fragment_spreads_are_possible.rb +3 -3
- data/lib/graphql/static_validation/rules/fragment_types_exist.rb +12 -2
- data/lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb +1 -1
- data/lib/graphql/static_validation/rules/mutation_root_exists.rb +1 -1
- data/lib/graphql/static_validation/rules/no_definitions_are_present.rb +1 -1
- data/lib/graphql/static_validation/rules/not_single_subscription_error.rb +25 -0
- data/lib/graphql/static_validation/rules/query_root_exists.rb +1 -1
- data/lib/graphql/static_validation/rules/required_arguments_are_present.rb +5 -5
- data/lib/graphql/static_validation/rules/required_input_object_attributes_are_present.rb +5 -5
- data/lib/graphql/static_validation/rules/subscription_root_exists_and_single_subscription_selection.rb +26 -0
- data/lib/graphql/static_validation/rules/unique_directives_per_location.rb +7 -3
- data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed.rb +18 -27
- data/lib/graphql/static_validation/rules/variable_names_are_unique.rb +1 -1
- data/lib/graphql/static_validation/rules/variable_usages_are_allowed.rb +2 -2
- data/lib/graphql/static_validation/rules/variables_are_input_types.rb +11 -2
- data/lib/graphql/static_validation/validation_context.rb +21 -5
- data/lib/graphql/static_validation/validator.rb +9 -1
- data/lib/graphql/static_validation.rb +0 -1
- data/lib/graphql/subscriptions/action_cable_subscriptions.rb +8 -5
- data/lib/graphql/subscriptions/broadcast_analyzer.rb +11 -5
- data/lib/graphql/subscriptions/default_subscription_resolve_extension.rb +12 -10
- data/lib/graphql/subscriptions/event.rb +21 -4
- data/lib/graphql/subscriptions/serialize.rb +3 -1
- data/lib/graphql/subscriptions.rb +21 -17
- data/lib/graphql/testing/helpers.rb +161 -0
- data/lib/graphql/testing/mock_action_cable.rb +111 -0
- data/lib/graphql/testing.rb +3 -0
- data/lib/graphql/tracing/active_support_notifications_trace.rb +14 -3
- data/lib/graphql/tracing/active_support_notifications_tracing.rb +1 -1
- data/lib/graphql/tracing/appoptics_trace.rb +7 -3
- data/lib/graphql/tracing/appoptics_tracing.rb +9 -2
- data/lib/graphql/tracing/appsignal_trace.rb +32 -59
- data/lib/graphql/tracing/appsignal_tracing.rb +2 -0
- data/lib/graphql/tracing/call_legacy_tracers.rb +66 -0
- data/lib/graphql/tracing/data_dog_trace.rb +46 -162
- data/lib/graphql/tracing/data_dog_tracing.rb +2 -0
- data/lib/graphql/tracing/detailed_trace/active_record_backend.rb +74 -0
- data/lib/graphql/tracing/detailed_trace/memory_backend.rb +60 -0
- data/lib/graphql/tracing/detailed_trace/redis_backend.rb +72 -0
- data/lib/graphql/tracing/detailed_trace.rb +156 -0
- data/lib/graphql/tracing/legacy_hooks_trace.rb +75 -0
- data/lib/graphql/tracing/legacy_trace.rb +4 -61
- data/lib/graphql/tracing/monitor_trace.rb +283 -0
- data/lib/graphql/tracing/new_relic_trace.rb +47 -54
- data/lib/graphql/tracing/new_relic_tracing.rb +2 -0
- data/lib/graphql/tracing/notifications_trace.rb +183 -37
- data/lib/graphql/tracing/notifications_tracing.rb +2 -0
- data/lib/graphql/tracing/null_trace.rb +9 -0
- data/lib/graphql/tracing/perfetto_trace/trace.proto +141 -0
- data/lib/graphql/tracing/perfetto_trace/trace_pb.rb +33 -0
- data/lib/graphql/tracing/perfetto_trace.rb +864 -0
- data/lib/graphql/tracing/platform_tracing.rb +3 -1
- data/lib/graphql/tracing/{prometheus_tracing → prometheus_trace}/graphql_collector.rb +5 -1
- data/lib/graphql/tracing/prometheus_trace.rb +73 -73
- data/lib/graphql/tracing/prometheus_tracing.rb +2 -0
- data/lib/graphql/tracing/scout_trace.rb +32 -58
- data/lib/graphql/tracing/scout_tracing.rb +2 -0
- data/lib/graphql/tracing/sentry_trace.rb +82 -0
- data/lib/graphql/tracing/statsd_trace.rb +33 -45
- data/lib/graphql/tracing/statsd_tracing.rb +2 -0
- data/lib/graphql/tracing/trace.rb +112 -1
- data/lib/graphql/tracing.rb +31 -28
- data/lib/graphql/type_kinds.rb +2 -1
- data/lib/graphql/types/iso_8601_duration.rb +77 -0
- data/lib/graphql/types/relay/connection_behaviors.rb +44 -2
- data/lib/graphql/types/relay/edge_behaviors.rb +18 -0
- data/lib/graphql/types/relay/has_node_field.rb +13 -8
- data/lib/graphql/types/relay/has_nodes_field.rb +13 -8
- data/lib/graphql/types/relay/node_behaviors.rb +13 -2
- data/lib/graphql/types/relay/page_info_behaviors.rb +4 -0
- data/lib/graphql/types.rb +18 -10
- data/lib/graphql/unauthorized_enum_value_error.rb +13 -0
- data/lib/graphql/unauthorized_error.rb +5 -1
- data/lib/graphql/version.rb +1 -1
- data/lib/graphql.rb +71 -54
- data/readme.md +12 -2
- metadata +233 -37
- data/lib/graphql/analysis/ast/analyzer.rb +0 -84
- data/lib/graphql/analysis/ast/field_usage.rb +0 -57
- data/lib/graphql/analysis/ast/max_query_complexity.rb +0 -22
- data/lib/graphql/analysis/ast/max_query_depth.rb +0 -22
- data/lib/graphql/analysis/ast/query_complexity.rb +0 -230
- data/lib/graphql/analysis/ast/query_depth.rb +0 -55
- data/lib/graphql/analysis/ast/visitor.rb +0 -276
- data/lib/graphql/analysis/ast.rb +0 -81
- data/lib/graphql/backtrace/inspect_result.rb +0 -50
- data/lib/graphql/backtrace/trace.rb +0 -96
- data/lib/graphql/backtrace/tracer.rb +0 -80
- data/lib/graphql/deprecation.rb +0 -9
- data/lib/graphql/filter.rb +0 -59
- data/lib/graphql/language/parser.y +0 -560
- data/lib/graphql/language/token.rb +0 -34
- data/lib/graphql/schema/base_64_bp.rb +0 -26
- data/lib/graphql/schema/invalid_type_error.rb +0 -7
- data/lib/graphql/schema/null_mask.rb +0 -11
- data/lib/graphql/static_validation/rules/subscription_root_exists.rb +0 -17
- data/lib/graphql/static_validation/type_stack.rb +0 -216
- data/lib/graphql/subscriptions/instrumentation.rb +0 -28
data/lib/graphql/schema/enum.rb
CHANGED
|
@@ -14,7 +14,7 @@ module GraphQL
|
|
|
14
14
|
# # ONIONS
|
|
15
15
|
# # PEPPERS
|
|
16
16
|
# # }
|
|
17
|
-
# class PizzaTopping < GraphQL::Enum
|
|
17
|
+
# class PizzaTopping < GraphQL::Schema::Enum
|
|
18
18
|
# value :MUSHROOMS
|
|
19
19
|
# value :ONIONS
|
|
20
20
|
# value :PEPPERS
|
|
@@ -22,9 +22,21 @@ module GraphQL
|
|
|
22
22
|
class Enum < GraphQL::Schema::Member
|
|
23
23
|
extend GraphQL::Schema::Member::ValidatesInput
|
|
24
24
|
|
|
25
|
+
# This is raised when either:
|
|
26
|
+
#
|
|
27
|
+
# - A resolver returns a value which doesn't match any of the enum's configured values;
|
|
28
|
+
# - Or, the resolver returns a value which matches a value, but that value's `authorized?` check returns false.
|
|
29
|
+
#
|
|
30
|
+
# In either case, the field should be modified so that the invalid value isn't returned.
|
|
31
|
+
#
|
|
32
|
+
# {GraphQL::Schema::Enum} subclasses get their own subclass of this error, so that bug trackers can better show where they came from.
|
|
25
33
|
class UnresolvedValueError < GraphQL::Error
|
|
26
|
-
def initialize(value:, enum:, context:)
|
|
27
|
-
fix_message =
|
|
34
|
+
def initialize(value:, enum:, context:, authorized:)
|
|
35
|
+
fix_message = if authorized == false
|
|
36
|
+
", but this value was unauthorized. Update the field or resolver to return a different value in this case (or return `nil`)."
|
|
37
|
+
else
|
|
38
|
+
", but this isn't a valid value for `#{enum.graphql_name}`. Update the field or resolver to return one of `#{enum.graphql_name}`'s values instead."
|
|
39
|
+
end
|
|
28
40
|
message = if (cp = context[:current_path]) && (cf = context[:current_field])
|
|
29
41
|
"`#{cf.path}` returned `#{value.inspect}` at `#{cp.join(".")}`#{fix_message}"
|
|
30
42
|
else
|
|
@@ -34,6 +46,8 @@ module GraphQL
|
|
|
34
46
|
end
|
|
35
47
|
end
|
|
36
48
|
|
|
49
|
+
# Raised when a {GraphQL::Schema::Enum} is defined to have no values.
|
|
50
|
+
# This can also happen when all values return false for `.visible?`.
|
|
37
51
|
class MissingValuesError < GraphQL::Error
|
|
38
52
|
def initialize(enum_type)
|
|
39
53
|
@enum_type = enum_type
|
|
@@ -43,15 +57,23 @@ module GraphQL
|
|
|
43
57
|
|
|
44
58
|
class << self
|
|
45
59
|
# Define a value for this enum
|
|
46
|
-
# @
|
|
47
|
-
# @
|
|
48
|
-
# @
|
|
49
|
-
# @
|
|
60
|
+
# @option kwargs [String, Symbol] :graphql_name the GraphQL value for this, usually `SCREAMING_CASE`
|
|
61
|
+
# @option kwargs [String] :description, the GraphQL description for this value, present in documentation
|
|
62
|
+
# @option kwargs [String] :comment, the GraphQL comment for this value, present in documentation
|
|
63
|
+
# @option kwargs [::Object] :value the translated Ruby value for this object (defaults to `graphql_name`)
|
|
64
|
+
# @option kwargs [::Object] :value_method, the method name to fetch `graphql_name` (defaults to `graphql_name.downcase`)
|
|
65
|
+
# @option kwargs [String] :deprecation_reason if this object is deprecated, include a message here
|
|
66
|
+
# @param value_method [Symbol, false] A method to generate for this value, or `false` to skip generation
|
|
50
67
|
# @return [void]
|
|
51
68
|
# @see {Schema::EnumValue} which handles these inputs by default
|
|
52
|
-
def value(*args, **kwargs, &block)
|
|
69
|
+
def value(*args, value_method: nil, **kwargs, &block)
|
|
53
70
|
kwargs[:owner] = self
|
|
54
71
|
value = enum_value_class.new(*args, **kwargs, &block)
|
|
72
|
+
|
|
73
|
+
if value_method || (value_methods && value_method != false)
|
|
74
|
+
generate_value_method(value, value_method)
|
|
75
|
+
end
|
|
76
|
+
|
|
55
77
|
key = value.graphql_name
|
|
56
78
|
prev_value = own_values[key]
|
|
57
79
|
case prev_value
|
|
@@ -68,13 +90,27 @@ module GraphQL
|
|
|
68
90
|
end
|
|
69
91
|
|
|
70
92
|
# @return [Array<GraphQL::Schema::EnumValue>] Possible values of this enum
|
|
71
|
-
def enum_values(context = GraphQL::Query::NullContext)
|
|
93
|
+
def enum_values(context = GraphQL::Query::NullContext.instance)
|
|
72
94
|
inherited_values = superclass.respond_to?(:enum_values) ? superclass.enum_values(context) : nil
|
|
73
95
|
visible_values = []
|
|
74
|
-
|
|
96
|
+
types = Warden.types_from_context(context)
|
|
75
97
|
own_values.each do |key, values_entry|
|
|
76
|
-
|
|
77
|
-
|
|
98
|
+
visible_value = nil
|
|
99
|
+
if values_entry.is_a?(Array)
|
|
100
|
+
values_entry.each do |v|
|
|
101
|
+
if types.visible_enum_value?(v, context)
|
|
102
|
+
if visible_value.nil?
|
|
103
|
+
visible_value = v
|
|
104
|
+
visible_values << v
|
|
105
|
+
else
|
|
106
|
+
raise DuplicateNamesError.new(
|
|
107
|
+
duplicated_name: v.path, duplicated_definition_1: visible_value.inspect, duplicated_definition_2: v.inspect
|
|
108
|
+
)
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
elsif types.visible_enum_value?(values_entry, context)
|
|
113
|
+
visible_values << values_entry
|
|
78
114
|
end
|
|
79
115
|
end
|
|
80
116
|
|
|
@@ -110,7 +146,7 @@ module GraphQL
|
|
|
110
146
|
end
|
|
111
147
|
|
|
112
148
|
# @return [Hash<String => GraphQL::Schema::EnumValue>] Possible values of this enum, keyed by name.
|
|
113
|
-
def values(context = GraphQL::Query::NullContext)
|
|
149
|
+
def values(context = GraphQL::Query::NullContext.instance)
|
|
114
150
|
enum_values(context).each_with_object({}) { |val, obj| obj[val.graphql_name] = val }
|
|
115
151
|
end
|
|
116
152
|
|
|
@@ -125,12 +161,24 @@ module GraphQL
|
|
|
125
161
|
end
|
|
126
162
|
end
|
|
127
163
|
|
|
164
|
+
def value_methods(new_value = NOT_CONFIGURED)
|
|
165
|
+
if NOT_CONFIGURED.equal?(new_value)
|
|
166
|
+
if @value_methods != nil
|
|
167
|
+
@value_methods
|
|
168
|
+
else
|
|
169
|
+
find_inherited_value(:value_methods, false)
|
|
170
|
+
end
|
|
171
|
+
else
|
|
172
|
+
@value_methods = new_value
|
|
173
|
+
end
|
|
174
|
+
end
|
|
175
|
+
|
|
128
176
|
def kind
|
|
129
177
|
GraphQL::TypeKinds::ENUM
|
|
130
178
|
end
|
|
131
179
|
|
|
132
180
|
def validate_non_null_input(value_name, ctx, max_errors: nil)
|
|
133
|
-
allowed_values = ctx.
|
|
181
|
+
allowed_values = ctx.types.enum_values(self)
|
|
134
182
|
matching_value = allowed_values.find { |v| v.graphql_name == value_name }
|
|
135
183
|
|
|
136
184
|
if matching_value.nil?
|
|
@@ -138,35 +186,55 @@ module GraphQL
|
|
|
138
186
|
else
|
|
139
187
|
nil
|
|
140
188
|
end
|
|
189
|
+
# rescue MissingValuesError
|
|
190
|
+
# nil
|
|
141
191
|
end
|
|
142
192
|
|
|
193
|
+
# Called by the runtime when a field returns a value to give back to the client.
|
|
194
|
+
# This method checks that the incoming {value} matches one of the enum's defined values.
|
|
195
|
+
# @param value [Object] Any value matching the values for this enum.
|
|
196
|
+
# @param ctx [GraphQL::Query::Context]
|
|
197
|
+
# @raise [GraphQL::Schema::Enum::UnresolvedValueError] if {value} doesn't match a configured value or if the matching value isn't authorized.
|
|
198
|
+
# @return [String] The GraphQL-ready string for {value}
|
|
143
199
|
def coerce_result(value, ctx)
|
|
144
|
-
|
|
145
|
-
all_values =
|
|
200
|
+
types = ctx.types
|
|
201
|
+
all_values = types ? types.enum_values(self) : values.each_value
|
|
146
202
|
enum_value = all_values.find { |val| val.value == value }
|
|
147
|
-
if enum_value
|
|
203
|
+
if enum_value && (was_authed = enum_value.authorized?(ctx))
|
|
148
204
|
enum_value.graphql_name
|
|
149
205
|
else
|
|
150
|
-
raise self::UnresolvedValueError.new(enum: self, value: value, context: ctx)
|
|
206
|
+
raise self::UnresolvedValueError.new(enum: self, value: value, context: ctx, authorized: was_authed)
|
|
151
207
|
end
|
|
152
208
|
end
|
|
153
209
|
|
|
210
|
+
# Called by the runtime with incoming string representations from a query.
|
|
211
|
+
# It will match the string to a configured by name or by Ruby value.
|
|
212
|
+
# @param value_name [String, Object] A string from a GraphQL query, or a Ruby value matching a `value(..., value: ...)` configuration
|
|
213
|
+
# @param ctx [GraphQL::Query::Context]
|
|
214
|
+
# @raise [GraphQL::UnauthorizedEnumValueError] if an {EnumValue} matches but returns false for `.authorized?`. Goes to {Schema.unauthorized_object}.
|
|
215
|
+
# @return [Object] The Ruby value for the matched {GraphQL::Schema::EnumValue}
|
|
154
216
|
def coerce_input(value_name, ctx)
|
|
155
|
-
all_values = ctx.
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
217
|
+
all_values = ctx.types ? ctx.types.enum_values(self) : values.each_value
|
|
218
|
+
|
|
219
|
+
# This tries matching by incoming GraphQL string, then checks Ruby-defined values
|
|
220
|
+
if v = (all_values.find { |val| val.graphql_name == value_name } || all_values.find { |val| val.value == value_name })
|
|
221
|
+
if v.authorized?(ctx)
|
|
222
|
+
v.value
|
|
223
|
+
else
|
|
224
|
+
raise GraphQL::UnauthorizedEnumValueError.new(type: self, enum_value: v, context: ctx)
|
|
225
|
+
end
|
|
163
226
|
else
|
|
164
227
|
nil
|
|
165
228
|
end
|
|
166
229
|
end
|
|
167
230
|
|
|
168
231
|
def inherited(child_class)
|
|
169
|
-
child_class.
|
|
232
|
+
if child_class.name
|
|
233
|
+
# Don't assign a custom error class to anonymous classes
|
|
234
|
+
# because they would end up with names like `#<Class0x1234>::UnresolvedValueError` which messes up bug trackers
|
|
235
|
+
child_class.const_set(:UnresolvedValueError, Class.new(Schema::Enum::UnresolvedValueError))
|
|
236
|
+
end
|
|
237
|
+
child_class.class_exec { @value_methods = nil }
|
|
170
238
|
super
|
|
171
239
|
end
|
|
172
240
|
|
|
@@ -175,6 +243,21 @@ module GraphQL
|
|
|
175
243
|
def own_values
|
|
176
244
|
@own_values ||= {}
|
|
177
245
|
end
|
|
246
|
+
|
|
247
|
+
def generate_value_method(value, configured_value_method)
|
|
248
|
+
return if configured_value_method == false
|
|
249
|
+
|
|
250
|
+
value_method_name = configured_value_method || value.graphql_name.downcase
|
|
251
|
+
|
|
252
|
+
if respond_to?(value_method_name.to_sym)
|
|
253
|
+
warn "Failed to define value method for :#{value_method_name}, because " \
|
|
254
|
+
"#{value.owner.name || value.owner.graphql_name} already responds to that method. Use `value_method:` to override the method name " \
|
|
255
|
+
"or `value_method: false` to disable Enum value method generation."
|
|
256
|
+
return
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
define_singleton_method(value_method_name) { value.graphql_name }
|
|
260
|
+
end
|
|
178
261
|
end
|
|
179
262
|
|
|
180
263
|
enum_value_class(GraphQL::Schema::EnumValue)
|
|
@@ -30,10 +30,11 @@ module GraphQL
|
|
|
30
30
|
# @return [Class] The enum type that owns this value
|
|
31
31
|
attr_reader :owner
|
|
32
32
|
|
|
33
|
-
def initialize(graphql_name, desc = nil, owner:, ast_node: nil, directives: nil, description: nil, value: NOT_CONFIGURED, deprecation_reason: nil, &block)
|
|
33
|
+
def initialize(graphql_name, desc = nil, owner:, ast_node: nil, directives: nil, description: nil, comment: nil, value: NOT_CONFIGURED, deprecation_reason: nil, &block)
|
|
34
34
|
@graphql_name = graphql_name.to_s
|
|
35
35
|
GraphQL::NameValidator.validate!(@graphql_name)
|
|
36
36
|
@description = desc || description
|
|
37
|
+
@comment = comment
|
|
37
38
|
@value = value == NOT_CONFIGURED ? @graphql_name : value
|
|
38
39
|
if deprecation_reason
|
|
39
40
|
self.deprecation_reason = deprecation_reason
|
|
@@ -58,6 +59,13 @@ module GraphQL
|
|
|
58
59
|
@description
|
|
59
60
|
end
|
|
60
61
|
|
|
62
|
+
def comment(new_comment = nil)
|
|
63
|
+
if new_comment
|
|
64
|
+
@comment = new_comment
|
|
65
|
+
end
|
|
66
|
+
@comment
|
|
67
|
+
end
|
|
68
|
+
|
|
61
69
|
def value(new_val = nil)
|
|
62
70
|
unless new_val.nil?
|
|
63
71
|
@value = new_val
|
|
@@ -66,7 +74,7 @@ module GraphQL
|
|
|
66
74
|
end
|
|
67
75
|
|
|
68
76
|
def inspect
|
|
69
|
-
"#<#{self.class} #{path} @value=#{@value.inspect}#{description ? " @description=#{description.inspect}" : ""}>"
|
|
77
|
+
"#<#{self.class} #{path} @value=#{@value.inspect}#{description ? " @description=#{description.inspect}" : ""}#{deprecation_reason ? " @deprecation_reason=#{deprecation_reason.inspect}" : ""}>"
|
|
70
78
|
end
|
|
71
79
|
|
|
72
80
|
def visible?(_ctx); true; end
|
|
@@ -21,59 +21,25 @@ module GraphQL
|
|
|
21
21
|
yield(object, next_args, arguments)
|
|
22
22
|
end
|
|
23
23
|
|
|
24
|
+
def resolve_next(objects:, arguments:, context:)
|
|
25
|
+
next_args = arguments.dup
|
|
26
|
+
next_args.delete(:first)
|
|
27
|
+
next_args.delete(:last)
|
|
28
|
+
next_args.delete(:before)
|
|
29
|
+
next_args.delete(:after)
|
|
30
|
+
yield(objects, next_args, arguments)
|
|
31
|
+
end
|
|
32
|
+
|
|
24
33
|
def after_resolve(value:, object:, arguments:, context:, memo:)
|
|
25
34
|
original_arguments = memo
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
value = nil
|
|
29
|
-
context.query.after_lazy(maybe_lazy) do |resolved_value|
|
|
30
|
-
value = resolved_value
|
|
31
|
-
if value.is_a? GraphQL::ExecutionError
|
|
32
|
-
# This isn't even going to work because context doesn't have ast_node anymore
|
|
33
|
-
context.add_error(value)
|
|
34
|
-
nil
|
|
35
|
-
elsif value.nil?
|
|
36
|
-
nil
|
|
37
|
-
elsif value.is_a?(GraphQL::Pagination::Connection)
|
|
38
|
-
# update the connection with some things that may not have been provided
|
|
39
|
-
value.context ||= context
|
|
40
|
-
value.parent ||= object.object
|
|
41
|
-
value.first_value ||= original_arguments[:first]
|
|
42
|
-
value.after_value ||= original_arguments[:after]
|
|
43
|
-
value.last_value ||= original_arguments[:last]
|
|
44
|
-
value.before_value ||= original_arguments[:before]
|
|
45
|
-
value.arguments ||= original_arguments # rubocop:disable Development/ContextIsPassedCop -- unrelated .arguments method
|
|
46
|
-
value.field ||= field
|
|
47
|
-
if field.has_max_page_size? && !value.has_max_page_size_override?
|
|
48
|
-
value.max_page_size = field.max_page_size
|
|
49
|
-
end
|
|
50
|
-
if field.has_default_page_size? && !value.has_default_page_size_override?
|
|
51
|
-
value.default_page_size = field.default_page_size
|
|
52
|
-
end
|
|
53
|
-
if context.schema.new_connections? && (custom_t = context.schema.connections.edge_class_for_field(@field))
|
|
54
|
-
value.edge_class = custom_t
|
|
55
|
-
end
|
|
56
|
-
value
|
|
57
|
-
elsif context.schema.new_connections?
|
|
58
|
-
context.namespace(:connections)[:all_wrappers] ||= context.schema.connections.all_wrappers
|
|
59
|
-
context.schema.connections.wrap(field, object.object, value, original_arguments, context)
|
|
60
|
-
else
|
|
61
|
-
if object.is_a?(GraphQL::Schema::Object)
|
|
62
|
-
object = object.object
|
|
63
|
-
end
|
|
64
|
-
connection_class = GraphQL::Relay::BaseConnection.connection_for_nodes(value)
|
|
65
|
-
connection_class.new(
|
|
66
|
-
value,
|
|
67
|
-
original_arguments,
|
|
68
|
-
field: field,
|
|
69
|
-
max_page_size: field.max_page_size,
|
|
70
|
-
default_page_size: field.default_page_size,
|
|
71
|
-
parent: object,
|
|
72
|
-
context: context,
|
|
73
|
-
)
|
|
74
|
-
end
|
|
35
|
+
context.query.after_lazy(value) do |resolved_value|
|
|
36
|
+
context.schema.connections.populate_connection(field, object.object, resolved_value, original_arguments, context)
|
|
75
37
|
end
|
|
76
38
|
end
|
|
39
|
+
|
|
40
|
+
def after_resolve_next(**kwargs)
|
|
41
|
+
raise "This should never be called -- it's hardcoded in execution instead."
|
|
42
|
+
end
|
|
77
43
|
end
|
|
78
44
|
end
|
|
79
45
|
end
|
|
@@ -5,17 +5,33 @@ module GraphQL
|
|
|
5
5
|
class Field
|
|
6
6
|
class ScopeExtension < GraphQL::Schema::FieldExtension
|
|
7
7
|
def after_resolve(object:, arguments:, context:, value:, memo:)
|
|
8
|
-
if
|
|
9
|
-
value
|
|
10
|
-
else
|
|
11
|
-
ret_type = @field.type.unwrap
|
|
12
|
-
if ret_type.respond_to?(:scope_items)
|
|
13
|
-
ret_type.scope_items(value, context)
|
|
14
|
-
else
|
|
8
|
+
if object.is_a?(GraphQL::Schema::Object)
|
|
9
|
+
if value.nil?
|
|
15
10
|
value
|
|
11
|
+
else
|
|
12
|
+
return_type = field.type.unwrap
|
|
13
|
+
if return_type.respond_to?(:scope_items)
|
|
14
|
+
scoped_items = return_type.scope_items(value, context)
|
|
15
|
+
if !scoped_items.equal?(value) && !return_type.reauthorize_scoped_objects
|
|
16
|
+
if (current_runtime_state = Fiber[:__graphql_runtime_info]) &&
|
|
17
|
+
(query_runtime_state = current_runtime_state[context.query])
|
|
18
|
+
query_runtime_state.was_authorized_by_scope_items = true
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
scoped_items
|
|
22
|
+
else
|
|
23
|
+
value
|
|
24
|
+
end
|
|
16
25
|
end
|
|
26
|
+
else
|
|
27
|
+
# TODO skip this entirely?
|
|
28
|
+
value
|
|
17
29
|
end
|
|
18
30
|
end
|
|
31
|
+
|
|
32
|
+
def after_resolve_next(**kwargs)
|
|
33
|
+
raise "This should never be called -- it's hardcoded in execution instead."
|
|
34
|
+
end
|
|
19
35
|
end
|
|
20
36
|
end
|
|
21
37
|
end
|