graphql 1.13.6 → 2.0.0

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 (216) hide show
  1. checksums.yaml +4 -4
  2. data/lib/generators/graphql/core.rb +0 -7
  3. data/lib/generators/graphql/enum_generator.rb +4 -10
  4. data/lib/generators/graphql/field_extractor.rb +31 -0
  5. data/lib/generators/graphql/input_generator.rb +50 -0
  6. data/lib/generators/graphql/install/mutation_root_generator.rb +34 -0
  7. data/lib/generators/graphql/{templates → install/templates}/base_mutation.erb +0 -0
  8. data/lib/generators/graphql/{templates → install/templates}/mutation_type.erb +0 -0
  9. data/lib/generators/graphql/install_generator.rb +1 -1
  10. data/lib/generators/graphql/interface_generator.rb +7 -7
  11. data/lib/generators/graphql/mutation_create_generator.rb +22 -0
  12. data/lib/generators/graphql/mutation_delete_generator.rb +22 -0
  13. data/lib/generators/graphql/mutation_generator.rb +5 -30
  14. data/lib/generators/graphql/mutation_update_generator.rb +22 -0
  15. data/lib/generators/graphql/object_generator.rb +8 -37
  16. data/lib/generators/graphql/orm_mutations_base.rb +40 -0
  17. data/lib/generators/graphql/scalar_generator.rb +4 -2
  18. data/lib/generators/graphql/templates/enum.erb +5 -1
  19. data/lib/generators/graphql/templates/input.erb +9 -0
  20. data/lib/generators/graphql/templates/interface.erb +4 -2
  21. data/lib/generators/graphql/templates/mutation.erb +1 -1
  22. data/lib/generators/graphql/templates/mutation_create.erb +20 -0
  23. data/lib/generators/graphql/templates/mutation_delete.erb +20 -0
  24. data/lib/generators/graphql/templates/mutation_update.erb +21 -0
  25. data/lib/generators/graphql/templates/object.erb +4 -2
  26. data/lib/generators/graphql/templates/scalar.erb +3 -1
  27. data/lib/generators/graphql/templates/union.erb +4 -2
  28. data/lib/generators/graphql/type_generator.rb +46 -9
  29. data/lib/generators/graphql/union_generator.rb +5 -5
  30. data/lib/graphql/analysis/ast/query_complexity.rb +1 -1
  31. data/lib/graphql/analysis/ast/query_depth.rb +0 -1
  32. data/lib/graphql/analysis/ast/visitor.rb +3 -2
  33. data/lib/graphql/analysis/ast.rb +0 -10
  34. data/lib/graphql/analysis.rb +0 -7
  35. data/lib/graphql/backtrace/table.rb +0 -18
  36. data/lib/graphql/backtrace/tracer.rb +1 -2
  37. data/lib/graphql/backtrace.rb +2 -8
  38. data/lib/graphql/dataloader/source.rb +2 -2
  39. data/lib/graphql/dig.rb +1 -1
  40. data/lib/graphql/execution/errors.rb +1 -9
  41. data/lib/graphql/execution/interpreter/runtime.rb +2 -9
  42. data/lib/graphql/execution/interpreter.rb +0 -22
  43. data/lib/graphql/execution/lazy.rb +1 -1
  44. data/lib/graphql/execution/lookahead.rb +6 -13
  45. data/lib/graphql/execution/multiplex.rb +50 -107
  46. data/lib/graphql/execution.rb +11 -3
  47. data/lib/graphql/introspection/dynamic_fields.rb +3 -8
  48. data/lib/graphql/introspection/entry_points.rb +2 -15
  49. data/lib/graphql/introspection.rb +4 -4
  50. data/lib/graphql/language/document_from_schema_definition.rb +0 -17
  51. data/lib/graphql/pagination/connections.rb +2 -28
  52. data/lib/graphql/query/context.rb +1 -185
  53. data/lib/graphql/query/literal_input.rb +8 -13
  54. data/lib/graphql/query/validation_pipeline.rb +8 -37
  55. data/lib/graphql/query/variables.rb +22 -18
  56. data/lib/graphql/query.rb +5 -35
  57. data/lib/graphql/railtie.rb +0 -104
  58. data/lib/graphql/relay.rb +0 -15
  59. data/lib/graphql/rubocop/graphql/default_required_true.rb +4 -4
  60. data/lib/graphql/schema/addition.rb +1 -8
  61. data/lib/graphql/schema/argument.rb +18 -25
  62. data/lib/graphql/schema/build_from_definition.rb +0 -1
  63. data/lib/graphql/schema/directive.rb +4 -21
  64. data/lib/graphql/schema/enum.rb +1 -18
  65. data/lib/graphql/schema/enum_value.rb +0 -22
  66. data/lib/graphql/schema/field.rb +22 -194
  67. data/lib/graphql/schema/input_object.rb +10 -57
  68. data/lib/graphql/schema/interface.rb +0 -25
  69. data/lib/graphql/schema/introspection_system.rb +3 -8
  70. data/lib/graphql/schema/late_bound_type.rb +2 -2
  71. data/lib/graphql/schema/list.rb +0 -6
  72. data/lib/graphql/schema/loader.rb +0 -1
  73. data/lib/graphql/schema/member/base_dsl_methods.rb +0 -5
  74. data/lib/graphql/schema/member/build_type.rb +4 -6
  75. data/lib/graphql/schema/member/has_arguments.rb +14 -18
  76. data/lib/graphql/schema/member/has_fields.rb +2 -2
  77. data/lib/graphql/schema/member/has_interfaces.rb +0 -2
  78. data/lib/graphql/schema/member.rb +0 -6
  79. data/lib/graphql/schema/mutation.rb +0 -9
  80. data/lib/graphql/schema/non_null.rb +1 -7
  81. data/lib/graphql/schema/object.rb +0 -40
  82. data/lib/graphql/schema/relay_classic_mutation.rb +17 -28
  83. data/lib/graphql/schema/scalar.rb +0 -15
  84. data/lib/graphql/schema/union.rb +0 -16
  85. data/lib/graphql/schema/warden.rb +1 -1
  86. data/lib/graphql/schema/wrapper.rb +0 -5
  87. data/lib/graphql/schema.rb +107 -949
  88. data/lib/graphql/static_validation/base_visitor.rb +4 -21
  89. data/lib/graphql/static_validation/rules/directives_are_in_valid_locations.rb +12 -12
  90. data/lib/graphql/static_validation/validator.rb +2 -24
  91. data/lib/graphql/static_validation.rb +0 -2
  92. data/lib/graphql/subscriptions/default_subscription_resolve_extension.rb +38 -1
  93. data/lib/graphql/subscriptions/event.rb +1 -1
  94. data/lib/graphql/subscriptions/instrumentation.rb +0 -51
  95. data/lib/graphql/subscriptions.rb +4 -13
  96. data/lib/graphql/tracing/platform_tracing.rb +0 -23
  97. data/lib/graphql/tracing.rb +0 -1
  98. data/lib/graphql/types/iso_8601_date_time.rb +8 -1
  99. data/lib/graphql/types/relay/connection_behaviors.rb +4 -7
  100. data/lib/graphql/types/relay/default_relay.rb +0 -10
  101. data/lib/graphql/types/relay/node_behaviors.rb +5 -1
  102. data/lib/graphql/types/relay.rb +0 -2
  103. data/lib/graphql/version.rb +1 -1
  104. data/lib/graphql.rb +12 -65
  105. metadata +15 -129
  106. data/lib/graphql/analysis/analyze_query.rb +0 -98
  107. data/lib/graphql/analysis/field_usage.rb +0 -45
  108. data/lib/graphql/analysis/max_query_complexity.rb +0 -26
  109. data/lib/graphql/analysis/max_query_depth.rb +0 -26
  110. data/lib/graphql/analysis/query_complexity.rb +0 -88
  111. data/lib/graphql/analysis/query_depth.rb +0 -43
  112. data/lib/graphql/analysis/reducer_state.rb +0 -48
  113. data/lib/graphql/argument.rb +0 -131
  114. data/lib/graphql/authorization.rb +0 -82
  115. data/lib/graphql/backtrace/legacy_tracer.rb +0 -56
  116. data/lib/graphql/backwards_compatibility.rb +0 -61
  117. data/lib/graphql/base_type.rb +0 -232
  118. data/lib/graphql/boolean_type.rb +0 -2
  119. data/lib/graphql/compatibility/execution_specification/counter_schema.rb +0 -53
  120. data/lib/graphql/compatibility/execution_specification/specification_schema.rb +0 -200
  121. data/lib/graphql/compatibility/execution_specification.rb +0 -436
  122. data/lib/graphql/compatibility/lazy_execution_specification/lazy_schema.rb +0 -111
  123. data/lib/graphql/compatibility/lazy_execution_specification.rb +0 -215
  124. data/lib/graphql/compatibility/query_parser_specification/parse_error_specification.rb +0 -87
  125. data/lib/graphql/compatibility/query_parser_specification/query_assertions.rb +0 -79
  126. data/lib/graphql/compatibility/query_parser_specification.rb +0 -266
  127. data/lib/graphql/compatibility/schema_parser_specification.rb +0 -682
  128. data/lib/graphql/compatibility.rb +0 -5
  129. data/lib/graphql/define/assign_argument.rb +0 -12
  130. data/lib/graphql/define/assign_connection.rb +0 -13
  131. data/lib/graphql/define/assign_enum_value.rb +0 -18
  132. data/lib/graphql/define/assign_global_id_field.rb +0 -11
  133. data/lib/graphql/define/assign_mutation_function.rb +0 -34
  134. data/lib/graphql/define/assign_object_field.rb +0 -42
  135. data/lib/graphql/define/defined_object_proxy.rb +0 -53
  136. data/lib/graphql/define/instance_definable.rb +0 -240
  137. data/lib/graphql/define/no_definition_error.rb +0 -7
  138. data/lib/graphql/define/non_null_with_bang.rb +0 -16
  139. data/lib/graphql/define/type_definer.rb +0 -31
  140. data/lib/graphql/define.rb +0 -31
  141. data/lib/graphql/deprecated_dsl.rb +0 -55
  142. data/lib/graphql/directive/deprecated_directive.rb +0 -2
  143. data/lib/graphql/directive/include_directive.rb +0 -2
  144. data/lib/graphql/directive/skip_directive.rb +0 -2
  145. data/lib/graphql/directive.rb +0 -107
  146. data/lib/graphql/enum_type.rb +0 -133
  147. data/lib/graphql/execution/execute.rb +0 -333
  148. data/lib/graphql/execution/flatten.rb +0 -40
  149. data/lib/graphql/execution/typecast.rb +0 -50
  150. data/lib/graphql/field/resolve.rb +0 -59
  151. data/lib/graphql/field.rb +0 -226
  152. data/lib/graphql/float_type.rb +0 -2
  153. data/lib/graphql/function.rb +0 -128
  154. data/lib/graphql/id_type.rb +0 -2
  155. data/lib/graphql/input_object_type.rb +0 -138
  156. data/lib/graphql/int_type.rb +0 -2
  157. data/lib/graphql/interface_type.rb +0 -72
  158. data/lib/graphql/internal_representation/document.rb +0 -27
  159. data/lib/graphql/internal_representation/node.rb +0 -206
  160. data/lib/graphql/internal_representation/print.rb +0 -51
  161. data/lib/graphql/internal_representation/rewrite.rb +0 -184
  162. data/lib/graphql/internal_representation/scope.rb +0 -88
  163. data/lib/graphql/internal_representation/visit.rb +0 -36
  164. data/lib/graphql/internal_representation.rb +0 -7
  165. data/lib/graphql/list_type.rb +0 -80
  166. data/lib/graphql/non_null_type.rb +0 -71
  167. data/lib/graphql/object_type.rb +0 -130
  168. data/lib/graphql/query/arguments.rb +0 -189
  169. data/lib/graphql/query/arguments_cache.rb +0 -24
  170. data/lib/graphql/query/executor.rb +0 -52
  171. data/lib/graphql/query/serial_execution/field_resolution.rb +0 -92
  172. data/lib/graphql/query/serial_execution/operation_resolution.rb +0 -19
  173. data/lib/graphql/query/serial_execution/selection_resolution.rb +0 -23
  174. data/lib/graphql/query/serial_execution/value_resolution.rb +0 -87
  175. data/lib/graphql/query/serial_execution.rb +0 -40
  176. data/lib/graphql/relay/array_connection.rb +0 -83
  177. data/lib/graphql/relay/base_connection.rb +0 -189
  178. data/lib/graphql/relay/connection_instrumentation.rb +0 -54
  179. data/lib/graphql/relay/connection_resolve.rb +0 -43
  180. data/lib/graphql/relay/connection_type.rb +0 -41
  181. data/lib/graphql/relay/edge.rb +0 -27
  182. data/lib/graphql/relay/edge_type.rb +0 -19
  183. data/lib/graphql/relay/edges_instrumentation.rb +0 -39
  184. data/lib/graphql/relay/global_id_resolve.rb +0 -18
  185. data/lib/graphql/relay/mongo_relation_connection.rb +0 -50
  186. data/lib/graphql/relay/mutation/instrumentation.rb +0 -23
  187. data/lib/graphql/relay/mutation/resolve.rb +0 -56
  188. data/lib/graphql/relay/mutation/result.rb +0 -38
  189. data/lib/graphql/relay/mutation.rb +0 -106
  190. data/lib/graphql/relay/node.rb +0 -39
  191. data/lib/graphql/relay/page_info.rb +0 -7
  192. data/lib/graphql/relay/relation_connection.rb +0 -188
  193. data/lib/graphql/relay/type_extensions.rb +0 -32
  194. data/lib/graphql/scalar_type.rb +0 -91
  195. data/lib/graphql/schema/catchall_middleware.rb +0 -35
  196. data/lib/graphql/schema/default_parse_error.rb +0 -10
  197. data/lib/graphql/schema/default_type_error.rb +0 -17
  198. data/lib/graphql/schema/member/accepts_definition.rb +0 -164
  199. data/lib/graphql/schema/member/cached_graphql_definition.rb +0 -58
  200. data/lib/graphql/schema/member/instrumentation.rb +0 -131
  201. data/lib/graphql/schema/middleware_chain.rb +0 -82
  202. data/lib/graphql/schema/possible_types.rb +0 -44
  203. data/lib/graphql/schema/rescue_middleware.rb +0 -60
  204. data/lib/graphql/schema/timeout_middleware.rb +0 -88
  205. data/lib/graphql/schema/traversal.rb +0 -228
  206. data/lib/graphql/schema/validation.rb +0 -313
  207. data/lib/graphql/static_validation/default_visitor.rb +0 -15
  208. data/lib/graphql/static_validation/no_validate_visitor.rb +0 -10
  209. data/lib/graphql/string_type.rb +0 -2
  210. data/lib/graphql/subscriptions/subscription_root.rb +0 -76
  211. data/lib/graphql/tracing/skylight_tracing.rb +0 -70
  212. data/lib/graphql/types/relay/node_field.rb +0 -24
  213. data/lib/graphql/types/relay/nodes_field.rb +0 -43
  214. data/lib/graphql/union_type.rb +0 -115
  215. data/lib/graphql/upgrader/member.rb +0 -937
  216. data/lib/graphql/upgrader/schema.rb +0 -38
