graphql 1.11.7 → 1.12.4

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 (140) hide show
  1. checksums.yaml +4 -4
  2. data/lib/generators/graphql/install_generator.rb +7 -5
  3. data/lib/generators/graphql/relay.rb +55 -0
  4. data/lib/generators/graphql/relay_generator.rb +20 -0
  5. data/lib/generators/graphql/templates/base_connection.erb +8 -0
  6. data/lib/generators/graphql/templates/base_edge.erb +8 -0
  7. data/lib/generators/graphql/templates/node_type.erb +9 -0
  8. data/lib/generators/graphql/templates/object.erb +1 -1
  9. data/lib/generators/graphql/templates/query_type.erb +1 -3
  10. data/lib/generators/graphql/templates/schema.erb +8 -35
  11. data/lib/graphql.rb +38 -4
  12. data/lib/graphql/analysis/analyze_query.rb +7 -0
  13. data/lib/graphql/analysis/ast.rb +11 -2
  14. data/lib/graphql/analysis/ast/visitor.rb +9 -1
  15. data/lib/graphql/backtrace.rb +28 -19
  16. data/lib/graphql/backtrace/inspect_result.rb +0 -1
  17. data/lib/graphql/backtrace/legacy_tracer.rb +56 -0
  18. data/lib/graphql/backtrace/table.rb +22 -3
  19. data/lib/graphql/backtrace/traced_error.rb +0 -1
  20. data/lib/graphql/backtrace/tracer.rb +37 -10
  21. data/lib/graphql/backwards_compatibility.rb +2 -1
  22. data/lib/graphql/base_type.rb +1 -1
  23. data/lib/graphql/compatibility/execution_specification.rb +1 -0
  24. data/lib/graphql/compatibility/lazy_execution_specification.rb +2 -0
  25. data/lib/graphql/compatibility/query_parser_specification.rb +2 -0
  26. data/lib/graphql/compatibility/schema_parser_specification.rb +2 -0
  27. data/lib/graphql/dataloader.rb +208 -0
  28. data/lib/graphql/dataloader/null_dataloader.rb +21 -0
  29. data/lib/graphql/dataloader/request.rb +19 -0
  30. data/lib/graphql/dataloader/request_all.rb +19 -0
  31. data/lib/graphql/dataloader/source.rb +107 -0
  32. data/lib/graphql/define/assign_global_id_field.rb +1 -1
  33. data/lib/graphql/define/instance_definable.rb +32 -2
  34. data/lib/graphql/define/type_definer.rb +5 -5
  35. data/lib/graphql/deprecated_dsl.rb +7 -2
  36. data/lib/graphql/deprecation.rb +13 -0
  37. data/lib/graphql/enum_type.rb +2 -0
  38. data/lib/graphql/execution/errors.rb +4 -0
  39. data/lib/graphql/execution/execute.rb +7 -0
  40. data/lib/graphql/execution/interpreter.rb +11 -7
  41. data/lib/graphql/execution/interpreter/arguments.rb +51 -14
  42. data/lib/graphql/execution/interpreter/arguments_cache.rb +37 -14
  43. data/lib/graphql/execution/interpreter/handles_raw_value.rb +0 -7
  44. data/lib/graphql/execution/interpreter/resolve.rb +33 -25
  45. data/lib/graphql/execution/interpreter/runtime.rb +173 -123
  46. data/lib/graphql/execution/multiplex.rb +36 -23
  47. data/lib/graphql/function.rb +4 -0
  48. data/lib/graphql/input_object_type.rb +2 -0
  49. data/lib/graphql/interface_type.rb +3 -1
  50. data/lib/graphql/internal_representation/document.rb +2 -2
  51. data/lib/graphql/internal_representation/rewrite.rb +1 -1
  52. data/lib/graphql/language/document_from_schema_definition.rb +50 -23
  53. data/lib/graphql/object_type.rb +2 -2
  54. data/lib/graphql/pagination/connection.rb +5 -1
  55. data/lib/graphql/pagination/connections.rb +6 -16
  56. data/lib/graphql/parse_error.rb +0 -1
  57. data/lib/graphql/query.rb +10 -2
  58. data/lib/graphql/query/arguments.rb +1 -1
  59. data/lib/graphql/query/arguments_cache.rb +0 -1
  60. data/lib/graphql/query/context.rb +4 -2
  61. data/lib/graphql/query/executor.rb +0 -1
  62. data/lib/graphql/query/null_context.rb +3 -2
  63. data/lib/graphql/query/serial_execution.rb +1 -0
  64. data/lib/graphql/query/variable_validation_error.rb +1 -1
  65. data/lib/graphql/relay/base_connection.rb +7 -0
  66. data/lib/graphql/relay/connection_instrumentation.rb +4 -4
  67. data/lib/graphql/relay/connection_type.rb +1 -1
  68. data/lib/graphql/relay/mutation.rb +1 -0
  69. data/lib/graphql/relay/node.rb +3 -0
  70. data/lib/graphql/relay/type_extensions.rb +2 -0
  71. data/lib/graphql/scalar_type.rb +2 -0
  72. data/lib/graphql/schema.rb +64 -26
  73. data/lib/graphql/schema/argument.rb +86 -7
  74. data/lib/graphql/schema/build_from_definition.rb +139 -51
  75. data/lib/graphql/schema/directive.rb +76 -0
  76. data/lib/graphql/schema/directive/flagged.rb +57 -0
  77. data/lib/graphql/schema/enum.rb +3 -0
  78. data/lib/graphql/schema/enum_value.rb +12 -6
  79. data/lib/graphql/schema/field.rb +40 -16
  80. data/lib/graphql/schema/field/connection_extension.rb +3 -2
  81. data/lib/graphql/schema/find_inherited_value.rb +3 -1
  82. data/lib/graphql/schema/input_object.rb +39 -24
  83. data/lib/graphql/schema/interface.rb +1 -0
  84. data/lib/graphql/schema/member.rb +4 -0
  85. data/lib/graphql/schema/member/base_dsl_methods.rb +1 -0
  86. data/lib/graphql/schema/member/build_type.rb +3 -3
  87. data/lib/graphql/schema/member/has_arguments.rb +54 -49
  88. data/lib/graphql/schema/member/has_deprecation_reason.rb +25 -0
  89. data/lib/graphql/schema/member/has_directives.rb +98 -0
  90. data/lib/graphql/schema/member/has_fields.rb +1 -4
  91. data/lib/graphql/schema/member/has_validators.rb +31 -0
  92. data/lib/graphql/schema/member/instrumentation.rb +0 -1
  93. data/lib/graphql/schema/member/type_system_helpers.rb +1 -1
  94. data/lib/graphql/schema/middleware_chain.rb +1 -1
  95. data/lib/graphql/schema/object.rb +11 -0
  96. data/lib/graphql/schema/printer.rb +5 -4
  97. data/lib/graphql/schema/resolver.rb +7 -0
  98. data/lib/graphql/schema/resolver/has_payload_type.rb +2 -0
  99. data/lib/graphql/schema/subscription.rb +19 -1
  100. data/lib/graphql/schema/timeout_middleware.rb +3 -1
  101. data/lib/graphql/schema/validation.rb +4 -2
  102. data/lib/graphql/schema/validator.rb +163 -0
  103. data/lib/graphql/schema/validator/exclusion_validator.rb +31 -0
  104. data/lib/graphql/schema/validator/format_validator.rb +49 -0
  105. data/lib/graphql/schema/validator/inclusion_validator.rb +33 -0
  106. data/lib/graphql/schema/validator/length_validator.rb +57 -0
  107. data/lib/graphql/schema/validator/numericality_validator.rb +71 -0
  108. data/lib/graphql/schema/validator/required_validator.rb +68 -0
  109. data/lib/graphql/static_validation/validator.rb +4 -0
  110. data/lib/graphql/subscriptions.rb +17 -20
  111. data/lib/graphql/subscriptions/event.rb +0 -1
  112. data/lib/graphql/subscriptions/instrumentation.rb +0 -1
  113. data/lib/graphql/subscriptions/serialize.rb +0 -1
  114. data/lib/graphql/subscriptions/subscription_root.rb +1 -1
  115. data/lib/graphql/tracing.rb +2 -2
  116. data/lib/graphql/tracing/appoptics_tracing.rb +3 -1
  117. data/lib/graphql/tracing/platform_tracing.rb +3 -1
  118. data/lib/graphql/tracing/skylight_tracing.rb +1 -1
  119. data/lib/graphql/types/relay.rb +11 -3
  120. data/lib/graphql/types/relay/base_connection.rb +2 -92
  121. data/lib/graphql/types/relay/base_edge.rb +2 -35
  122. data/lib/graphql/types/relay/connection_behaviors.rb +123 -0
  123. data/lib/graphql/types/relay/default_relay.rb +27 -0
  124. data/lib/graphql/types/relay/edge_behaviors.rb +42 -0
  125. data/lib/graphql/types/relay/has_node_field.rb +41 -0
  126. data/lib/graphql/types/relay/has_nodes_field.rb +41 -0
  127. data/lib/graphql/types/relay/node.rb +2 -4
  128. data/lib/graphql/types/relay/node_behaviors.rb +15 -0
  129. data/lib/graphql/types/relay/node_field.rb +1 -19
  130. data/lib/graphql/types/relay/nodes_field.rb +1 -19
  131. data/lib/graphql/types/relay/page_info.rb +2 -14
  132. data/lib/graphql/types/relay/page_info_behaviors.rb +25 -0
  133. data/lib/graphql/union_type.rb +2 -0
  134. data/lib/graphql/upgrader/member.rb +1 -0
  135. data/lib/graphql/upgrader/schema.rb +1 -0
  136. data/lib/graphql/version.rb +1 -1
  137. metadata +50 -93
  138. data/lib/graphql/types/relay/base_field.rb +0 -22
  139. data/lib/graphql/types/relay/base_interface.rb +0 -29
  140. data/lib/graphql/types/relay/base_object.rb +0 -26
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: af3eaf2a85e27ab7a366e27a98d42e4372b93c7590c99fb6fb12fccb48ef37f9
4
- data.tar.gz: 62be23c2f74539be298db79081b148db5d004325ef6ae6f1b007711659110a01
3
+ metadata.gz: 986cbfad7b1ad59a7c26ee447068627be0c4f089fdb4894bd1b4a8580ba9b180
4
+ data.tar.gz: f5945fe64fea70330e078c7f11119f97bd9815b41f37a4e8748e682a9a4aa5ef
5
5
  SHA512:
