graphql 1.13.19 → 2.0.19

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.

Potentially problematic release.


This version of graphql might be problematic. Click here for more details.

Files changed (256) hide show
  1. checksums.yaml +4 -4
  2. data/lib/generators/graphql/install_generator.rb +1 -1
  3. data/lib/generators/graphql/relay.rb +3 -17
  4. data/lib/generators/graphql/templates/schema.erb +3 -0
  5. data/lib/graphql/analysis/ast/field_usage.rb +3 -1
  6. data/lib/graphql/analysis/ast/max_query_complexity.rb +0 -1
  7. data/lib/graphql/analysis/ast/query_complexity.rb +1 -1
  8. data/lib/graphql/analysis/ast/query_depth.rb +0 -1
  9. data/lib/graphql/analysis/ast/visitor.rb +43 -36
  10. data/lib/graphql/analysis/ast.rb +2 -12
  11. data/lib/graphql/analysis.rb +0 -7
  12. data/lib/graphql/backtrace/table.rb +2 -20
  13. data/lib/graphql/backtrace/tracer.rb +2 -3
  14. data/lib/graphql/backtrace.rb +2 -8
  15. data/lib/graphql/dataloader/null_dataloader.rb +3 -1
  16. data/lib/graphql/dataloader/source.rb +9 -0
  17. data/lib/graphql/dataloader.rb +4 -1
  18. data/lib/graphql/dig.rb +1 -1
  19. data/lib/graphql/execution/errors.rb +12 -82
  20. data/lib/graphql/execution/interpreter/resolve.rb +26 -0
  21. data/lib/graphql/execution/interpreter/runtime.rb +162 -119
  22. data/lib/graphql/execution/interpreter.rb +187 -78
  23. data/lib/graphql/execution/lazy.rb +7 -21
  24. data/lib/graphql/execution/lookahead.rb +44 -40
  25. data/lib/graphql/execution/multiplex.rb +3 -174
  26. data/lib/graphql/execution.rb +11 -4
  27. data/lib/graphql/introspection/dynamic_fields.rb +3 -8
  28. data/lib/graphql/introspection/entry_points.rb +2 -15
  29. data/lib/graphql/introspection/type_type.rb +8 -1
  30. data/lib/graphql/introspection.rb +4 -3
  31. data/lib/graphql/language/document_from_schema_definition.rb +18 -35
  32. data/lib/graphql/language/lexer.rb +216 -1488
  33. data/lib/graphql/language/lexer.ri +744 -0
  34. data/lib/graphql/language/nodes.rb +41 -33
  35. data/lib/graphql/language/parser.rb +375 -363
  36. data/lib/graphql/language/parser.y +48 -43
  37. data/lib/graphql/language/printer.rb +37 -21
  38. data/lib/graphql/language/visitor.rb +191 -83
  39. data/lib/graphql/pagination/active_record_relation_connection.rb +0 -8
  40. data/lib/graphql/pagination/array_connection.rb +4 -2
  41. data/lib/graphql/pagination/connection.rb +31 -4
  42. data/lib/graphql/pagination/connections.rb +3 -28
  43. data/lib/graphql/pagination/relation_connection.rb +2 -0
  44. data/lib/graphql/query/context.rb +155 -196
  45. data/lib/graphql/query/input_validation_result.rb +1 -1
  46. data/lib/graphql/query/null_context.rb +0 -3
  47. data/lib/graphql/query/validation_pipeline.rb +10 -34
  48. data/lib/graphql/query/variables.rb +7 -20
  49. data/lib/graphql/query.rb +32 -42
  50. data/lib/graphql/railtie.rb +0 -104
  51. data/lib/graphql/rake_task/validate.rb +1 -1
  52. data/lib/graphql/rake_task.rb +29 -1
  53. data/lib/graphql/relay/range_add.rb +9 -20
  54. data/lib/graphql/relay.rb +0 -15
  55. data/lib/graphql/schema/addition.rb +7 -9
  56. data/lib/graphql/schema/argument.rb +36 -43
  57. data/lib/graphql/schema/build_from_definition.rb +32 -18
  58. data/lib/graphql/schema/directive/one_of.rb +12 -0
  59. data/lib/graphql/schema/directive/transform.rb +1 -1
  60. data/lib/graphql/schema/directive.rb +11 -22
  61. data/lib/graphql/schema/enum.rb +28 -39
  62. data/lib/graphql/schema/enum_value.rb +5 -25
  63. data/lib/graphql/schema/field/connection_extension.rb +4 -0
  64. data/lib/graphql/schema/field.rb +214 -327
  65. data/lib/graphql/schema/input_object.rb +56 -67
  66. data/lib/graphql/schema/interface.rb +0 -35
  67. data/lib/graphql/schema/introspection_system.rb +3 -8
  68. data/lib/graphql/schema/late_bound_type.rb +8 -2
  69. data/lib/graphql/schema/list.rb +0 -6
  70. data/lib/graphql/schema/loader.rb +1 -2
  71. data/lib/graphql/schema/member/base_dsl_methods.rb +15 -19
  72. data/lib/graphql/schema/member/build_type.rb +5 -7
  73. data/lib/graphql/schema/member/has_arguments.rb +144 -53
  74. data/lib/graphql/schema/member/has_deprecation_reason.rb +3 -4
  75. data/lib/graphql/schema/member/has_directives.rb +71 -56
  76. data/lib/graphql/schema/member/has_fields.rb +15 -3
  77. data/lib/graphql/schema/member/has_interfaces.rb +47 -18
  78. data/lib/graphql/schema/member/has_validators.rb +31 -5
  79. data/lib/graphql/schema/member/relay_shortcuts.rb +28 -2
  80. data/lib/graphql/schema/member/type_system_helpers.rb +17 -0
  81. data/lib/graphql/schema/member/validates_input.rb +1 -1
  82. data/lib/graphql/schema/member.rb +0 -6
  83. data/lib/graphql/schema/mutation.rb +0 -9
  84. data/lib/graphql/schema/non_null.rb +1 -7
  85. data/lib/graphql/schema/object.rb +15 -52
  86. data/lib/graphql/schema/relay_classic_mutation.rb +53 -42
  87. data/lib/graphql/schema/resolver/has_payload_type.rb +20 -10
  88. data/lib/graphql/schema/resolver.rb +41 -42
  89. data/lib/graphql/schema/scalar.rb +7 -22
  90. data/lib/graphql/schema/subscription.rb +0 -7
  91. data/lib/graphql/schema/timeout.rb +24 -28
  92. data/lib/graphql/schema/type_membership.rb +3 -0
  93. data/lib/graphql/schema/union.rb +10 -17
  94. data/lib/graphql/schema/warden.rb +23 -6
  95. data/lib/graphql/schema/wrapper.rb +0 -5
  96. data/lib/graphql/schema.rb +240 -968
  97. data/lib/graphql/static_validation/all_rules.rb +1 -0
  98. data/lib/graphql/static_validation/base_visitor.rb +4 -21
  99. data/lib/graphql/static_validation/definition_dependencies.rb +7 -1
  100. data/lib/graphql/static_validation/error.rb +2 -2
  101. data/lib/graphql/static_validation/literal_validator.rb +19 -1
  102. data/lib/graphql/static_validation/rules/directives_are_defined.rb +11 -5
  103. data/lib/graphql/static_validation/rules/directives_are_in_valid_locations.rb +12 -12
  104. data/lib/graphql/static_validation/rules/one_of_input_objects_are_valid.rb +66 -0
  105. data/lib/graphql/static_validation/rules/one_of_input_objects_are_valid_error.rb +29 -0
  106. data/lib/graphql/static_validation/rules/unique_directives_per_location.rb +12 -6
  107. data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed.rb +1 -1
  108. data/lib/graphql/static_validation/validator.rb +3 -25
  109. data/lib/graphql/static_validation.rb +0 -2
  110. data/lib/graphql/subscriptions/action_cable_subscriptions.rb +7 -1
  111. data/lib/graphql/subscriptions/default_subscription_resolve_extension.rb +38 -1
  112. data/lib/graphql/subscriptions/event.rb +3 -8
  113. data/lib/graphql/subscriptions/instrumentation.rb +0 -51
  114. data/lib/graphql/subscriptions.rb +32 -20
  115. data/lib/graphql/tracing/active_support_notifications_trace.rb +16 -0
  116. data/lib/graphql/tracing/appoptics_trace.rb +231 -0
  117. data/lib/graphql/tracing/appsignal_trace.rb +66 -0
  118. data/lib/graphql/tracing/data_dog_trace.rb +148 -0
  119. data/lib/graphql/tracing/data_dog_tracing.rb +2 -0
  120. data/lib/graphql/tracing/new_relic_trace.rb +75 -0
  121. data/lib/graphql/tracing/notifications_trace.rb +41 -0
  122. data/lib/graphql/tracing/platform_trace.rb +107 -0
  123. data/lib/graphql/tracing/platform_tracing.rb +26 -41
  124. data/lib/graphql/tracing/prometheus_trace.rb +89 -0
  125. data/lib/graphql/tracing/prometheus_tracing.rb +3 -3
  126. data/lib/graphql/tracing/scout_trace.rb +72 -0
  127. data/lib/graphql/tracing/statsd_trace.rb +56 -0
  128. data/lib/graphql/tracing.rb +136 -40
  129. data/lib/graphql/type_kinds.rb +6 -3
  130. data/lib/graphql/types/iso_8601_date.rb +4 -1
  131. data/lib/graphql/types/iso_8601_date_time.rb +4 -0
  132. data/lib/graphql/types/relay/base_connection.rb +16 -6
  133. data/lib/graphql/types/relay/connection_behaviors.rb +5 -25
  134. data/lib/graphql/types/relay/default_relay.rb +5 -9
  135. data/lib/graphql/types/relay/edge_behaviors.rb +1 -4
  136. data/lib/graphql/types/relay/node_behaviors.rb +5 -1
  137. data/lib/graphql/types/relay.rb +0 -2
  138. data/lib/graphql/types/string.rb +1 -1
  139. data/lib/graphql/version.rb +1 -1
  140. data/lib/graphql.rb +11 -72
  141. metadata +31 -132
  142. data/lib/graphql/analysis/analyze_query.rb +0 -98
  143. data/lib/graphql/analysis/field_usage.rb +0 -45
  144. data/lib/graphql/analysis/max_query_complexity.rb +0 -26
  145. data/lib/graphql/analysis/max_query_depth.rb +0 -26
  146. data/lib/graphql/analysis/query_complexity.rb +0 -88
  147. data/lib/graphql/analysis/query_depth.rb +0 -43
  148. data/lib/graphql/analysis/reducer_state.rb +0 -48
  149. data/lib/graphql/argument.rb +0 -131
  150. data/lib/graphql/authorization.rb +0 -82
  151. data/lib/graphql/backtrace/legacy_tracer.rb +0 -56
  152. data/lib/graphql/backwards_compatibility.rb +0 -61
  153. data/lib/graphql/base_type.rb +0 -232
  154. data/lib/graphql/boolean_type.rb +0 -2
  155. data/lib/graphql/compatibility/execution_specification/counter_schema.rb +0 -53
  156. data/lib/graphql/compatibility/execution_specification/specification_schema.rb +0 -200
  157. data/lib/graphql/compatibility/execution_specification.rb +0 -436
  158. data/lib/graphql/compatibility/lazy_execution_specification/lazy_schema.rb +0 -111
  159. data/lib/graphql/compatibility/lazy_execution_specification.rb +0 -215
  160. data/lib/graphql/compatibility/query_parser_specification/parse_error_specification.rb +0 -87
  161. data/lib/graphql/compatibility/query_parser_specification/query_assertions.rb +0 -79
  162. data/lib/graphql/compatibility/query_parser_specification.rb +0 -266
  163. data/lib/graphql/compatibility/schema_parser_specification.rb +0 -682
  164. data/lib/graphql/compatibility.rb +0 -5
  165. data/lib/graphql/define/assign_argument.rb +0 -12
  166. data/lib/graphql/define/assign_connection.rb +0 -13
  167. data/lib/graphql/define/assign_enum_value.rb +0 -18
  168. data/lib/graphql/define/assign_global_id_field.rb +0 -11
  169. data/lib/graphql/define/assign_mutation_function.rb +0 -34
  170. data/lib/graphql/define/assign_object_field.rb +0 -42
  171. data/lib/graphql/define/defined_object_proxy.rb +0 -53
  172. data/lib/graphql/define/instance_definable.rb +0 -255
  173. data/lib/graphql/define/no_definition_error.rb +0 -7
  174. data/lib/graphql/define/non_null_with_bang.rb +0 -16
  175. data/lib/graphql/define/type_definer.rb +0 -31
  176. data/lib/graphql/define.rb +0 -31
  177. data/lib/graphql/deprecated_dsl.rb +0 -55
  178. data/lib/graphql/directive/deprecated_directive.rb +0 -2
  179. data/lib/graphql/directive/include_directive.rb +0 -2
  180. data/lib/graphql/directive/skip_directive.rb +0 -2
  181. data/lib/graphql/directive.rb +0 -107
  182. data/lib/graphql/enum_type.rb +0 -133
  183. data/lib/graphql/execution/execute.rb +0 -333
  184. data/lib/graphql/execution/flatten.rb +0 -40
  185. data/lib/graphql/execution/instrumentation.rb +0 -92
  186. data/lib/graphql/execution/lazy/resolve.rb +0 -91
  187. data/lib/graphql/execution/typecast.rb +0 -50
  188. data/lib/graphql/field/resolve.rb +0 -59
  189. data/lib/graphql/field.rb +0 -226
  190. data/lib/graphql/float_type.rb +0 -2
  191. data/lib/graphql/function.rb +0 -128
  192. data/lib/graphql/id_type.rb +0 -2
  193. data/lib/graphql/input_object_type.rb +0 -138
  194. data/lib/graphql/int_type.rb +0 -2
  195. data/lib/graphql/interface_type.rb +0 -72
  196. data/lib/graphql/internal_representation/document.rb +0 -27
  197. data/lib/graphql/internal_representation/node.rb +0 -206
  198. data/lib/graphql/internal_representation/print.rb +0 -51
  199. data/lib/graphql/internal_representation/rewrite.rb +0 -184
  200. data/lib/graphql/internal_representation/scope.rb +0 -88
  201. data/lib/graphql/internal_representation/visit.rb +0 -36
  202. data/lib/graphql/internal_representation.rb +0 -7
  203. data/lib/graphql/language/lexer.rl +0 -260
  204. data/lib/graphql/list_type.rb +0 -80
  205. data/lib/graphql/non_null_type.rb +0 -71
  206. data/lib/graphql/object_type.rb +0 -130
  207. data/lib/graphql/query/arguments.rb +0 -189
  208. data/lib/graphql/query/arguments_cache.rb +0 -24
  209. data/lib/graphql/query/executor.rb +0 -52
  210. data/lib/graphql/query/literal_input.rb +0 -136
  211. data/lib/graphql/query/serial_execution/field_resolution.rb +0 -92
  212. data/lib/graphql/query/serial_execution/operation_resolution.rb +0 -19
  213. data/lib/graphql/query/serial_execution/selection_resolution.rb +0 -23
  214. data/lib/graphql/query/serial_execution/value_resolution.rb +0 -87
  215. data/lib/graphql/query/serial_execution.rb +0 -40
  216. data/lib/graphql/relay/array_connection.rb +0 -83
  217. data/lib/graphql/relay/base_connection.rb +0 -189
  218. data/lib/graphql/relay/connection_instrumentation.rb +0 -54
  219. data/lib/graphql/relay/connection_resolve.rb +0 -43
  220. data/lib/graphql/relay/connection_type.rb +0 -54
  221. data/lib/graphql/relay/edge.rb +0 -27
  222. data/lib/graphql/relay/edge_type.rb +0 -19
  223. data/lib/graphql/relay/edges_instrumentation.rb +0 -39
  224. data/lib/graphql/relay/global_id_resolve.rb +0 -17
  225. data/lib/graphql/relay/mongo_relation_connection.rb +0 -50
  226. data/lib/graphql/relay/mutation/instrumentation.rb +0 -23
  227. data/lib/graphql/relay/mutation/resolve.rb +0 -56
  228. data/lib/graphql/relay/mutation/result.rb +0 -38
  229. data/lib/graphql/relay/mutation.rb +0 -106
  230. data/lib/graphql/relay/node.rb +0 -39
  231. data/lib/graphql/relay/page_info.rb +0 -7
  232. data/lib/graphql/relay/relation_connection.rb +0 -188
  233. data/lib/graphql/relay/type_extensions.rb +0 -32
  234. data/lib/graphql/scalar_type.rb +0 -91
  235. data/lib/graphql/schema/catchall_middleware.rb +0 -35
  236. data/lib/graphql/schema/default_parse_error.rb +0 -10
  237. data/lib/graphql/schema/default_type_error.rb +0 -17
  238. data/lib/graphql/schema/member/accepts_definition.rb +0 -164
  239. data/lib/graphql/schema/member/cached_graphql_definition.rb +0 -58
  240. data/lib/graphql/schema/member/instrumentation.rb +0 -131
  241. data/lib/graphql/schema/middleware_chain.rb +0 -82
  242. data/lib/graphql/schema/possible_types.rb +0 -44
  243. data/lib/graphql/schema/rescue_middleware.rb +0 -60
  244. data/lib/graphql/schema/timeout_middleware.rb +0 -88
  245. data/lib/graphql/schema/traversal.rb +0 -228
  246. data/lib/graphql/schema/validation.rb +0 -313
  247. data/lib/graphql/static_validation/default_visitor.rb +0 -15
  248. data/lib/graphql/static_validation/no_validate_visitor.rb +0 -10
  249. data/lib/graphql/string_type.rb +0 -2
  250. data/lib/graphql/subscriptions/subscription_root.rb +0 -76
  251. data/lib/graphql/tracing/skylight_tracing.rb +0 -70
  252. data/lib/graphql/types/relay/node_field.rb +0 -24
  253. data/lib/graphql/types/relay/nodes_field.rb +0 -43
  254. data/lib/graphql/union_type.rb +0 -115
  255. data/lib/graphql/upgrader/member.rb +0 -937
  256. data/lib/graphql/upgrader/schema.rb +0 -38