@@ -14,11 +14,6 @@ module GraphQL
14
14
  super(document)
15
15
  end
16
16
 
17
- # This will be overwritten by {InternalRepresentation::Rewrite} if it's included
18
- def rewrite_document
19
- nil
20
- end
21
-
22
17
  attr_reader :context
23
18
 
24
19
  # @return [Array<GraphQL::ObjectType>] Types whose scope we've entered
@@ -32,22 +27,13 @@ module GraphQL
32
27
  # Build a class to visit the AST and perform validation,
33
28
  # or use a pre-built class if rules is `ALL_RULES` or empty.
34
29
  # @param rules [Array<Module, Class>]
35
- # @param rewrite [Boolean] if `false`, don't include rewrite
36
30
  # @return [Class] A class for validating `rules` during visitation
37
- def self.including_rules(rules, rewrite: true)
31
+ def self.including_rules(rules)
38
32
  if rules.empty?
39
- if rewrite
40
- NoValidateVisitor
41
- else
42
- # It's not doing _anything?!?_
43
- BaseVisitor
44
- end
33
+ # It's not doing _anything?!?_
34
+ BaseVisitor
45
35
  elsif rules == ALL_RULES
46
- if rewrite
47
- DefaultVisitor
48
- else
49
- InterpreterVisitor
50
- end
36
+ InterpreterVisitor
51
37
  else