6
- metadata.gz: f12858fd3c28da572082443e022ed2a5281bda7eda01a35b4c6bee65273b5744ae43904c5bf6202a5d461d67de6ee1ec9d1210a121181d5876a3aee3f37b4f1e
7
- data.tar.gz: ed4f7ba1b52e9526d4f4a630f2ca06234816bd6be7522e29a98015a8bfa94a8bccdf98a03139ef9f45b266a8f62cb9d922c93ddebf797125d91d04a2203a4aec
6
+ metadata.gz: f593fc1f7a47764de491e297703e5b6cb9fd64cb90de65ed0af51bb510a47f02e2e059d2707ad425d36f6caee71597584c5f27909df39635c60d04706431121a
7
+ data.tar.gz: 6c70786f0d123fc9a8dfa6b6cb3d1a24c7d07ca1fd73e375871372b45c0b67452cb5b96a0f633fded6a92e436414b5799a920e1739f8018bfc4953b4e2ad0343
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  require 'rails/generators/base'
3
3
  require_relative 'core'
4
+ require_relative 'relay'
4
5
 
5
6
  module Graphql
6
7
  module Generators
@@ -43,9 +44,6 @@ module Graphql
43
44
  # post "/graphql", to: "graphql#execute"
44
45
  # ```
45
46
  #
