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,91 +0,0 @@
1
- # frozen_string_literal: true
2
- module GraphQL
3
- module Execution
4
- class Lazy
5
- # Helpers for dealing with data structures containing {Lazy} instances
6
- # @api private
7
- module Resolve
8
- # Mutate `value`, replacing {Lazy} instances in place with their resolved values
9
- # @return [void]
10
-
11
- # This object can be passed like an array, but it doesn't allocate an
12
- # array until it's used.
13
- #
14
- # There's one crucial difference: you have to _capture_ the result
15
- # of `#<<`. (This _works_ with arrays but isn't required, since it has a side-effect.)
16
- # @api private
17
- module NullAccumulator
18
- def self.<<(item)
19
- [item]
20
- end
21
-
22
- def self.empty?
23
- true
24
- end
25
- end
26
-
27
- def self.resolve(value)
28
- lazies = resolve_in_place(value)
29
- deep_sync(lazies)
30
- end
31
-
32
- def self.resolve_in_place(value)
33
- acc = each_lazy(NullAccumulator, value)
34
-
35
- if acc.empty?
36
- Lazy::NullResult
37
- else
38
- Lazy.new {
39
- acc.each_with_index { |ctx, idx|
40
- acc[idx] = ctx.value.value
41
- }
42
- resolve_in_place(acc)
43
- }
44
- end
45
- end
46
-
47
- # If `value` is a collection,
48
- # add any {Lazy} instances in the collection
49
- # to `acc`
50
- # @return [void]
51
- def self.each_lazy(acc, value)
52
- case value
53
- when Hash
54
- value.each do |key, field_result|
55
- acc = each_lazy(acc, field_result)
56
- end
57
- when Array
58
- value.each do |field_result|
59
- acc = each_lazy(acc, field_result)
60
- end
61
- when Query::Context::SharedMethods
62
- field_value = value.value
63
- case field_value
64
- when Lazy
65
- acc = acc << value
66
- when Enumerable # shortcut for Hash & Array
67
- acc = each_lazy(acc, field_value)
68
- end
69
- end
70
-
71
- acc
72
- end
73
-
74
- # Traverse `val`, triggering resolution for each {Lazy}.
75
- # These {Lazy}s are expected to mutate their owner data structures
76
- # during resolution! (They're created with the `.then` calls in `resolve_in_place`).
77
- # @return [void]
78
- def self.deep_sync(val)
79
- case val
80
- when Lazy
81
- deep_sync(val.value)
82
- when Array
83
- val.each { |v| deep_sync(v.value) }
84
- when Hash
85
- val.each { |k, v| deep_sync(v.value) }
86
- end
87
- end
88
- end
89
- end
90
- end
91
- end
@@ -1,50 +0,0 @@
1
- # frozen_string_literal: true
2
- module GraphQL
3
- module Execution
4
- # @api private
5
- module Typecast
6
- # @return [Boolean]
7
- def self.subtype?(parent_type, child_type)
8
- if parent_type == child_type
9
- # Equivalent types are subtypes
10
- true
11
- elsif child_type.is_a?(GraphQL::NonNullType)
12
- # A non-null type is a subtype of a nullable type
13
- # if its inner type is a subtype of that type
14
- if parent_type.is_a?(GraphQL::NonNullType)
15
- subtype?(parent_type.of_type, child_type.of_type)
16
- else
17
- subtype?(parent_type, child_type.of_type)
18
- end
19
- else
20
- case parent_type
21
- when GraphQL::InterfaceType
22
- # A type is a subtype of an interface
23
- # if it implements that interface
24
- case child_type
25
- when GraphQL::ObjectType
26
- child_type.interfaces.include?(parent_type)
27
- else
28
- false
29
- end
30
- when GraphQL::UnionType
31
- # A type is a subtype of that union
32
- # if the union includes that type
33
- parent_type.possible_types.include?(child_type)
34
- when GraphQL::ListType
35
- # A list type is a subtype of another list type
36
- # if its inner type is a subtype of the other inner type
37
- case child_type
38
- when GraphQL::ListType
39
- subtype?(parent_type.of_type, child_type.of_type)
40
- else
41
- false
42
- end
43
- else
44
- false
45
- end
46
- end
47
- end
48
- end
49
- end
50
- end
@@ -1,59 +0,0 @@
1
- # frozen_string_literal: true
2
- module GraphQL
3
- class Field
4
- # Create resolve procs ahead of time based on a {GraphQL::Field}'s `name`, `property`, and `hash_key` configuration.
5
- module Resolve
6
- module_function
7
-
8
- # @param field [GraphQL::Field] A field that needs a resolve proc
9
- # @return [Proc] A resolver for this field, based on its config
10
- def create_proc(field)
11
- if field.property
12
- MethodResolve.new(field)
13
- elsif !field.hash_key.nil?
14
- HashKeyResolve.new(field.hash_key)
15
- else
16
- NameResolve.new(field)
17
- end
18
- end
19
-
20
- # These only require `obj` as input
21
- class BuiltInResolve
22
- end
23
-
24
- # Resolve the field by `public_send`ing `@method_name`
25
- class MethodResolve < BuiltInResolve
26
- def initialize(field)
27
- @method_name = field.property.to_sym
28
- end
29
-
30
- def call(obj, args, ctx)
31
- obj.public_send(@method_name)
32
- end
33
- end
34
-
35
- # Resolve the field by looking up `@hash_key` with `#[]`
36
- class HashKeyResolve < BuiltInResolve
37
- def initialize(hash_key)
38
- @hash_key = hash_key
39
- end
40
-
41
- def call(obj, args, ctx)
42
- obj[@hash_key]
43
- end
44
- end
45
-
46
- # Call the field's name at query-time since
47
- # it might have changed
48
- class NameResolve < BuiltInResolve
49
- def initialize(field)
50
- @field = field
51
- end
52
-
53
- def call(obj, args, ctx)
54
- obj.public_send(@field.name)
55
- end
56
- end
57
- end
58
- end
59
- end
data/lib/graphql/field.rb DELETED
@@ -1,226 +0,0 @@
1
- # frozen_string_literal: true
2
- require "graphql/field/resolve"
3
-
4
- module GraphQL
5
- # @api deprecated
6
- class Field
7
- include GraphQL::Define::InstanceDefinable
8
- deprecated_accepts_definitions :name, :description, :deprecation_reason,
9
- :resolve, :lazy_resolve,
10
- :type, :arguments,
11
- :property, :hash_key, :complexity,
12
- :mutation, :function,
13
- :edge_class,
14
- :relay_node_field,
15
- :relay_nodes_field,
16
- :subscription_scope,
17
- :trace,
18
- :introspection,
19
- argument: GraphQL::Define::AssignArgument
20
-
21
- ensure_defined(
22
- :name, :deprecation_reason, :description, :description=, :property, :hash_key,
23
- :mutation, :arguments, :complexity, :function,
24
- :resolve, :resolve=, :lazy_resolve, :lazy_resolve=, :lazy_resolve_proc, :resolve_proc,
25
- :type, :type=, :name=, :property=, :hash_key=,
26
- :relay_node_field, :relay_nodes_field, :edges?, :edge_class, :subscription_scope,
27
- :introspection?
28
- )
29
-
30
- # @return [Boolean] True if this is the Relay find-by-id field
31
- attr_accessor :relay_node_field
32
-
33
- # @return [Boolean] True if this is the Relay find-by-ids field
34
- attr_accessor :relay_nodes_field
35
-
36
- # @return [<#call(obj, args, ctx)>] A proc-like object which can be called to return the field's value
37
- attr_reader :resolve_proc
38
-
39
- # @return [<#call(obj, args, ctx)>] A proc-like object which can be called trigger a lazy resolution
40
- attr_reader :lazy_resolve_proc
41
-
42
- # @return [String] The name of this field on its {GraphQL::ObjectType} (or {GraphQL::InterfaceType})
43
- attr_reader :name
44
- alias :graphql_name :name
45
-
46
- # @return [String, nil] The client-facing description of this field
47
- attr_accessor :description
48
-
49
- # @return [String, nil] The client-facing reason why this field is deprecated (if present, the field is deprecated)
50
- attr_accessor :deprecation_reason
51
-
52
- # @return [Hash<String => GraphQL::Argument>] Map String argument names to their {GraphQL::Argument} implementations
53
- attr_accessor :arguments
54
-
55
- # @return [GraphQL::Relay::Mutation, nil] The mutation this field was derived from, if it was derived from a mutation
56
- attr_accessor :mutation
57
-
58
- # @return [Numeric, Proc] The complexity for this field (default: 1), as a constant or a proc like `->(query_ctx, args, child_complexity) { } # Numeric`
59
- attr_accessor :complexity
60
-
61
- # @return [Symbol, nil] The method to call on `obj` to return this field (overrides {#name} if present)
62
- attr_reader :property
63
-
64
- # @return [Object, nil] The key to access with `obj.[]` to resolve this field (overrides {#name} if present)
65
- attr_reader :hash_key
66
-
67
- # @return [Object, GraphQL::Function] The function used to derive this field
68
- attr_accessor :function
69
-
70
- attr_accessor :arguments_class
71
-
72
- attr_writer :connection
73
- attr_writer :introspection
74
-
75
- # @return [nil, String] Prefix for subscription names from this field
76
- attr_accessor :subscription_scope
77
-
78
- # @return [Boolean] True if this field should be traced. By default, fields are only traced if they are not a ScalarType or EnumType.
79
- attr_accessor :trace
80
-
81
- attr_accessor :ast_node
82
-
83
- # Future-compatible alias
84
- # @see {GraphQL::SchemaMember}
85
- alias :graphql_definition :itself
86
-
87
- # @return [Boolean]
88
- def connection?
89
- @connection
90
- end
91
-
92
- # @return [nil, Class]
93
- # @api private
94
- attr_accessor :edge_class
95
-
96
- # @return [Boolean]
97
- def edges?
98
- !!@edge_class
99
- end
100
-
101
- # @return [nil, Integer]
102
- attr_accessor :connection_max_page_size
103
-
104
- def initialize
105
- @complexity = 1
106
- @arguments = {}
107
- @resolve_proc = build_default_resolver
108
- @lazy_resolve_proc = DefaultLazyResolve
109
- @relay_node_field = false
110
- @connection = false
111
- @connection_max_page_size = nil
112
- @edge_class = nil
113
- @trace = nil
114
- @introspection = false
115
- end
116
-
117
- def initialize_copy(other)
118
- ensure_defined
119
- super
120
- @arguments = other.arguments.dup
121
- end
122
-
123
- # @return [Boolean] Is this field a predefined introspection field?
124
- def introspection?
125
- @introspection
126
- end
127
-
128
- # Get a value for this field
129
- # @example resolving a field value
130
- # field.resolve(obj, args, ctx)
131
- #
132
- # @param object [Object] The object this field belongs to
133
- # @param arguments [Hash] Arguments declared in the query
134
- # @param context [GraphQL::Query::Context]
135
- def resolve(object, arguments, context)
136
- resolve_proc.call(object, arguments, context)
137
- end
138
-
139
- # Provide a new callable for this field's resolve function. If `nil`,
140
- # a new resolve proc will be build based on its {#name}, {#property} or {#hash_key}.
141
- # @param new_resolve_proc [<#call(obj, args, ctx)>, nil]
142
- def resolve=(new_resolve_proc)
143
- @resolve_proc = new_resolve_proc || build_default_resolver
144
- end
145
-
146
- def type=(new_return_type)
147
- @clean_type = nil
148
- @dirty_type = new_return_type
149
- end
150
-
151
- # Get the return type for this field.
152
- def type
153
- @clean_type ||= GraphQL::BaseType.resolve_related_type(@dirty_type)
154
- end
155
-
156
- def name=(new_name)
157
- old_name = defined?(@name) ? @name : nil
158
- @name = new_name
159
-
160
- if old_name != new_name && @resolve_proc.is_a?(Field::Resolve::NameResolve)
161
- # Since the NameResolve would use the old field name,
162
- # reset resolve proc when the name has changed
163
- self.resolve = nil
164
- end
165
- end
166
-
167
- # @param new_property [Symbol] A method to call to resolve this field. Overrides the existing resolve proc.
168
- def property=(new_property)
169
- @property = new_property
170
- self.resolve = nil # reset resolve proc
171
- end
172
-
173
- # @param new_hash_key [Symbol] A key to access with `#[key]` to resolve this field. Overrides the existing resolve proc.
174
- def hash_key=(new_hash_key)
175
- @hash_key = new_hash_key
176
- self.resolve = nil # reset resolve proc
177
- end
178
-
179
- def to_s
180
- "<Field name:#{name || "not-named"} desc:#{description} resolve:#{resolve_proc}>"
181
- end
182
-
183
- # If {#resolve} returned an object which should be handled lazily,
184
- # this method will be called later to force the object to return its value.
185
- # @param obj [Object] The {#resolve}-provided object, registered with {Schema#lazy_resolve}
186
- # @param args [GraphQL::Query::Arguments] Arguments to this field
187
- # @param ctx [GraphQL::Query::Context] Context for this field
188
- # @return [Object] The result of calling the registered method on `obj`
189
- def lazy_resolve(obj, args, ctx)
190
- @lazy_resolve_proc.call(obj, args, ctx)
191
- end
192
-
193
- # Assign a new resolve proc to this field. Used for {#lazy_resolve}
194
- def lazy_resolve=(new_lazy_resolve_proc)
195
- @lazy_resolve_proc = new_lazy_resolve_proc
196
- end
197
-
198
- # Prepare a lazy value for this field. It may be `then`-ed and resolved later.
199
- # @return [GraphQL::Execution::Lazy] A lazy wrapper around `obj` and its registered method name
200
- def prepare_lazy(obj, args, ctx)
201
- GraphQL::Execution::Lazy.new {
202
- lazy_resolve(obj, args, ctx)
203
- }
204
- end
205
-
206
- def type_class
207
- metadata[:type_class]
208
- end
209
-
210
- def get_argument(argument_name)
211
- arguments[argument_name]
212
- end
213
-
214
- private
215
-
216
- def build_default_resolver
217
- GraphQL::Field::Resolve.create_proc(self)
218
- end
219
-
220
- module DefaultLazyResolve
221
- def self.call(obj, args, ctx)
222
- ctx.schema.sync_lazy(obj)
223
- end
224
- end
225
- end
226
- end
@@ -1,2 +0,0 @@
1
- # frozen_string_literal: true
2
- GraphQL::FLOAT_TYPE = GraphQL::Types::Float.graphql_definition(silence_deprecation_warning: true)
@@ -1,128 +0,0 @@
1
- # frozen_string_literal: true
2
- module GraphQL
3
- # @api deprecated
4
- class Function
5
- def self.inherited(subclass)
6
- GraphQL::Deprecation.warn "GraphQL::Function (used for #{subclass}) will be removed from GraphQL-Ruby 2.0, please upgrade to resolvers: https://graphql-ruby.org/fields/resolvers.html"
7
- end
8
-
9
- # @return [Hash<String => GraphQL::Argument>] Arguments, keyed by name
10
- def arguments
11
- self.class.arguments
12
- end
13
-
14
- # @return [GraphQL::BaseType] Return type
15
- def type
16
- self.class.type
17
- end
18
-
19
- # @return [Object] This function's resolver
20
- def call(obj, args, ctx)
21
- raise GraphQL::RequiredImplementationMissingError
22
- end
23
-
24
- # @return [String, nil]
25
- def description
26
- self.class.description
27
- end
28
-
29
- # @return [String, nil]
30
- def deprecation_reason
31
- self.class.deprecation_reason
32
- end
33
-
34
- # @return [Integer, Proc]
35
- def complexity
36
- self.class.complexity || 1
37
- end
38
-
39
- class << self
40
- # Define an argument for this function & its subclasses
41
- # @see {GraphQL::Field} same arguments as the `argument` definition helper
42
- # @return [void]
43
- def argument(*args, **kwargs, &block)
44
- argument = GraphQL::Argument.from_dsl(*args, **kwargs, &block)
45
- own_arguments[argument.name] = argument
46
- nil
47
- end
48
-
49
- # @return [Hash<String => GraphQL::Argument>] Arguments for this function class, including inherited arguments
50
- def arguments
51
- if parent_function?
52
- own_arguments.merge(superclass.arguments)
53
- else
54
- own_arguments.dup
55
- end
56
- end
57
-
58
- # Provides shorthand access to GraphQL's built-in types
59
- def types
60
- GraphQL::Define::TypeDefiner.instance
61
- end
62
-
63
- # Get or set the return type for this function class & descendants
64
- # @return [GraphQL::BaseType]
65
- def type(premade_type = nil, &block)
66
- if block_given?
67
- @type = GraphQL::ObjectType.define(&block)
68
- elsif premade_type
69
- @type = premade_type
70
- elsif parent_function?
71
- @type || superclass.type
72
- else
73
- @type
74
- end
75
- end
76
-
77
- def build_field(function)
78
- GraphQL::Field.define(
79
- arguments: function.arguments,
80
- complexity: function.complexity,
81
- type: function.type,
82
- resolve: function,
83
- description: function.description,
84
- function: function,
85
- deprecation_reason: function.deprecation_reason,
86
- )
87
- end
88
-
89
- # Class-level reader/writer which is inherited
90
- # @api private
91
- def self.inherited_value(name)
92
- self.class_eval <<-RUBY
93
- def #{name}(new_value = nil)
94
- if new_value
95
- @#{name} = new_value
96
- elsif parent_function?
97
- @#{name} || superclass.#{name}
98
- else
99
- @#{name}
100
- end
101
- end
102
- RUBY
103
- end
104
-
105
- # @!method description(new_value = nil)
106
- # Get or set this class's description
107
- inherited_value(:description)
108
- # @!method deprecation_reason(new_value = nil)
109
- # Get or set this class's deprecation_reason
110
- inherited_value(:deprecation_reason)
111
- # @!method complexity(new_value = nil)
112
- # Get or set this class's complexity
113
- inherited_value(:complexity)
114
-
115
- private
116
-
117
- # Does this function inherit from another function?
118
- def parent_function?
119
- superclass <= GraphQL::Function
120
- end
121
-
122
- # Arguments defined on this class (not superclasses)
123
- def own_arguments
124
- @own_arguments ||= {}
125
- end
126
- end
127
- end
128
- end
@@ -1,2 +0,0 @@
1
- # frozen_string_literal: true
2
- GraphQL::ID_TYPE = GraphQL::Types::ID.graphql_definition(silence_deprecation_warning: true)
@@ -1,138 +0,0 @@
1
- # frozen_string_literal: true
2
- module GraphQL
3
- # @api deprecated
4
- class InputObjectType < GraphQL::BaseType
5
- extend Define::InstanceDefinable::DeprecatedDefine
6
-
7
- deprecated_accepts_definitions(
8
- :arguments, :mutation,
9
- input_field: GraphQL::Define::AssignArgument,
10
- argument: GraphQL::Define::AssignArgument
11
- )
12
-
13
- attr_accessor :mutation, :arguments, :arguments_class
14
- ensure_defined(:mutation, :arguments, :input_fields)
15
- alias :input_fields :arguments
16
-
17
- # @!attribute mutation
18
- # @return [GraphQL::Relay::Mutation, nil] The mutation this field was derived from, if it was derived from a mutation
19
-
20
- # @!attribute arguments
21
- # @return [Hash<String => GraphQL::Argument>] Map String argument names to their {GraphQL::Argument} implementations
22
-
23
-
24
- def initialize
25
- super
26
- @arguments = {}
27
- end
28
-
29
- def initialize_copy(other)
30
- super
31
- @arguments = other.arguments.dup
32
- end
33
-
34
- def kind
35
- GraphQL::TypeKinds::INPUT_OBJECT
36
- end
37
-
38
- def coerce_result(value, ctx = nil)
39
- if ctx.nil?
40
- warn_deprecated_coerce("coerce_isolated_result")
41
- ctx = GraphQL::Query::NullContext
42
- end
43
-
44
- # Allow the application to provide values as :symbols, and convert them to the strings
45
- value = value.reduce({}) { |memo, (k, v)| memo[k.to_s] = v; memo }
46
-
47
- result = {}
48
-
49
- arguments.each do |input_key, input_field_defn|
50
- input_value = value[input_key]
51
- if value.key?(input_key)
52
- result[input_key] = if input_value.nil?
53
- nil
54
- else
55
- input_field_defn.type.coerce_result(input_value, ctx)
56
- end
57
- end
58
- end
59
-
60
- result
61
- end
62
-
63
- def get_argument(argument_name)
64
- arguments[argument_name]
65
- end
66
-
67
- private
68
-
69
- def coerce_non_null_input(value, ctx)
70
- input_values = {}
71
- defaults_used = Set.new
72
-
73
- arguments.each do |input_key, input_field_defn|
74
- field_value = value[input_key]
75
-
76
- if value.key?(input_key)
77
- coerced_value = input_field_defn.type.coerce_input(field_value, ctx)
78
- input_values[input_key] = input_field_defn.prepare(coerced_value, ctx)
79
- elsif input_field_defn.default_value?
80
- coerced_value = input_field_defn.type.coerce_input(input_field_defn.default_value, ctx)
81
- input_values[input_key] = coerced_value
82
- defaults_used << input_key
83
- end
84
- end
85
-
86
- result = arguments_class.new(input_values, context: ctx, defaults_used: defaults_used)
87
- result.prepare
88
- end
89
-
90
- # @api private
91
- INVALID_OBJECT_MESSAGE = "Expected %{object} to be a key, value object responding to `to_h` or `to_unsafe_h`."
92
-
93
- def validate_non_null_input(input, ctx)
94
- warden = ctx.warden
95
- result = GraphQL::Query::InputValidationResult.new
96
-
97
- if input.is_a?(Array)
98
- result.add_problem(INVALID_OBJECT_MESSAGE % { object: JSON.generate(input, quirks_mode: true) })
99
- return result
100
- end
101
-
102
- # We're not actually _using_ the coerced result, we're just
103
- # using these methods to make sure that the object will
104
- # behave like a hash below, when we call `each` on it.
105
- begin
106
- input.to_h
107
- rescue
108
- begin
109
- # Handle ActionController::Parameters:
110
- input.to_unsafe_h
111
- rescue
112
- # We're not sure it'll act like a hash, so reject it:
113
- result.add_problem(INVALID_OBJECT_MESSAGE % { object: JSON.generate(input, quirks_mode: true) })
114
- return result
115
- end
116
- end
117
-
118
- visible_arguments_map = warden.arguments(self).reduce({}) { |m, f| m[f.name] = f; m}
119
-
120
- # Items in the input that are unexpected
121
- input.each do |name, value|
122
- if visible_arguments_map[name].nil?
123
- result.add_problem("Field is not defined on #{self.graphql_name}", [name])
124
- end
125
- end
126
-
127
- # Items in the input that are expected, but have invalid values
128
- visible_arguments_map.map do |name, field|
129
- field_result = field.type.validate_input(input[name], ctx)
130
- if !field_result.valid?
131
- result.merge_result!(name, field_result)
132
- end
133
- end
134
-
135
- result
136
- end
137
- end
138
- end
@@ -1,2 +0,0 @@
1
- # frozen_string_literal: true
2
- GraphQL::INT_TYPE = GraphQL::Types::Int.graphql_definition(silence_deprecation_warning: true)