52
38
  visitor_class = Class.new(self) do
53
39
  include(GraphQL::StaticValidation::DefinitionDependencies)
@@ -60,9 +46,6 @@ module GraphQL
60
46
  end
61
47
  end
62
48
 
63
- if rewrite
64
- visitor_class.include(GraphQL::InternalRepresentation::Rewrite)
65
- end
66
49
  visitor_class.include(ContextMethods)
67
50
  visitor_class
68
51
  end
@@ -12,20 +12,20 @@ module GraphQL
12
12
  private
13
13
 
14
14
  LOCATION_MESSAGE_NAMES = {
15
- GraphQL::Directive::QUERY => "queries",
16
- GraphQL::Directive::MUTATION => "mutations",
17
- GraphQL::Directive::SUBSCRIPTION => "subscriptions",
18
- GraphQL::Directive::FIELD => "fields",
19
- GraphQL::Directive::FRAGMENT_DEFINITION => "fragment definitions",
20
- GraphQL::Directive::FRAGMENT_SPREAD => "fragment spreads",
21
- GraphQL::Directive::INLINE_FRAGMENT => "inline fragments",
15
+ GraphQL::Schema::Directive::QUERY => "queries",
16
+ GraphQL::Schema::Directive::MUTATION => "mutations",
17
+ GraphQL::Schema::Directive::SUBSCRIPTION => "subscriptions",
18
+ GraphQL::Schema::Directive::FIELD => "fields",
19
+ GraphQL::Schema::Directive::FRAGMENT_DEFINITION => "fragment definitions",
20
+ GraphQL::Schema::Directive::FRAGMENT_SPREAD => "fragment spreads",
21
+ GraphQL::Schema::Directive::INLINE_FRAGMENT => "inline fragments",
22
22
  }