46
- # Accept a `--relay` option which adds
47
- # The root `node(id: ID!)` field.
48
- #
49
47
  # Accept a `--batch` option which adds `GraphQL::Batch` setup.
50
48
  #
51
49
  # Use `--no-graphiql` to skip `graphiql-rails` installation.
@@ -53,6 +51,7 @@ module Graphql
53
51
  # TODO: also add base classes
54
52
  class InstallGenerator < Rails::Generators::Base
55
53
  include Core
54
+ include Relay
56
55
 
57
56
  desc "Install GraphQL folder structure and boilerplate code"
58
57
  source_root File.expand_path('../templates', __FILE__)
@@ -79,8 +78,8 @@ module Graphql
79
78
 
80
79
  class_option :relay,
81
80
  type: :boolean,
82
- default: false,
83
- desc: "Include GraphQL::Relay installation"
81
+ default: true,
82
+ desc: "Include installation of Relay conventions (nodes, connections, edges)"
84
83
 
85
84
  class_option :batch,
86
85
  type: :boolean,
@@ -164,7 +163,10 @@ if Rails.env.development?
164
163
  RUBY
165
164
  end
166
165
  end
166
+ end
167
167
 
168
+ if options[:relay]
169
+ install_relay
168
170
  end
169
171
 
170
172
  if gemfile_modified?
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+ module Graphql
3
+ module Generators
4
+ module Relay
5
+ def install_relay
6
+ # Add Node, `node(id:)`, and `nodes(ids:)`
7
+ template("node_type.erb", "#{options[:directory]}/types/node_type.rb")
8
+ in_root do
9
+ fields = " # Add `node(id: ID!) and `nodes(ids: [ID!]!)`\n include GraphQL::Types::Relay::HasNodeField\n include GraphQL::Types::Relay::HasNodesField\n\n"
10
+ inject_into_file "#{options[:directory]}/types/query_type.rb", fields, after: /class .*QueryType\s*<\s*[^\s]+?\n/m, force: false
11
+ end
12
+
13
+ # Add connections and edges
14
+ template("base_connection.erb", "#{options[:directory]}/types/base_connection.rb")
15
+ template("base_edge.erb", "#{options[:directory]}/types/base_edge.rb")
16
+ connectionable_type_files = {
17
+ "#{options[:directory]}/types/base_object.rb" => /class .*BaseObject\s*<\s*[^\s]+?\n/m,
18
+ "#{options[:directory]}/types/base_union.rb" => /class .*BaseUnion\s*<\s*[^\s]+?\n/m,
19
+ "#{options[:directory]}/types/base_interface.rb" => /include GraphQL::Schema::Interface\n/m,
20
+ }
21
+ in_root do
22
+ connectionable_type_files.each do |type_class_file, sentinel|
23
+ inject_into_file type_class_file, " connection_type_class(Types::BaseConnection)\n", after: sentinel, force: false
24
+ inject_into_file type_class_file, " edge_type_class(Types::BaseEdge)\n", after: sentinel, force: false
25
+ end
26
+ end
27
+
28
+ # Add object ID hooks & connection plugin
29
+ schema_code = <<-RUBY
30
+
31
+ # Relay-style Object Identification:
32
+
33
+ # Return a string UUID for `object`
34
+ def self.id_from_object(object, type_definition, query_ctx)
35
+ # Here's a simple implementation which:
36
+ # - joins the type name & object.id
37
+ # - encodes it with base64:
38
+ # GraphQL::Schema::UniqueWithinType.encode(type_definition.name, object.id)
39
+ end
40
+
41
+ # Given a string UUID, find the object
42
+ def self.object_from_id(id, query_ctx)
43
+ # For example, to decode the UUIDs generated above:
44
+ # type_name, item_id = GraphQL::Schema::UniqueWithinType.decode(id)
45
+ #
46
+ # Then, based on `type_name` and `id`
47
+ # find an object in your application
48
+ # ...
49
+ end
50
+ RUBY
51
+ inject_into_file schema_file_path, schema_code, before: /^end\n/m, force: false
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+ require 'rails/generators/base'
3
+ require_relative 'core'
4
+ require_relative 'relay'
5
+
6
+ module Graphql
7
+ module Generators
8
+ class RelayGenerator < Rails::Generators::Base
9
+ include Core
10
+ include Relay
11
+
12
+ desc "Add base types and fields for Relay-style nodes and connections"
13
+ source_root File.expand_path('../templates', __FILE__)
14
+
15
+ def install_relay
16
+ super
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,8 @@
1
+ <% module_namespacing_when_supported do -%>
2
+ module Types
3
+ class BaseConnection < Types::BaseObject
4
+ # add `nodes` and `pageInfo` fields, as well as `edge_type(...)` and `node_nullable(...)` overrides
5
+ include GraphQL::Types::Relay::ConnectionBehaviors
6
+ end
7
+ end
8
+ <% end -%>
@@ -0,0 +1,8 @@
1
+ <% module_namespacing_when_supported do -%>
2
+ module Types
3
+ class BaseEdge < Types::BaseObject
4
+ # add `node` and `cursor` fields, as well as `node_type(...)` override
5
+ include GraphQL::Types::Relay::EdgeBehaviors
6
+ end
7
+ end
8
+ <% end -%>
@@ -0,0 +1,9 @@
1
+ <% module_namespacing_when_supported do -%>
2
+ module Types
3
+ module NodeType
4
+ include Types::BaseInterface
5
+ # Add the `id` field
6
+ include GraphQL::Types::Relay::NodeBehaviors
7
+ end
8
+ end
9
+ <% end -%>
@@ -1,7 +1,7 @@
1
1
  <% module_namespacing_when_supported do -%>
