|
7 | 7 | require "graphql/schema/finder" |
8 | 8 | require "graphql/schema/introspection_system" |
9 | 9 | require "graphql/schema/late_bound_type" |
| 10 | +require "graphql/schema/ractor_shareable" |
10 | 11 | require "graphql/schema/timeout" |
11 | 12 | require "graphql/schema/type_expression" |
12 | 13 | require "graphql/schema/unique_within_type" |
@@ -148,10 +149,12 @@ def subscriptions=(new_implementation) |
148 | 149 | end |
149 | 150 |
|
150 | 151 | # @param new_mode [Symbol] If configured, this will be used when `context: { trace_mode: ... }` isn't set. |
151 | | - def default_trace_mode(new_mode = nil) |
152 | | - if new_mode |
| 152 | + def default_trace_mode(new_mode = NOT_CONFIGURED) |
| 153 | + if !NOT_CONFIGURED.equal?(new_mode) |
153 | 154 | @default_trace_mode = new_mode |
154 | | - elsif defined?(@default_trace_mode) |
| 155 | + elsif defined?(@default_trace_mode) && |
| 156 | + !@default_trace_mode.nil? # This `nil?` check seems necessary because of |
| 157 | + # Ractors silently initializing @default_trace_mode somehow |
155 | 158 | @default_trace_mode |
156 | 159 | elsif superclass.respond_to?(:default_trace_mode) |
157 | 160 | superclass.default_trace_mode |
@@ -365,7 +368,8 @@ def types(context = GraphQL::Query::NullContext.instance) |
365 | 368 | # @return [Module, nil] A type, or nil if there's no type called `type_name` |
366 | 369 | def get_type(type_name, context = GraphQL::Query::NullContext.instance, use_visibility_profile = use_visibility_profile?) |
367 | 370 | if use_visibility_profile |
368 | | - return Visibility::Profile.from_context(context, self).type(type_name) |
| 371 | + profile = Visibility::Profile.from_context(context, self) |
| 372 | + return profile.type(type_name) |
369 | 373 | end |
370 | 374 | local_entry = own_types[type_name] |
371 | 375 | type_defn = case local_entry |
@@ -697,7 +701,21 @@ def type_from_ast(ast_node, context: self.query_class.new(self, "{ __typename }" |
697 | 701 | GraphQL::Schema::TypeExpression.build_type(context.query.types, ast_node) |
698 | 702 | end |
699 | 703 |
|
700 | | - def get_field(type_or_name, field_name, context = GraphQL::Query::NullContext.instance) |
| 704 | + def get_field(type_or_name, field_name, context = GraphQL::Query::NullContext.instance, use_visibility_profile = use_visibility_profile?) |
| 705 | + if use_visibility_profile |
| 706 | + profile = Visibility::Profile.from_context(context, self) |
| 707 | + parent_type = case type_or_name |
| 708 | + when String |
| 709 | + profile.type(type_or_name) |
| 710 | + when Module |
| 711 | + type_or_name |
| 712 | + when LateBoundType |
| 713 | + profile.type(type_or_name.name) |
| 714 | + else |
| 715 | + raise GraphQL::InvariantError, "Unexpected field owner for #{field_name.inspect}: #{type_or_name.inspect} (#{type_or_name.class})" |
| 716 | + end |
| 717 | + return profile.field(parent_type, field_name) |
| 718 | + end |
701 | 719 | parent_type = case type_or_name |
702 | 720 | when LateBoundType |
703 | 721 | get_type(type_or_name.name, context) |
@@ -1105,20 +1123,21 @@ def rescue_from(*err_classes, &handler_block) |
1105 | 1123 | end |
1106 | 1124 | end |
1107 | 1125 |
|
1108 | | - NEW_HANDLER_HASH = ->(h, k) { |
1109 | | - h[k] = { |
1110 | | - class: k, |
1111 | | - handler: nil, |
1112 | | - subclass_handlers: Hash.new(&NEW_HANDLER_HASH), |
1113 | | - } |
1114 | | - } |
1115 | | - |
1116 | 1126 | def error_handlers |
1117 | | - @error_handlers ||= { |
1118 | | - class: nil, |
1119 | | - handler: nil, |
1120 | | - subclass_handlers: Hash.new(&NEW_HANDLER_HASH), |
1121 | | - } |
| 1127 | + @error_handlers ||= begin |
| 1128 | + new_handler_hash = ->(h, k) { |
| 1129 | + h[k] = { |
| 1130 | + class: k, |
| 1131 | + handler: nil, |
| 1132 | + subclass_handlers: Hash.new(&new_handler_hash), |
| 1133 | + } |
| 1134 | + } |
| 1135 | + { |
| 1136 | + class: nil, |
| 1137 | + handler: nil, |
| 1138 | + subclass_handlers: Hash.new(&new_handler_hash), |
| 1139 | + } |
| 1140 | + end |
1122 | 1141 | end |
1123 | 1142 |
|
1124 | 1143 | # @api private |
|
0 commit comments