23
23
 
24
24
  SIMPLE_LOCATIONS = {
25
- Nodes::Field => GraphQL::Directive::FIELD,
26
- Nodes::InlineFragment => GraphQL::Directive::INLINE_FRAGMENT,
27
- Nodes::FragmentSpread => GraphQL::Directive::FRAGMENT_SPREAD,
28
- Nodes::FragmentDefinition => GraphQL::Directive::FRAGMENT_DEFINITION,
25
+ Nodes::Field => GraphQL::Schema::Directive::FIELD,
26
+ Nodes::InlineFragment => GraphQL::Schema::Directive::INLINE_FRAGMENT,
27
+ Nodes::FragmentSpread => GraphQL::Schema::Directive::FRAGMENT_SPREAD,
28
+ Nodes::FragmentDefinition => GraphQL::Schema::Directive::FRAGMENT_DEFINITION,
29
29
  }
30
30
 
31
31
  SIMPLE_LOCATION_NODES = SIMPLE_LOCATIONS.keys
@@ -34,7 +34,7 @@ module GraphQL
34
34
  directive_defn = directives[ast_directive.name]
35
35
  case ast_parent
36
36
  when Nodes::OperationDefinition
37
- required_location = GraphQL::Directive.const_get(ast_parent.operation_type.upcase)
37
+ required_location = GraphQL::Schema::Directive.const_get(ast_parent.operation_type.upcase)
38
38
  assert_includes_location(directive_defn, ast_directive, required_location)
39
39
  when *SIMPLE_LOCATION_NODES
40
40
  required_location = SIMPLE_LOCATIONS[ast_parent.class]
@@ -28,12 +28,11 @@ module GraphQL
28
28
  # @return [Array<Hash>]
29
29
  def validate(query, validate: true, timeout: nil, max_errors: nil)
30
30
  query.trace("validate", { validate: validate, query: query }) do
31
- can_skip_rewrite = query.context.interpreter? && query.schema.using_ast_analysis? && query.schema.is_a?(Class)
32
- errors = if validate == false && can_skip_rewrite
31
+ errors = if validate == false
33
32
  []
34
33
  else
35
34
  rules_to_use = validate ? @rules : []
36
- visitor_class = BaseVisitor.including_rules(rules_to_use, rewrite: !can_skip_rewrite)
35
+ visitor_class = BaseVisitor.including_rules(rules_to_use)
37
36
 