2
2
  module Types
3
3
  class <%= type_ruby_name.split('::')[-1] %> < Types::BaseObject
4
- <% if options.node %> implements GraphQL::Relay::Node.interface
4
+ <% if options.node %> implements GraphQL::Types::Relay::Node
5
5
  <% end %><% normalized_fields.each do |f| %> <%= f.to_ruby %>
6
6
  <% end %> end
7
7
  end
@@ -10,8 +10,6 @@ module Types
10
10
  def test_field
11
11
  "Hello World!"
12
12
  end
13
- <% if options[:relay] %>
14
- field :node, field: GraphQL::Relay::Node.field
15
- <% end %> end
13
+ end
16
14
  end
17
15
  <% end -%>
@@ -1,42 +1,15 @@
1
1
  <% module_namespacing_when_supported do -%>
2
2
  class <%= schema_name %> < GraphQL::Schema
3
3
  query(Types::QueryType)
4
-
5
- # Opt in to the new runtime (default in future graphql-ruby versions)
6
- use GraphQL::Execution::Interpreter
7
- use GraphQL::Analysis::AST
8
-
9
- # Add built-in connections for pagination
10
- use GraphQL::Pagination::Connections
11
- <% if options[:relay] %>
12
- # Relay Object Identification:
13
-
14
- # Return a string UUID for `object`
15
- def self.id_from_object(object, type_definition, query_ctx)
16
- # Here's a simple implementation which:
17
- # - joins the type name & object.id
18
- # - encodes it with base64:
19
- # GraphQL::Schema::UniqueWithinType.encode(type_definition.name, object.id)
20
- end
21
-
22
- # Given a string UUID, find the object
23
- def self.object_from_id(id, query_ctx)
24
- # For example, to decode the UUIDs generated above:
25
- # type_name, item_id = GraphQL::Schema::UniqueWithinType.decode(id)
26
- #
27
- # Then, based on `type_name` and `id`
28
- # find an object in your application
29
- # ...
30
- end
31
-
32
- # Object Resolution
33
- def self.resolve_type(type, obj, ctx)
4
+ <% if options[:batch] %>
5
+ # GraphQL::Batch setup:
6
+ use GraphQL::Batch
7
+ <% end %>
8
+ # Union and Interface Resolution
9
+ def self.resolve_type(abstract_type, obj, ctx)
34
10
  # TODO: Implement this function