@@ -1,43 +0,0 @@
1
- # frozen_string_literal: true
2
- module GraphQL
3
- module Analysis
4
- # A query reducer for measuring the depth of a given query.
5
- #
6
- # @example Logging the depth of a query
7
- # Schema.query_analyzers << GraphQL::Analysis::QueryDepth.new { |query, depth| puts "GraphQL query depth: #{depth}" }
8
- # Schema.execute(query_str)
9
- # # GraphQL query depth: 8
10
- #
11
- class QueryDepth
12
- def initialize(&block)
13
- @depth_handler = block
14
- end
15
-
16
- def initial_value(query)
17
- {
18
- max_depth: 0,
19
- current_depth: 0,
20
- query: query,
21
- }
22
- end
23
-
24
- def call(memo, visit_type, irep_node)
25
- if irep_node.ast_node.is_a?(GraphQL::Language::Nodes::Field)
26
- if visit_type == :enter
27
- memo[:current_depth] += 1
28
- else
29
- if memo[:max_depth] < memo[:current_depth]
30
- memo[:max_depth] = memo[:current_depth]
31
- end
32
- memo[:current_depth] -= 1
33
- end
34
- end
35
- memo
36
- end
37
-
38
- def final_value(memo)
39
- @depth_handler.call(memo[:query], memo[:max_depth])
40
- end
41
- end
42
- end
43
- end
@@ -1,48 +0,0 @@
1
- # frozen_string_literal: true
2
- module GraphQL
3
- module Analysis
4
- class ReducerState
5
- attr_reader :reducer
6
- attr_accessor :memo, :errors
7
-
8
- def initialize(reducer, query)
9
- @reducer = reducer
10
- @memo = initialize_reducer(reducer, query)
11
- @errors = []
12
- end
13
-
14
- def call(visit_type, irep_node)
15
- @memo = @reducer.call(@memo, visit_type, irep_node)
16
- rescue AnalysisError => err
17
- @errors << err
18
- end
19
-
20
- # Respond with any errors, if found. Otherwise, if the reducer accepts
21
- # `final_value`, send it the last memo value.
22
- # Otherwise, use the last value from the traversal.
23
- # @return [Any] final memo value
24
- def finalize_reducer
25
- if @errors.any?
26
- @errors
27
- elsif reducer.respond_to?(:final_value)
28
- reducer.final_value(@memo)
29
- else
30
- @memo
31
- end
32
- end
33
-
34
- private
35
-
36
- # If the reducer has an `initial_value` method, call it and store
37
- # the result as `memo`. Otherwise, use `nil` as memo.
38
- # @return [Any] initial memo value
39
- def initialize_reducer(reducer, query)
40
- if reducer.respond_to?(:initial_value)
41
- reducer.initial_value(query)
42
- else
43
- nil
44
- end
45
- end
46
- end
47
- end
48
- end
@@ -1,131 +0,0 @@
1
- # frozen_string_literal: true
2
- module GraphQL
3
- # @api deprecated
4
- class Argument
5
- include GraphQL::Define::InstanceDefinable
6
- deprecated_accepts_definitions :name, :type, :description, :default_value, :as, :prepare, :method_access, :deprecation_reason
7
- attr_reader :default_value
8
- attr_accessor :description, :name, :as, :deprecation_reason
9
- attr_accessor :ast_node
10
- attr_accessor :method_access
11
- alias :graphql_name :name
12
-
13
- ensure_defined(:name, :description, :default_value, :type=, :type, :as, :expose_as, :prepare, :method_access, :deprecation_reason)
14
-
15
- # @api private
16
- module DefaultPrepare
17
- def self.call(value, ctx); value; end
18
- end
19
-
20
- def initialize
21
- @prepare_proc = DefaultPrepare
22
- end
23
-
24
- def initialize_copy(other)
25
- @expose_as = nil
26
- end
27
-
28
- def default_value?
29
- !!@has_default_value
30
- end
31
-
32
- def method_access?
33
- # Treat unset as true -- only `false` should override
34
- @method_access != false
35
- end
36
-
37
- def default_value=(new_default_value)
38
- if new_default_value == NO_DEFAULT_VALUE
39
- @has_default_value = false
40
- @default_value = nil
41
- else
42
- @has_default_value = true
43
- @default_value = GraphQL::Argument.deep_stringify(new_default_value)
44
- end
45
- end
46
-
47
- # @!attribute name
48
- # @return [String] The name of this argument on its {GraphQL::Field} or {GraphQL::InputObjectType}
49
-
50
- # @param new_input_type [GraphQL::BaseType, Proc] Assign a new input type for this argument (if it's a proc, it will be called after schema initialization)
51
- def type=(new_input_type)
52
- @clean_type = nil
53
- @dirty_type = new_input_type
54
- end
55
-
56
- # @return [GraphQL::BaseType] the input type for this argument
57
- def type
58
- @clean_type ||= GraphQL::BaseType.resolve_related_type(@dirty_type)
59
- end
60
-
61
- # @return [String] The name of this argument inside `resolve` functions
62
- def expose_as
63
- @expose_as ||= (@as || @name).to_s
64
- end
65
-
66
- # Backport this to support legacy-style directives
67
- def keyword
68
- @keyword ||= GraphQL::Schema::Member::BuildType.underscore(expose_as).to_sym
69
- end
70
-
71
- # @param value [Object] The incoming value from variables or query string literal
72
- # @param ctx [GraphQL::Query::Context]
73
- # @return [Object] The prepared `value` for this argument or `value` itself if no `prepare` function exists.
74
- def prepare(value, ctx)
75
- @prepare_proc.call(value, ctx)
76
- end
77
-
78
- # Assign a `prepare` function to prepare this argument's value before `resolve` functions are called.
79
- # @param prepare_proc [#<call(value, ctx)>]
80
- def prepare=(prepare_proc)
81
- @prepare_proc = BackwardsCompatibility.wrap_arity(prepare_proc, from: 1, to: 2, name: "Argument#prepare(value, ctx)")
82
- end
83
-
84
- def type_class
85
- metadata[:type_class]
86
- end
87
-
88
- NO_DEFAULT_VALUE = Object.new
89
- # @api private
90
- def self.from_dsl(name, type_or_argument = nil, description = nil, default_value: NO_DEFAULT_VALUE, as: nil, prepare: DefaultPrepare, **kwargs, &block)
91
- name_s = name.to_s
92
-
93
- # Move some positional args into keywords if they're present
94
- description && kwargs[:description] ||= description
95
- kwargs[:name] ||= name_s
96
- kwargs[:default_value] ||= default_value
97
- kwargs[:as] ||= as
98
-
99
- unless prepare == DefaultPrepare
100
- kwargs[:prepare] ||= prepare
101
- end
102
-
103
- if !type_or_argument.nil? && !type_or_argument.is_a?(GraphQL::Argument)
104
- # Maybe a string, proc or BaseType
105
- kwargs[:type] = type_or_argument
106
- end
107
-
108
- if type_or_argument.is_a?(GraphQL::Argument)
109
- type_or_argument.redefine(**kwargs, &block)
110
- else
111
- GraphQL::Argument.define(**kwargs, &block)
112
- end
113
- end
114
-
115
- # @api private
116
- def self.deep_stringify(val)
117
- case val
118
- when Array
119
- val.map { |v| deep_stringify(v) }
120
- when Hash
121
- new_val = {}
122
- val.each do |k, v|
123
- new_val[k.to_s] = deep_stringify(v)
124
- end
125
- new_val
126
- else
127
- val
128
- end
129
- end
130
- end
131
- end
@@ -1,82 +0,0 @@
1
- # frozen_string_literal: true
2
- module GraphQL
3
- module Authorization
4
- class InaccessibleFieldsError < GraphQL::AnalysisError
5
- # @return [Array<Schema::Field, GraphQL::Field>] Fields that failed `.accessible?` checks
6
- attr_reader :fields
7
-
8
- # @return [GraphQL::Query::Context] The current query's context
9
- attr_reader :context
10
-
11
- # @return [Array<GraphQL::InternalRepresentation::Node>] The visited nodes that failed `.accessible?` checks
12
- # @see {#fields} for the Field definitions
13
- attr_reader :irep_nodes
14
-
15
- def initialize(fields:, irep_nodes:, context:)
16
- @fields = fields
17
- @irep_nodes = irep_nodes
18
- @context = context
19
- super("Some fields in this query are not accessible: #{fields.map(&:graphql_name).join(", ")}")
20
- end
21
- end
22
-
23
- # @deprecated authorization at query runtime is generally a better idea.
24
- module Analyzer
25
- module_function
26
- def initial_value(query)
27
- {
28
- schema: query.schema,
29
- context: query.context,
30
- inaccessible_nodes: [],
31
- }
32
- end
33
-
34
- def call(memo, visit_type, irep_node)
35
- if visit_type == :enter
36
- field = irep_node.definition
37
- if field
38
- schema = memo[:schema]
39
- ctx = memo[:context]
40
- next_field_accessible = schema.accessible?(field, ctx)
41
- if !next_field_accessible
42
- memo[:inaccessible_nodes] << irep_node
43
- else
44
- arg_accessible = true
45
- irep_node.arguments.argument_values.each do |name, arg_value|
46
- arg_accessible = schema.accessible?(arg_value.definition, ctx)
47
- if !arg_accessible
48
- memo[:inaccessible_nodes] << irep_node
49
- break
50
- end
51
- end
52
- if arg_accessible
53
- return_type = field.type.unwrap
54
- next_type_accessible = schema.accessible?(return_type, ctx)
55
- if !next_type_accessible
56
- memo[:inaccessible_nodes] << irep_node
57
- end
58
- end
59
- end
60
- end
61
- end
62
- memo
63
- end
64
-
65
- def final_value(memo)
66
- nodes = memo[:inaccessible_nodes]
67
- if nodes.any?
68
- fields = nodes.map do |node|
69
- field_inst = node.definition
70
- # Get the "source of truth" for this field
71
- field_inst.metadata[:type_class] || field_inst
72
- end
73
- context = memo[:context]
74
- err = InaccessibleFieldsError.new(fields: fields, irep_nodes: nodes, context: context)
75
- context.schema.inaccessible_fields(err)
76
- else
77
- nil
78
- end
79
- end
80
- end
81
- end
82
- end
@@ -1,56 +0,0 @@
1
- # frozen_string_literal: true
2
- module GraphQL
3
- class Backtrace
4
- module LegacyTracer
5
- module_function
6
-
7
- # Implement the {GraphQL::Tracing} API.
8
- def trace(key, metadata)
9
- case key
10
- when "lex", "parse"
11
- # No context here, don't have a query yet
12
- nil
13
- when "execute_multiplex", "analyze_multiplex"
14
- # No query context yet
15
- nil
16
- when "validate", "analyze_query", "execute_query", "execute_query_lazy"
17
- query = metadata[:query] || metadata[:queries].first
18
- push_data = query
19
- multiplex = query.multiplex
20
- when "execute_field", "execute_field_lazy"
21
- # The interpreter passes `query:`, legacy passes `context:`
22
- context = metadata[:context] || ((q = metadata[:query]) && q.context)
23
- push_data = context
24
- multiplex = context.query.multiplex
25
- else
26
- # Custom key, no backtrace data for this
27
- nil
28
- end
29
-
30
- if push_data
31
- multiplex.context[:last_graphql_backtrace_context] = push_data
32
- end
33
-
34
- if key == "execute_multiplex"
35
- begin
36
- yield
37
- rescue StandardError => err
38
- # This is an unhandled error from execution,
39
- # Re-raise it with a GraphQL trace.
40
- potential_context = metadata[:multiplex].context[:last_graphql_backtrace_context]
41
-
42
- if potential_context.is_a?(GraphQL::Query::Context) || potential_context.is_a?(GraphQL::Query::Context::FieldResolutionContext)
43
- raise TracedError.new(err, potential_context)
44
- else
45
- raise
46
- end
47
- ensure
48
- metadata[:multiplex].context.delete(:last_graphql_backtrace_context)
49
- end
50
- else
51
- yield
52
- end
53
- end
54
- end
55
- end
56
- end
@@ -1,61 +0,0 @@
1
- # frozen_string_literal: true
2
- module GraphQL
3
- # Helpers for migrating in a backwards-compatible way
4
- # Remove this in GraphQL-Ruby 2.0, when all users of it will be gone.
5
- # @api private
6
- module BackwardsCompatibility
7
- module_function
8
- # Given a callable whose API used to take `from` arguments,
9
- # check its arity, and if needed, apply a wrapper so that
10
- # it can be called with `to` arguments.
11
- # If a wrapper is applied, warn the application with `name`.
12
- #
13
- # If `last`, then use the last arguments to call the function.
14
- def wrap_arity(callable, from:, to:, name:, last: false)
15
- arity = get_arity(callable)
16
- if arity == to || arity < 0
17
- # It already matches, return it as is
18
- callable
19
- elsif arity == from
20
- # It has the old arity, so wrap it with an arity converter
21
- message ="#{name} with #{from} arguments is deprecated, it now accepts #{to} arguments, see:"
22
- backtrace = caller(0, 20)
23
- # Find the first line in the trace that isn't library internals:
24
- user_line = backtrace.find {|l| l !~ /lib\/graphql/ }
25
- GraphQL::Deprecation.warn(message + "\n" + user_line + "\n")
26
- wrapper = last ? LastArgumentsWrapper : FirstArgumentsWrapper
27
- wrapper.new(callable, from)
28
- else
29
- raise "Can't wrap #{callable} (arity: #{arity}) to have arity #{to}"
30
- end
31
- end
32
-
33
- def get_arity(callable)
34
- case callable
35
- when Method, Proc
36
- callable.arity
37
- else
38
- callable.method(:call).arity
39
- end
40
- end
41
-
42
- class FirstArgumentsWrapper
43
- def initialize(callable, old_arity)
44
- @callable = callable
45
- @old_arity = old_arity
46
- end
47
-
48
- def call(*args)
49
- backwards_compat_args = args.first(@old_arity)
50
- @callable.call(*backwards_compat_args)
51
- end
52
- end
53
-
54
- class LastArgumentsWrapper < FirstArgumentsWrapper
55
- def call(*args)
56
- backwards_compat_args = args.last(@old_arity)
57
- @callable.call(*backwards_compat_args)
58
- end
59
- end
60
- end
61
- end
@@ -1,232 +0,0 @@
1
- # frozen_string_literal: true
2
- require "graphql/relay/type_extensions"
3
-
4
- module GraphQL
5
- # The parent for all type classes.
6
- class BaseType
7
- include GraphQL::Define::NonNullWithBang
8
- include GraphQL::Define::InstanceDefinable
9
- include GraphQL::Relay::TypeExtensions
10
-
11
- deprecated_accepts_definitions :name, :description,
12
- :introspection,
13
- :default_scalar,
14
- :default_relay,
15
- {
16
- connection: GraphQL::Define::AssignConnection,
17
- global_id_field: GraphQL::Define::AssignGlobalIdField,
18
- }
19
-
20
- ensure_defined(:graphql_name, :name, :description, :introspection?, :default_scalar?)
21
-
22
- attr_accessor :ast_node
23
-
24
- def initialize
25
- @introspection = false
26
- @default_scalar = false
27
- @default_relay = false
28
- end
29
-
30
- def initialize_copy(other)
31
- super
32
- # Reset these derived defaults
33
- @connection_type = nil
34
- @edge_type = nil
35
- end
36
-
37
- # @return [String] the name of this type, must be unique within a Schema
38
- attr_reader :name
39
- # Future-compatible alias
40
- # @see {GraphQL::SchemaMember}
41
- alias :graphql_name :name
42
- # Future-compatible alias
43
- # @see {GraphQL::SchemaMember}
44
- def graphql_definition(silence_deprecation_warning: false)
45
- itself
46
- end
47
-
48
- def type_class
49
- metadata[:type_class]
50
- end
51
-
52
- def name=(name)
53
- GraphQL::NameValidator.validate!(name)
54
- @name = name
55
- end
56
-
57
- # @return [String, nil] a description for this type
58
- attr_accessor :description
59
-
60
- # @return [Boolean] Is this type a predefined introspection type?
61
- def introspection?
62
- @introspection
63
- end
64
-
65
- # @return [Boolean] Is this type a built-in scalar type? (eg, `String`, `Int`)
66
- def default_scalar?
67
- @default_scalar
68
- end
69
-
70
- # @return [Boolean] Is this type a built-in Relay type? (`Node`, `PageInfo`)
71
- def default_relay?
72
- @default_relay
73
- end
74
-
75
- # @api private
76
- attr_writer :introspection, :default_scalar, :default_relay
77
-
78
- # @param other [GraphQL::BaseType] compare to this object
79
- # @return [Boolean] are these types equivalent? (incl. non-null, list)
80
- # @see {ModifiesAnotherType#==} for override on List & NonNull types
81
- def ==(other)
82
- other.is_a?(GraphQL::BaseType) && self.name == other.name
83
- end
84
-
85
- # If this type is modifying an underlying type,
86
- # return the underlying type. (Otherwise, return `self`.)
87
- def unwrap
88
- self
89
- end
90
-
91
- # @return [GraphQL::NonNullType] a non-null version of this type
92
- def to_non_null_type
93
- GraphQL::NonNullType.new(of_type: self)
94
- end
95
-
96
- # @return [GraphQL::ListType] a list version of this type
97
- def to_list_type
98
- GraphQL::ListType.new(of_type: self)
99
- end
100
-
101
- module ModifiesAnotherType
102
- def unwrap
103
- self.of_type.unwrap
104
- end
105
-
106
- def ==(other)
107
- other.is_a?(ModifiesAnotherType) && other.of_type == of_type
108
- end
109
- end
110
-
111
- # Find out which possible type to use for `value`.
112
- # Returns self if there are no possible types (ie, not Union or Interface)
113
- def resolve_type(value, ctx)
114
- self
115
- end
116
-
117
- # Print the human-readable name of this type using the query-string naming pattern
118
- def to_s
119
- name
120
- end
121
-
122
- alias :inspect :to_s
123
- alias :to_type_signature :to_s
124
-
125
- def valid_isolated_input?(value)
126
- valid_input?(value, GraphQL::Query::NullContext)
127
- end
128
-
129
- def validate_isolated_input(value)
130
- validate_input(value, GraphQL::Query::NullContext)
131
- end
132
-
133
- def coerce_isolated_input(value)
134
- coerce_input(value, GraphQL::Query::NullContext)
135
- end
136
-
137
- def coerce_isolated_result(value)
138
- coerce_result(value, GraphQL::Query::NullContext)
139
- end
140
-
141
- def valid_input?(value, ctx = nil)
142
- if ctx.nil?
143
- warn_deprecated_coerce("valid_isolated_input?")
144
- ctx = GraphQL::Query::NullContext
145
- end
146
-
147
- validate_input(value, ctx).valid?
148
- end
149
-
150
- def validate_input(value, ctx = nil)
151
- if ctx.nil?
152
- warn_deprecated_coerce("validate_isolated_input")
153
- ctx = GraphQL::Query::NullContext
154
- end
155
-
156
- if value.nil?
157
- GraphQL::Query::InputValidationResult.new
158
- else
159
- validate_non_null_input(value, ctx)
160
- end
161
- end
162
-
163
- def coerce_input(value, ctx = nil)
164
- if value.nil?
165
- nil
166
- else
167
- if ctx.nil?
168
- warn_deprecated_coerce("coerce_isolated_input")
169
- ctx = GraphQL::Query::NullContext
170
- end
171
- coerce_non_null_input(value, ctx)
172
- end
173
- end
174
-
175
- def coerce_result(value, ctx)
176
- raise GraphQL::RequiredImplementationMissingError
177
- end
178
-
179
- # Types with fields may override this
180
- # @param name [String] field name to lookup for this type
181
- # @return [GraphQL::Field, nil]
182
- def get_field(name)
183
- nil
184
- end
185
-
186
- # During schema definition, types can be defined inside procs or as strings.
187
- # This function converts it to a type instance
188
- # @return [GraphQL::BaseType]
189
- def self.resolve_related_type(type_arg)
190
- case type_arg
191
- when Proc
192
- # lazy-eval it, then try again
193
- resolve_related_type(type_arg.call)
194
- when String
195
- # Get a constant by this name
196
- resolve_related_type(Object.const_get(type_arg))
197
- else
198
- if type_arg.respond_to?(:graphql_definition)
199
- type_arg.graphql_definition(silence_deprecation_warning: true)
200
- else
201
- type_arg
202
- end
203
- end
204
- end
205
-
206
- # Return a GraphQL string for the type definition
207
- # @param schema [GraphQL::Schema]
208
- # @param printer [GraphQL::Schema::Printer]
209
- # @see {GraphQL::Schema::Printer#initialize for additional options}
210
- # @return [String] type definition
211
- def to_definition(schema, printer: nil, **args)
212
- printer ||= GraphQL::Schema::Printer.new(schema, **args)
213
- printer.print_type(self)
214
- end
215
-
216
- # Returns true if this is a non-nullable type. A nullable list of non-nullables is considered nullable.
217
- def non_null?
218
- false
219
- end
220
-
221
- # Returns true if this is a list type. A non-nullable list is considered a list.
222
- def list?
223
- false
224
- end
225
-
226
- private
227
-
228
- def warn_deprecated_coerce(alt_method_name)
229
- GraphQL::Deprecation.warn("Coercing without a context is deprecated; use `#{alt_method_name}` if you don't want context-awareness")
230
- end
231
- end
232
- end
@@ -1,2 +0,0 @@
1
- # frozen_string_literal: true
2
- GraphQL::BOOLEAN_TYPE = GraphQL::Types::Boolean.graphql_definition(silence_deprecation_warning: true)