38
37
  context = GraphQL::StaticValidation::ValidationContext.new(query, visitor_class, max_errors)
39
38
 
@@ -42,18 +41,6 @@ module GraphQL
42
41
  # A timeout value of 0 or nil will execute the block without any timeout.
43
42
  Timeout::timeout(timeout) do
44
43
  catch(:too_many_validation_errors) do
45
- # Attach legacy-style rules.
46
- # Only loop through rules if it has legacy-style rules
47
- unless (legacy_rules = rules_to_use - GraphQL::StaticValidation::ALL_RULES).empty?
48
- legacy_rules.each do |rule_class_or_module|
49
- if rule_class_or_module.method_defined?(:validate)
50
- GraphQL::Deprecation.warn "Legacy validator rules will be removed from GraphQL-Ruby 2.0, use a module instead (see the built-in rules: https://github.com/rmosolgo/graphql-ruby/tree/master/lib/graphql/static_validation/rules)"
51
- GraphQL::Deprecation.warn " -> Legacy validator: #{rule_class_or_module}"
52
- rule_class_or_module.new.validate(context)
53
- end
54
- end
55
- end
56
-
57
44
  context.visitor.visit
58
45
  end
59
46
  end
@@ -64,22 +51,13 @@ module GraphQL
64
51
  context.errors
65
52
  end
66
53
 
67
- irep = if errors.empty? && context
68
- # Only return this if there are no errors and validation was actually run
69
- context.visitor.rewrite_document
70
- else
71
- nil
72
- end
73
-
74
54
  {
75
55
  errors: errors,
76
- irep: irep,
77
56
  }
78
57
  end
79
58
  rescue GraphQL::ExecutionError => e
80
59
  {
81
60
  errors: [e],
82
- irep: nil,
83
61
  }
84
62
  end
85
63
 
@@ -7,7 +7,6 @@ require "graphql/static_validation/validation_context"
7
7
  require "graphql/static_validation/validation_timeout_error"
8
8
  require "graphql/static_validation/literal_validator"
9
9
  require "graphql/static_validation/base_visitor"
10
- require "graphql/static_validation/no_validate_visitor"
11
10
 
12
11
  rules_glob = File.expand_path("../static_validation/rules/*.rb", __FILE__)
13
12
  Dir.glob(rules_glob).each do |file|
@@ -15,5 +14,4 @@ Dir.glob(rules_glob).each do |file|
15
14
  end
16
15
 
17
16
  require "graphql/static_validation/all_rules"
18
- require "graphql/static_validation/default_visitor"
19
17
  require "graphql/static_validation/interpreter_visitor"
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  module GraphQL
3
3
  class Subscriptions
4
- class DefaultSubscriptionResolveExtension < GraphQL::Subscriptions::SubscriptionRoot::Extension
4
+ class DefaultSubscriptionResolveExtension < GraphQL::Schema::FieldExtension
5
5
  def resolve(context:, object:, arguments:)
6
6
  has_override_implementation = @field.resolver ||
7
7
  object.respond_to?(@field.resolver_method)
@@ -16,6 +16,43 @@ module GraphQL
16
16
  yield(object, arguments)
17
17
  end
18
18
  end
19
+
20
+ def after_resolve(value:, context:, object:, arguments:, **rest)
21
+ if value.is_a?(GraphQL::ExecutionError)
22
+ value
23
+ elsif (events = context.namespace(:subscriptions)[:events])
24
+ # This is the first execution, so gather an Event
25
+ # for the backend to register:
26
+ event = Subscriptions::Event.new(
27
+ name: field.name,
28
+ arguments: arguments_without_field_extras(arguments: arguments),
29
+ context: context,
30
+ field: field,
31
+ )
32
+ events << event
33
+ value
34
+ elsif context.query.subscription_topic == Subscriptions::Event.serialize(
35
+ field.name,
36
+ arguments_without_field_extras(arguments: arguments),
37
+ field,
38
+ scope: (field.subscription_scope ? context[field.subscription_scope] : nil),
39
+ )
40
+ # This is a subscription update. The resolver returned `skip` if it should be skipped,
41
+ # or else it returned an object to resolve the update.
42
+ value
43
+ else
44
+ # This is a subscription update, but this event wasn't triggered.
45
+ context.skip
46
+ end
47
+ end
48
+
49
+ private
50
+
51
+ def arguments_without_field_extras(arguments:)
52
+ arguments.dup.tap do |event_args|
53
+ field.extras.each { |k| event_args.delete(k) }
54
+ end
55
+ end
19
56
  end
20
57
  end
21
58
  end
@@ -9,7 +9,7 @@ module GraphQL
9
9
  # @return [String] Corresponds to the Subscription root field name
10
10
  attr_reader :name
11
11
 
12
- # @return [GraphQL::Query::Arguments]
12
+ # @return [GraphQL::Execution::Interpreter::Arguments]
13
13
  attr_reader :arguments
14
14
 
15
15
  # @return [GraphQL::Query::Context]
@@ -9,16 +9,6 @@ module GraphQL
9
9
  @schema = schema
10
10
  end
11
11
 