35
- # to return the correct type for `obj`
11
+ # to return the correct object type for `obj`
36
12
  raise(GraphQL::RequiredImplementationMissingError)
37
13
  end
38
- <% end %><% if options[:batch] %>
39
- # GraphQL::Batch setup:
40
- use GraphQL::Batch
41
- <% end %>end
14
+ end
42
15
  <% end -%>
data/lib/graphql.rb CHANGED
@@ -110,6 +110,7 @@ require "graphql/execution"
110
110
  require "graphql/runtime_type_error"
111
111
  require "graphql/unresolved_type_error"
112
112
  require "graphql/invalid_null_error"
113
+ require "graphql/pagination"
113
114
  require "graphql/schema"
114
115
  require "graphql/query"
115
116
  require "graphql/directive"
@@ -124,6 +125,10 @@ require "graphql/string_type"
124
125
  require "graphql/schema/built_in_types"
125
126
  require "graphql/schema/loader"
126
127
  require "graphql/schema/printer"
128
+ require "graphql/filter"
129
+ require "graphql/internal_representation"
130
+ require "graphql/static_validation"
131
+ require "graphql/dataloader"
127
132
  require "graphql/introspection"
128
133
 
129
134
  require "graphql/analysis_error"
@@ -132,12 +137,9 @@ require "graphql/invalid_name_error"
132
137
  require "graphql/integer_decoding_error"