12
- def instrument(type, field)
13
- if type == @schema.subscription.graphql_definition
14
- # This is a root field of `subscription`
15
- subscribing_resolve_proc = SubscriptionRegistrationResolve.new(field.resolve_proc)
16
- field.redefine(resolve: subscribing_resolve_proc)
17
- else
18
- field
19
- end
20
- end
21
-
22
12
  # If needed, prepare to gather events which this query subscribes to
23
13
  def before_query(query)
24
14
  if query.subscription? && !query.subscription_update?
@@ -33,47 +23,6 @@ module GraphQL
33
23
  @schema.subscriptions.write_subscription(query, events)
34
24
  end
35
25
  end
36
-
37
- private
38
-
39
- class SubscriptionRegistrationResolve
40
- def initialize(inner_proc)
41
- @inner_proc = inner_proc
42
- end
43
-
44
- # Wrap the proc with subscription registration logic
45
- def call(obj, args, ctx)
46
- result = nil
47
- if @inner_proc && !@inner_proc.is_a?(GraphQL::Field::Resolve::BuiltInResolve)
48
- result = @inner_proc.call(obj, args, ctx)
49
- end
50
-
51
- events = ctx.namespace(:subscriptions)[:events]
52
-
53
- if events
54
- # This is the first execution, so gather an Event
55
- # for the backend to register:
56
- events << Subscriptions::Event.new(
57
- name: ctx.field.name,
58
- arguments: args,
59
- context: ctx,
60
- )
61
- result
62
- elsif ctx.irep_node.subscription_topic == ctx.query.subscription_topic
63
- if !result.nil?
64
- result
65
- elsif obj.is_a?(GraphQL::Schema::Object)
66
- # The root object is _already_ the subscription update:
67
- obj.object
68
- else
69
- obj
70
- end
71
- else
72
- # This is a subscription update, but this event wasn't triggered.
73
- ctx.skip
74
- end
75
- end
76
- end
77
26
  end
78
27
  end
79
28
  end
@@ -5,7 +5,6 @@ require "graphql/subscriptions/event"
5
5
  require "graphql/subscriptions/instrumentation"
6
6
  require "graphql/subscriptions/serialize"
7
7
  require "graphql/subscriptions/action_cable_subscriptions"
8
- require "graphql/subscriptions/subscription_root"
9
8
  require "graphql/subscriptions/default_subscription_resolve_extension"
10
9
 
11
10
  module GraphQL
@@ -33,9 +32,6 @@ module GraphQL
33
32
 
34
33
  instrumentation = Subscriptions::Instrumentation.new(schema: schema)
35
34
  defn.instrument(:query, instrumentation)
36
- if !schema.is_a?(Class)
37
- defn.instrument(:field, instrumentation)
38
- end
39
35
  options[:schema] = schema
40
36
  schema.subscriptions = self.new(**options)
41
37
  schema.add_subscription_extension_if_necessary
@@ -45,9 +41,6 @@ module GraphQL
45
41
  # @param schema [Class] the GraphQL schema this manager belongs to
46
42
  def initialize(schema:, broadcast: false, default_broadcastable: false, **rest)
47
43
  if broadcast
48
- if !schema.using_ast_analysis?
49
- raise ArgumentError, "`broadcast: true` requires AST analysis, add `using GraphQL::Analysis::AST` to your schema or see https://graphql-ruby.org/queries/ast_analysis.html."
50
- end
51
44
  schema.query_analyzer(Subscriptions::BroadcastAnalyzer)
52
45
  end
53
46
  @default_broadcastable = default_broadcastable
@@ -233,7 +226,7 @@ module GraphQL
233
226
  # @return [Any] normalized arguments value
234
227
  def normalize_arguments(event_name, arg_owner, args, context)
235
228
  case arg_owner
236
- when GraphQL::Field, GraphQL::InputObjectType, GraphQL::Schema::Field, Class
229
+ when GraphQL::Schema::Field, Class
237
230
  if arg_owner.is_a?(Class) && !arg_owner.kind.input_object?
238
231
  # it's a type, but not an input object
239
232
  return args
@@ -274,9 +267,7 @@ module GraphQL
274
267
  end
275
268
 
276
269
  if missing_arg_names.any?
277
- arg_owner_name = if arg_owner.is_a?(GraphQL::Field)
278
- "Subscription.#{arg_owner.name}"
279
- elsif arg_owner.is_a?(GraphQL::Schema::Field)
270
+ arg_owner_name = if arg_owner.is_a?(GraphQL::Schema::Field)
280
271
  arg_owner.path
281
272
  elsif arg_owner.is_a?(Class)
282
273
  arg_owner.graphql_name
@@ -287,9 +278,9 @@ module GraphQL
287
278
  end
288
279
 
289
280
  normalized_args
290
- when GraphQL::ListType, GraphQL::Schema::List
281
+ when GraphQL::Schema::List
291
282
  args.map { |a| normalize_arguments(event_name, arg_owner.of_type, a, context) }
292
- when GraphQL::NonNullType, GraphQL::Schema::NonNull
283
+ when GraphQL::Schema::NonNull
293
284
  normalize_arguments(event_name, arg_owner.of_type, args, context)
294
285
  else
295
286
  args
@@ -74,31 +74,8 @@ module GraphQL
74
74
  end
75
75
  end
76
76
 
77
- def instrument(type, field)
78
- return_type = field.type.unwrap
79
- case return_type
80
- when GraphQL::ScalarType, GraphQL::EnumType
81
- if field.trace || (field.trace.nil? && @trace_scalars)
82
- trace_field(type, field)
83
- else
84
- field
85
- end
86
- else
87
- trace_field(type, field)
88
- end
89
- end
90
-
91
- def trace_field(type, field)
92
- new_f = field.redefine
93
- new_f.metadata[:platform_key] = platform_field_key(type, field)
94
- new_f
95
- end
96
-
97
77
  def self.use(schema_defn, options = {})
98
78
  tracer = self.new(**options)
99
- if !schema_defn.is_a?(Class)
100
- schema_defn.instrument(:field, tracer)
101
- end
102
79
  schema_defn.tracer(tracer)
103
80
  end
104
81
 
@@ -6,7 +6,6 @@ require "graphql/tracing/appsignal_tracing"
6
6
  require "graphql/tracing/data_dog_tracing"
7
7
  require "graphql/tracing/new_relic_tracing"
8
8
  require "graphql/tracing/scout_tracing"
9
- require "graphql/tracing/skylight_tracing"
10
9
  require "graphql/tracing/statsd_tracing"
11
10
  require "graphql/tracing/prometheus_tracing"
12
11
 
@@ -54,7 +54,14 @@ module GraphQL
54
54
  Time.iso8601(str_value)
55
55
  rescue ArgumentError, TypeError
56
56
  begin
57
- Date.iso8601(str_value).to_time
57
+ dt = Date.iso8601(str_value).to_time
58
+ # For compatibility, continue accepting dates given without times
59
+ # But without this, it would zero out given any time part of `str_value` (hours and/or minutes)
60
+ if dt.iso8601.start_with?(str_value)
61
+ dt
62
+ else
63
+ nil
64
+ end
58
65
  rescue ArgumentError, TypeError
59
66
  # Invalid input
60
67
  nil
@@ -36,7 +36,7 @@ module GraphQL
36
36
  # class name to set defaults. You can call it again in the class definition
37
37
  # to override the default (or provide a value, if the default lookup failed).
38
38
  # @param field_options [Hash] Any extra keyword arguments to pass to the `field :edges, ...` and `field :nodes, ...` configurations
39
- def edge_type(edge_type_class, edge_class: GraphQL::Relay::Edge, node_type: edge_type_class.node_type, nodes_field: self.has_nodes_field, node_nullable: self.node_nullable, edges_nullable: self.edges_nullable, edge_nullable: self.edge_nullable, field_options: nil)
39
+ def edge_type(edge_type_class, edge_class: GraphQL::Pagination::Connection::Edge, node_type: edge_type_class.node_type, nodes_field: self.has_nodes_field, node_nullable: self.node_nullable, edges_nullable: self.edges_nullable, edge_nullable: self.edge_nullable, field_options: nil)
40
40
  # Set this connection's graphql name
41
41
  node_type_name = node_type.graphql_name
42
42
 
@@ -49,7 +49,6 @@ module GraphQL
49
49
  type: [edge_type_class, null: edge_nullable],
50
50
  null: edges_nullable,
51
51
  description: "A list of edges.",
52
- legacy_edge_class: edge_class, # This is used by the old runtime only, for EdgesInstrumentation
53
52
  connection: false,
54
53
  }
55
54
 
@@ -83,7 +82,8 @@ module GraphQL
83
82
  end
84
83
 
85
84
  def visible?(ctx)
86
- node_type.visible?(ctx)
85
+ # if this is an abstract base class, there may be no `node_type`
86
+ node_type ? node_type.visible?(ctx) : super
87
87
  end
88
88
 
89
89
  # Set the default `node_nullable` for this class and its child classes. (Defaults to `true`.)
@@ -158,13 +158,10 @@ module GraphQL
158
158
  def edges
159
159
  if @object.is_a?(GraphQL::Pagination::Connection)
160
160
  @object.edges
161
- elsif context.interpreter?
161
+ else
162
162
  context.schema.after_lazy(object.edge_nodes) do |nodes|
163
163
  nodes.map { |n| self.class.edge_class.new(n, object) }
164
164
  end
165
- else
166
- # This is done by edges_instrumentation
167
- @object.edge_nodes
168
165
  end
169
166
  end
170
167
  end
@@ -15,16 +15,6 @@ module GraphQL
15
15
  def default_relay?
16
16
  !!@default_relay
17
17
  end
18
-
19
- def to_graphql
20
- type_defn = if method(:to_graphql).super_method.arity
21
- super(silence_deprecation_warning: true)
22
- else
23
- super
24
- end
25
- type_defn.default_relay = default_relay?
26
- type_defn
27
- end
28
18
  end
29
19
  end
30
20
  end
@@ -7,7 +7,11 @@ module GraphQL
7
7
  def self.included(child_module)
8
8
  child_module.extend(DefaultRelay)
9
9
  child_module.description("An object with an ID.")
10
- child_module.field(:id, ID, null: false, description: "ID of the object.")
10
+ child_module.field(:id, ID, null: false, description: "ID of the object.", resolver_method: :default_global_id)
11
+ end
12
+
13
+ def default_global_id
14
+ context.schema.id_from_object(object, self, context)
11
15
  end