133
138
  require "graphql/integer_encoding_error"
134
139
  require "graphql/string_encoding_error"
135
- require "graphql/internal_representation"
136
- require "graphql/static_validation"
137
140
  require "graphql/version"
138
141
  require "graphql/compatibility"
139
142
  require "graphql/function"
140
- require "graphql/filter"
141
143
  require "graphql/subscriptions"
142
144
  require "graphql/parse_error"
143
145
  require "graphql/backtrace"
@@ -147,4 +149,36 @@ require "graphql/authorization"
147
149
  require "graphql/unauthorized_error"
148
150
  require "graphql/unauthorized_field_error"
149
151
  require "graphql/load_application_object_failed_error"
150
- require "graphql/pagination"
152
+ require "graphql/deprecation"
153
+
154
+ module GraphQL
155
+ # Ruby has `deprecate_constant`,
156
+ # but I don't see a way to give a nice error message in that case,
157
+ # so I'm doing this instead.
158
+ DEPRECATED_INT_TYPE = INT_TYPE
159
+ DEPRECATED_FLOAT_TYPE = FLOAT_TYPE
160
+ DEPRECATED_STRING_TYPE = STRING_TYPE
161
+ DEPRECATED_BOOLEAN_TYPE = BOOLEAN_TYPE
162
+ DEPRECATED_ID_TYPE = ID_TYPE
163
+
164
+ remove_const :INT_TYPE
165
+ remove_const :FLOAT_TYPE
166
+ remove_const :STRING_TYPE
167
+ remove_const :BOOLEAN_TYPE
168
+ remove_const :ID_TYPE
169
+
170
+ def self.const_missing(const_name)
171
+ deprecated_const_name = :"DEPRECATED_#{const_name}"
172
+ if const_defined?(deprecated_const_name)
173
+ deprecated_type = const_get(deprecated_const_name)
174
+ deprecated_caller = caller(1, 1).first
175
+ # Don't warn about internal uses, like `types.Int`
176
+ if !deprecated_caller.include?("lib/graphql")
177
+ 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})"
178
+ end
179
+ deprecated_type
180
+ else
181
+ super
182
+ end
183
+ end
184
+ end
@@ -3,6 +3,11 @@ module GraphQL
3
3
  module Analysis
4
4
  module_function
5
5
 
6
+ def use(schema_class)
7
+ schema = schema_class.is_a?(Class) ? schema_class : schema_class.target
8
+ schema.analysis_engine = self
9
+ end
10
+
6
11
  # @return [void]
7
12
  def analyze_multiplex(multiplex, analyzers)
8
13
  multiplex.trace("analyze_multiplex", { multiplex: multiplex }) do
@@ -38,6 +43,8 @@ module GraphQL
38
43
  # @param analyzers [Array<#call>] Objects that respond to `#call(memo, visit_type, irep_node)`
39
44
  # @return [Array<Any>] Results from those analyzers
40
45
  def analyze_query(query, analyzers, multiplex_states: [])
46
+ GraphQL::Deprecation.warn "Legacy analysis will be removed in GraphQL-Ruby 2.0, please upgrade to AST Analysis: https://graphql-ruby.org/queries/ast_analysis.html (schema: #{query.schema})"
47
+
41
48
  query.trace("analyze_query", { query: query }) do
42
49
  analyzers_to_run = analyzers.select do |analyzer|
43
50
  if analyzer.respond_to?(:analyze?)
@@ -13,7 +13,12 @@ module GraphQL
13
13
  module_function
14
14
 
15
15
  def use(schema_class)
16
- schema_class.analysis_engine = GraphQL::Analysis::AST
16
+ if schema_class.analysis_engine == self
17
+ definition_line = caller(2, 1).first
18
+ GraphQL::Deprecation.warn("GraphQL::Analysis::AST is now the default; remove `use GraphQL::Analysis::AST` from the schema definition (#{definition_line})")
19
+ else
20
+ schema_class.analysis_engine = self
21
+ end
17
22
  end
18
23
 
19
24
  # Analyze a multiplex, and all queries within.