12
16
  end
13
17
  end
@@ -14,8 +14,6 @@ require "graphql/types/relay/page_info"
14
14
  require "graphql/types/relay/base_connection"
15
15
  require "graphql/types/relay/base_edge"
16
16
  require "graphql/types/relay/node"
17
- require "graphql/types/relay/node_field"
18
- require "graphql/types/relay/nodes_field"
19
17
 
20
18
  module GraphQL
21
19
  module Types
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module GraphQL
3
- VERSION = "1.13.6"
3
+ VERSION = "2.0.0"
4
4
  end
data/lib/graphql.rb CHANGED
@@ -17,6 +17,17 @@ module GraphQL
17
17
  class Error < StandardError
18
18
  end
19
19
 
20
+ # This error is raised when GraphQL-Ruby encounters a situation
21
+ # that it *thought* would never happen. Please report this bug!
22
+ class InvariantError < Error
23
+ def initialize(message)
24
+ message += "
25
+
26
+ This is probably a bug in GraphQL-Ruby, please report this error on GitHub: https://github.com/rmosolgo/graphql-ruby/issues/new?template=bug_report.md"
27
+ super(message)
28
+ end
29
+ end
30
+
20
31
  class RequiredImplementationMissingError < Error
21
32
  end
22
33
 
@@ -70,26 +81,8 @@ require "graphql/integer_decoding_error"
70
81
  require "graphql/integer_encoding_error"
71
82
  require "graphql/string_encoding_error"
72
83
  require "graphql/date_encoding_error"
73
-
74
- require "graphql/define"
75
- require "graphql/base_type"
76
- require "graphql/object_type"
77
- require "graphql/enum_type"
78
- require "graphql/input_object_type"
79
- require "graphql/interface_type"
80
- require "graphql/list_type"
81
- require "graphql/non_null_type"
82
- require "graphql/union_type"
83
-
84
- require "graphql/argument"
85
- require "graphql/field"
86
84
  require "graphql/type_kinds"
87
-
88
- require "graphql/backwards_compatibility"
89
- require "graphql/scalar_type"
90
-
91
85
  require "graphql/name_validator"
92
-
93
86
  require "graphql/language"
94
87
 
95
88
  require_relative "./graphql/railtie" if defined? Rails::Railtie
@@ -104,16 +97,8 @@ require "graphql/query"
104
97
  require "graphql/types"
105
98
  require "graphql/dataloader"
106
99
  require "graphql/filter"
107
- require "graphql/internal_representation"
108
- require "graphql/directive"
109
100
  require "graphql/static_validation"
110
101
  require "graphql/execution"
111
- require "graphql/deprecation"
112
- require "graphql/boolean_type"
113
- require "graphql/float_type"
114
- require "graphql/id_type"
115
- require "graphql/int_type"
116
- require "graphql/string_type"
117
102
  require "graphql/schema/built_in_types"
118
103
  require "graphql/schema/loader"
119
104
  require "graphql/schema/printer"
@@ -121,49 +106,11 @@ require "graphql/introspection"
121
106
  require "graphql/relay"
122
107
 
123
108
  require "graphql/version"
124
- require "graphql/compatibility"
125
- require "graphql/function"
126
109
  require "graphql/subscriptions"
127
110
  require "graphql/parse_error"
128
111
  require "graphql/backtrace"
129
112
 
130
- require "graphql/deprecated_dsl"
131
- require "graphql/authorization"
132
113
  require "graphql/unauthorized_error"
133
114
  require "graphql/unauthorized_field_error"
134
115
  require "graphql/load_application_object_failed_error"
135
- require "graphql/directive/include_directive"
136
- require "graphql/directive/skip_directive"
137
- require "graphql/directive/deprecated_directive"
138
-
139
- module GraphQL
140
- # Ruby has `deprecate_constant`,
141
- # but I don't see a way to give a nice error message in that case,
142
- # so I'm doing this instead.
143
- DEPRECATED_INT_TYPE = INT_TYPE
144
- DEPRECATED_FLOAT_TYPE = FLOAT_TYPE
145
- DEPRECATED_STRING_TYPE = STRING_TYPE
146
- DEPRECATED_BOOLEAN_TYPE = BOOLEAN_TYPE
147
- DEPRECATED_ID_TYPE = ID_TYPE
148
-
149
- remove_const :INT_TYPE
150
- remove_const :FLOAT_TYPE
151
- remove_const :STRING_TYPE
152
- remove_const :BOOLEAN_TYPE
153
- remove_const :ID_TYPE
154
-
155
- def self.const_missing(const_name)
156
- deprecated_const_name = :"DEPRECATED_#{const_name}"
157
- if const_defined?(deprecated_const_name)
158
- deprecated_type = const_get(deprecated_const_name)
159
- deprecated_caller = caller(1, 1).first
160
- # Don't warn about internal uses, like `types.Int`
161
- if !deprecated_caller.include?("lib/graphql")
162
- warn "GraphQL::#{const_name} is deprecated and will be removed in GraphQL-Ruby 2.0, use GraphQL::Types::#{deprecated_type.graphql_name} instead. (from #{deprecated_caller})"
163
- end
164
- deprecated_type
165
- else
166
- super
167
- end
168
- end
169
- end
116
+ require "graphql/deprecation"