@@ -67,7 +72,11 @@ module GraphQL
67
72
 
68
73
  visitor.visit
69
74
 
70
- query_analyzers.map(&:result)
75
+ if visitor.rescued_errors.any?
76
+ visitor.rescued_errors
77
+ else
78
+ query_analyzers.map(&:result)
79
+ end
71
80
  else
72
81
  []
73
82
  end
@@ -19,6 +19,7 @@ module GraphQL
19
19
  @field_definitions = []
20
20
  @argument_definitions = []
21
21
  @directive_definitions = []
22
+ @rescued_errors = []
22
23
  @query = query
23
24
  @schema = query.schema
24
25
  @response_path = []
@@ -32,6 +33,9 @@ module GraphQL
32
33
  # @return [Array<GraphQL::ObjectType>] Types whose scope we've entered
33
34
  attr_reader :object_types
34
35
 
36
+ # @return [Array<GraphQL::AnalysisError]
37
+ attr_reader :rescued_errors
38
+
35
39
  def visit
36
40
  return unless @document
37
41
  super
@@ -239,7 +243,11 @@ module GraphQL
239
243
 
240
244
  def call_analyzers(method, node, parent)
241
245
  @analyzers.each do |analyzer|
242
- analyzer.public_send(method, node, parent, self)
246
+ begin
247
+ analyzer.public_send(method, node, parent, self)
248
+ rescue AnalysisError => err
249
+ @rescued_errors << err
250
+ end
243
251
  end
244
252
  end
245
253
 
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  require "graphql/backtrace/inspect_result"
3
+ require "graphql/backtrace/legacy_tracer"
3
4
  require "graphql/backtrace/table"
4
5
  require "graphql/backtrace/traced_error"
5
6
  require "graphql/backtrace/tracer"
@@ -9,13 +10,12 @@ module GraphQL
9
10
  # {TracedError} provides a GraphQL backtrace with arguments and return values.
10
11
  # The underlying error is available as {TracedError#cause}.
11
12
  #
12
- # WARNING: {.enable} is not threadsafe because {GraphQL::Tracing.install} is not threadsafe.
13
- #
14
13
  # @example toggling backtrace annotation
15
- # # to enable:
16
- # GraphQL::Backtrace.enable
17
- # # later, to disable:
18
- # GraphQL::Backtrace.disable
14
+ # class MySchema < GraphQL::Schema
15
+ # if Rails.env.development? || Rails.env.test?
16
+ # use GraphQL::Backtrace
17
+ # end
18
+ # end
19
19
  #
20
20
  class Backtrace
21
21
  include Enumerable
@@ -23,19 +23,13 @@ module GraphQL
23
23
 
24
24
  def_delegators :to_a, :each, :[]
25
25
 
26
- def self.enable
27
- warn("GraphQL::Backtrace.enable is deprecated, add `use GraphQL::Backtrace` to your schema definition instead.")
28
- GraphQL::Tracing.install(Backtrace::Tracer)
29
- nil
30
- end
31
-
32
- def self.disable
33
- GraphQL::Tracing.uninstall(Backtrace::Tracer)
34
- nil
35
- end
36
-
37
- def self.use(schema_defn)
38
- schema_defn.tracer(self::Tracer)
26
+ def self.use(schema_defn, legacy: false)
27
+ tracer = if legacy
28
+ self::LegacyTracer
29
+ else
30
+ self::Tracer
31
+ end
32
+ schema_defn.tracer(tracer)
39
33
  end
40
34
 
41
35
  def initialize(context, value: nil)
@@ -51,5 +45,20 @@ module GraphQL
51
45
  def to_a
52
46
  @table.to_backtrace
53
47
  end
48
+
49
+ # Used for internal bookkeeping
50
+ # @api private
51
+ class Frame
52
+ attr_reader :path, :query, :ast_node, :object, :field, :arguments, :parent_frame
53
+ def initialize(path:, query:, ast_node:, object:, field:, arguments:, parent_frame:)
54
+ @path = path
55
+ @query = query
56
+ @ast_node = ast_node
57
+ @field = field
58
+ @object = object
59
+ @arguments = arguments
60
+ @parent_frame = parent_frame
61
+ end
62
+ end
54
63
  end
55
64
  end