graphql 1.11.4 → 1.12.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (160) hide show
  1. checksums.yaml +4 -4
  2. data/lib/generators/graphql/install_generator.rb +5 -5
  3. data/lib/generators/graphql/object_generator.rb +2 -0
  4. data/lib/generators/graphql/relay_generator.rb +63 -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/generators/graphql/templates/union.erb +1 -1
  12. data/lib/graphql.rb +55 -4
  13. data/lib/graphql/analysis/analyze_query.rb +7 -0
  14. data/lib/graphql/analysis/ast.rb +11 -2
  15. data/lib/graphql/analysis/ast/visitor.rb +9 -1
  16. data/lib/graphql/argument.rb +3 -3
  17. data/lib/graphql/backtrace.rb +28 -19
  18. data/lib/graphql/backtrace/legacy_tracer.rb +56 -0
  19. data/lib/graphql/backtrace/table.rb +22 -2
  20. data/lib/graphql/backtrace/tracer.rb +40 -8
  21. data/lib/graphql/backwards_compatibility.rb +1 -0
  22. data/lib/graphql/compatibility/execution_specification.rb +1 -0
  23. data/lib/graphql/compatibility/lazy_execution_specification.rb +2 -0
  24. data/lib/graphql/compatibility/query_parser_specification.rb +2 -0
  25. data/lib/graphql/compatibility/schema_parser_specification.rb +2 -0
  26. data/lib/graphql/dataloader.rb +198 -0
  27. data/lib/graphql/dataloader/null_dataloader.rb +21 -0
  28. data/lib/graphql/dataloader/request.rb +24 -0
  29. data/lib/graphql/dataloader/request_all.rb +22 -0
  30. data/lib/graphql/dataloader/source.rb +93 -0
  31. data/lib/graphql/define/assign_global_id_field.rb +2 -2
  32. data/lib/graphql/define/instance_definable.rb +32 -2
  33. data/lib/graphql/define/type_definer.rb +5 -5
  34. data/lib/graphql/deprecated_dsl.rb +5 -0
  35. data/lib/graphql/enum_type.rb +2 -0
  36. data/lib/graphql/execution/errors.rb +4 -0
  37. data/lib/graphql/execution/execute.rb +7 -0
  38. data/lib/graphql/execution/interpreter.rb +20 -6
  39. data/lib/graphql/execution/interpreter/arguments.rb +57 -5
  40. data/lib/graphql/execution/interpreter/arguments_cache.rb +8 -0
  41. data/lib/graphql/execution/interpreter/handles_raw_value.rb +0 -7
  42. data/lib/graphql/execution/interpreter/runtime.rb +236 -120
  43. data/lib/graphql/execution/multiplex.rb +20 -6
  44. data/lib/graphql/function.rb +4 -0
  45. data/lib/graphql/input_object_type.rb +2 -0
  46. data/lib/graphql/integer_decoding_error.rb +17 -0
  47. data/lib/graphql/interface_type.rb +3 -1
  48. data/lib/graphql/introspection.rb +96 -0
  49. data/lib/graphql/introspection/field_type.rb +7 -3
  50. data/lib/graphql/introspection/input_value_type.rb +6 -0
  51. data/lib/graphql/introspection/introspection_query.rb +6 -92
  52. data/lib/graphql/introspection/type_type.rb +7 -3
  53. data/lib/graphql/invalid_null_error.rb +1 -1
  54. data/lib/graphql/language/block_string.rb +24 -5
  55. data/lib/graphql/language/document_from_schema_definition.rb +50 -23
  56. data/lib/graphql/language/lexer.rb +7 -3
  57. data/lib/graphql/language/lexer.rl +7 -3
  58. data/lib/graphql/language/nodes.rb +1 -1
  59. data/lib/graphql/language/parser.rb +107 -103
  60. data/lib/graphql/language/parser.y +4 -0
  61. data/lib/graphql/language/sanitized_printer.rb +59 -26
  62. data/lib/graphql/name_validator.rb +6 -7
  63. data/lib/graphql/object_type.rb +2 -0
  64. data/lib/graphql/pagination/connection.rb +5 -1
  65. data/lib/graphql/pagination/connections.rb +15 -17
  66. data/lib/graphql/query.rb +8 -3
  67. data/lib/graphql/query/context.rb +18 -3
  68. data/lib/graphql/query/serial_execution.rb +1 -0
  69. data/lib/graphql/query/validation_pipeline.rb +1 -1
  70. data/lib/graphql/relay/array_connection.rb +2 -2
  71. data/lib/graphql/relay/base_connection.rb +7 -0
  72. data/lib/graphql/relay/connection_instrumentation.rb +4 -4
  73. data/lib/graphql/relay/connection_type.rb +1 -1
  74. data/lib/graphql/relay/mutation.rb +1 -0
  75. data/lib/graphql/relay/node.rb +3 -0
  76. data/lib/graphql/relay/range_add.rb +14 -5
  77. data/lib/graphql/relay/type_extensions.rb +2 -0
  78. data/lib/graphql/scalar_type.rb +2 -0
  79. data/lib/graphql/schema.rb +104 -39
  80. data/lib/graphql/schema/argument.rb +74 -5
  81. data/lib/graphql/schema/build_from_definition.rb +203 -86
  82. data/lib/graphql/schema/default_type_error.rb +2 -0
  83. data/lib/graphql/schema/directive.rb +76 -0
  84. data/lib/graphql/schema/directive/deprecated.rb +1 -1
  85. data/lib/graphql/schema/directive/flagged.rb +57 -0
  86. data/lib/graphql/schema/enum.rb +3 -0
  87. data/lib/graphql/schema/enum_value.rb +12 -6
  88. data/lib/graphql/schema/field.rb +59 -24
  89. data/lib/graphql/schema/field/connection_extension.rb +10 -8
  90. data/lib/graphql/schema/field/scope_extension.rb +1 -1
  91. data/lib/graphql/schema/input_object.rb +38 -25
  92. data/lib/graphql/schema/interface.rb +2 -1
  93. data/lib/graphql/schema/late_bound_type.rb +2 -2
  94. data/lib/graphql/schema/loader.rb +1 -0
  95. data/lib/graphql/schema/member.rb +4 -0
  96. data/lib/graphql/schema/member/base_dsl_methods.rb +1 -0
  97. data/lib/graphql/schema/member/build_type.rb +17 -7
  98. data/lib/graphql/schema/member/has_arguments.rb +70 -51
  99. data/lib/graphql/schema/member/has_deprecation_reason.rb +25 -0
  100. data/lib/graphql/schema/member/has_directives.rb +98 -0
  101. data/lib/graphql/schema/member/has_fields.rb +2 -2
  102. data/lib/graphql/schema/member/has_validators.rb +31 -0
  103. data/lib/graphql/schema/member/type_system_helpers.rb +3 -3
  104. data/lib/graphql/schema/object.rb +11 -0
  105. data/lib/graphql/schema/printer.rb +5 -4
  106. data/lib/graphql/schema/relay_classic_mutation.rb +4 -2
  107. data/lib/graphql/schema/resolver.rb +7 -0
  108. data/lib/graphql/schema/resolver/has_payload_type.rb +2 -0
  109. data/lib/graphql/schema/subscription.rb +19 -1
  110. data/lib/graphql/schema/timeout.rb +29 -15
  111. data/lib/graphql/schema/timeout_middleware.rb +2 -0
  112. data/lib/graphql/schema/unique_within_type.rb +1 -2
  113. data/lib/graphql/schema/validation.rb +10 -0
  114. data/lib/graphql/schema/validator.rb +163 -0
  115. data/lib/graphql/schema/validator/exclusion_validator.rb +31 -0
  116. data/lib/graphql/schema/validator/format_validator.rb +49 -0
  117. data/lib/graphql/schema/validator/inclusion_validator.rb +33 -0
  118. data/lib/graphql/schema/validator/length_validator.rb +57 -0
  119. data/lib/graphql/schema/validator/numericality_validator.rb +71 -0
  120. data/lib/graphql/schema/validator/required_validator.rb +68 -0
  121. data/lib/graphql/static_validation.rb +1 -0
  122. data/lib/graphql/static_validation/all_rules.rb +1 -0
  123. data/lib/graphql/static_validation/rules/fields_will_merge.rb +25 -17
  124. data/lib/graphql/static_validation/rules/input_object_names_are_unique.rb +30 -0
  125. data/lib/graphql/static_validation/rules/input_object_names_are_unique_error.rb +30 -0
  126. data/lib/graphql/static_validation/validation_timeout_error.rb +25 -0
  127. data/lib/graphql/static_validation/validator.rb +33 -7
  128. data/lib/graphql/subscriptions.rb +18 -23
  129. data/lib/graphql/subscriptions/action_cable_subscriptions.rb +21 -7
  130. data/lib/graphql/tracing.rb +2 -2
  131. data/lib/graphql/tracing/appoptics_tracing.rb +3 -1
  132. data/lib/graphql/tracing/platform_tracing.rb +4 -2
  133. data/lib/graphql/tracing/prometheus_tracing/graphql_collector.rb +4 -1
  134. data/lib/graphql/tracing/skylight_tracing.rb +1 -1
  135. data/lib/graphql/types/int.rb +9 -2
  136. data/lib/graphql/types/relay.rb +11 -3
  137. data/lib/graphql/types/relay/base_connection.rb +2 -91
  138. data/lib/graphql/types/relay/base_edge.rb +2 -34
  139. data/lib/graphql/types/relay/connection_behaviors.rb +123 -0
  140. data/lib/graphql/types/relay/default_relay.rb +27 -0
  141. data/lib/graphql/types/relay/edge_behaviors.rb +42 -0
  142. data/lib/graphql/types/relay/has_node_field.rb +41 -0
  143. data/lib/graphql/types/relay/has_nodes_field.rb +41 -0
  144. data/lib/graphql/types/relay/node.rb +2 -4
  145. data/lib/graphql/types/relay/node_behaviors.rb +15 -0
  146. data/lib/graphql/types/relay/node_field.rb +1 -19
  147. data/lib/graphql/types/relay/nodes_field.rb +1 -19
  148. data/lib/graphql/types/relay/page_info.rb +2 -14
  149. data/lib/graphql/types/relay/page_info_behaviors.rb +25 -0
  150. data/lib/graphql/types/string.rb +7 -1
  151. data/lib/graphql/unauthorized_error.rb +1 -1
  152. data/lib/graphql/union_type.rb +2 -0
  153. data/lib/graphql/upgrader/member.rb +1 -0
  154. data/lib/graphql/upgrader/schema.rb +1 -0
  155. data/lib/graphql/version.rb +1 -1
  156. data/readme.md +1 -1
  157. metadata +49 -6
  158. data/lib/graphql/types/relay/base_field.rb +0 -22
  159. data/lib/graphql/types/relay/base_interface.rb +0 -29
  160. 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: c5bf42de25927dab863bd600879d33d204c54bdf124b2b4cc5b27c4c16d4f28b
4
- data.tar.gz: 58b21a4dd5ba80ec0f6c3362013a6adb07c2f1af243e5a851d4c3f08554fe09d
3
+ metadata.gz: 292a830cc392302b9cb20a7290b8026bc8c0d56982b64f3675ab0617341a82a6
4
+ data.tar.gz: 3d1b22c24b94f9352e295bf0c3ca714437f3bff82694ca69a075c43fb1c2520a
5
5
  SHA512:
6
- metadata.gz: f199d24a190910e44b189340b6a3d2a3c121ab56ba10ec6cf44d8801107db8d73541f24788b00b13ee7dd357f7bfe6ecff7001f053fe417c777bca59db5851db
7
- data.tar.gz: fd0955c7f67b20370ea376d6a286fdf0ac7272ac5b243d6c309d2159a780cd0b8f92fd0e06ca312a69a16b7c8ad0ebd7bb4587feac9dc77b27da507c9a44cd8f
6
+ metadata.gz: 5711c019ac9b7fcffd0224d8438f5dea04c114a5e170900ec292c3f80a8b672a0a13d4449188888f85c83b4f386a7276a3d91530f38a4bf66df21608711cf95b
7
+ data.tar.gz: 6fb9c18db01f800f9b018dc8c1a1e27c463b6ab7a81f7de59c9d30967f409c25061b779eb672b828058d769b9aebab8c5f45406a373869a893d6b5a5e574572f
@@ -43,9 +43,6 @@ module Graphql
43
43
  # post "/graphql", to: "graphql#execute"
44
44
  # ```
45
45
  #
46
- # Accept a `--relay` option which adds
47
- # The root `node(id: ID!)` field.
48
- #
49
46
  # Accept a `--batch` option which adds `GraphQL::Batch` setup.
50
47
  #
51
48
  # Use `--no-graphiql` to skip `graphiql-rails` installation.
@@ -79,8 +76,8 @@ module Graphql
79
76
 
80
77
  class_option :relay,
81
78
  type: :boolean,
82
- default: false,
83
- desc: "Include GraphQL::Relay installation"
79
+ default: true,
80
+ desc: "Include installation of Relay conventions (nodes, connections, edges)"
84
81
 
85
82
  class_option :batch,
86
83
  type: :boolean,
@@ -164,7 +161,10 @@ if Rails.env.development?
164
161
  RUBY
165
162
  end
166
163
  end
164
+ end
167
165
 
166
+ if options[:relay]
167
+ generate("graphql:relay")
168
168
  end
169
169
 
170
170
  if gemfile_modified?
@@ -40,6 +40,8 @@ module Graphql
40
40
  case type_expression
41
41
  when "Text"
42
42
  ["String", null]
43
+ when "Decimal"
44
+ ["Float", null]
43
45
  when "DateTime", "Datetime"
44
46
  ["GraphQL::Types::ISO8601DateTime", null]
45
47
  when "Date"
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+ require 'rails/generators/base'
3
+ require_relative 'core'
4
+
5
+ module Graphql
6
+ module Generators
7
+ class RelayGenerator < Rails::Generators::Base
8
+ include Core
9
+
10
+ desc "Add base types and fields for Relay-style nodes and connections"
11
+ source_root File.expand_path('../templates', __FILE__)
12
+
13
+ def install_relay
14
+ # Add Node, `node(id:)`, and `nodes(ids:)`
15
+ template("node_type.erb", "#{options[:directory]}/types/node_type.rb")
16
+ in_root do
17
+ fields = " # Add `node(id: ID!) and `nodes(ids: [ID!]!)`\n include GraphQL::Types::Relay::HasNodeField\n include GraphQL::Types::Relay::HasNodesField\n\n"
18
+ inject_into_file "#{options[:directory]}/types/query_type.rb", fields, after: /class .*QueryType\s*<\s*[^\s]+?\n/m, force: false
19
+ end
20
+
21
+ # Add connections and edges
22
+ template("base_connection.erb", "#{options[:directory]}/types/base_connection.rb")
23
+ template("base_edge.erb", "#{options[:directory]}/types/base_edge.rb")
24
+ connectionable_type_files = {
25
+ "#{options[:directory]}/types/base_object.rb" => /class .*BaseObject\s*<\s*[^\s]+?\n/m,
26
+ "#{options[:directory]}/types/base_union.rb" => /class .*BaseUnion\s*<\s*[^\s]+?\n/m,
27
+ "#{options[:directory]}/types/base_interface.rb" => /include GraphQL::Schema::Interface\n/m,
28
+ }
29
+ in_root do
30
+ connectionable_type_files.each do |type_class_file, sentinel|
31
+ inject_into_file type_class_file, " connection_type_class(Types::BaseConnection)\n", after: sentinel, force: false
32
+ inject_into_file type_class_file, " edge_type_class(Types::BaseEdge)\n", after: sentinel, force: false
33
+ end
34
+ end
35
+
36
+ # Add object ID hooks & connection plugin
37
+ schema_code = <<-RUBY
38
+
39
+ # Relay-style Object Identification:
40
+
41
+ # Return a string UUID for `object`
42
+ def self.id_from_object(object, type_definition, query_ctx)
43
+ # Here's a simple implementation which:
44
+ # - joins the type name & object.id
45
+ # - encodes it with base64:
46
+ # GraphQL::Schema::UniqueWithinType.encode(type_definition.name, object.id)
47
+ end
48
+
49
+ # Given a string UUID, find the object
50
+ def self.object_from_id(id, query_ctx)
51
+ # For example, to decode the UUIDs generated above:
52
+ # type_name, item_id = GraphQL::Schema::UniqueWithinType.decode(id)
53
+ #
54
+ # Then, based on `type_name` and `id`
55
+ # find an object in your application
56
+ # ...
57
+ end
58
+ RUBY
59
+ inject_into_file schema_file_path, schema_code, before: /^end\n/m, force: false
60
+ end
61
+ end
62
+ end
63
+ 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 -%>
@@ -1,7 +1,7 @@
1
1
  <% module_namespacing_when_supported do -%>
2
2
  module Types
3
3
  class <%= type_ruby_name.split('::')[-1] %> < Types::BaseUnion
4
- <% if possible_types.any? %> possible_types [<%= normalized_possible_types.join(", ") %>]
4
+ <% if possible_types.any? %> possible_types <%= normalized_possible_types.join(", ") %>
5
5
  <% end %> end
6
6
  end
7
7
  <% end -%>
@@ -21,6 +21,14 @@ module GraphQL
21
21
  class RequiredImplementationMissingError < Error
22
22
  end
23
23
 
24
+ class << self
25
+ def default_parser
26
+ @default_parser ||= GraphQL::Language::Parser
27
+ end
28
+
29
+ attr_writer :default_parser
30
+ end
31
+
24
32
  # Turn a query string or schema definition into an AST
25
33
  # @param graphql_string [String] a GraphQL query string or schema definition
26
34
  # @return [GraphQL::Language::Nodes::Document]
@@ -61,6 +69,14 @@ module GraphQL
61
69
  end
62
70
  end
63
71
  end
72
+
73
+ module StringMatchBackport
74
+ refine String do
75
+ def match?(pattern)
76
+ self =~ pattern
77
+ end
78
+ end
79
+ end
64
80
  end
65
81
 
66
82
  # Order matters for these:
@@ -94,6 +110,7 @@ require "graphql/execution"
94
110
  require "graphql/runtime_type_error"
95
111
  require "graphql/unresolved_type_error"
96
112
  require "graphql/invalid_null_error"
113
+ require "graphql/pagination"
97
114
  require "graphql/schema"
98
115
  require "graphql/query"
99
116
  require "graphql/directive"
@@ -108,19 +125,20 @@ require "graphql/string_type"
108
125
  require "graphql/schema/built_in_types"
109
126
  require "graphql/schema/loader"
110
127
  require "graphql/schema/printer"
128
+ require "graphql/filter"
129
+ require "graphql/internal_representation"
130
+ require "graphql/static_validation"
111
131
  require "graphql/introspection"
112
132
 
113
133
  require "graphql/analysis_error"
114
134
  require "graphql/coercion_error"
115
135
  require "graphql/invalid_name_error"
136
+ require "graphql/integer_decoding_error"
116
137
  require "graphql/integer_encoding_error"
117
138
  require "graphql/string_encoding_error"
118
- require "graphql/internal_representation"
119
- require "graphql/static_validation"
120
139
  require "graphql/version"
121
140
  require "graphql/compatibility"
122
141
  require "graphql/function"
123
- require "graphql/filter"
124
142
  require "graphql/subscriptions"
125
143
  require "graphql/parse_error"
126
144
  require "graphql/backtrace"
@@ -130,4 +148,37 @@ require "graphql/authorization"
130
148
  require "graphql/unauthorized_error"
131
149
  require "graphql/unauthorized_field_error"
132
150
  require "graphql/load_application_object_failed_error"
133
- require "graphql/pagination"
151
+ require "graphql/dataloader"
152
+
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
+ 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
+ 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
 
@@ -3,14 +3,14 @@ module GraphQL
3
3
  # @api deprecated
4
4
  class Argument
5
5
  include GraphQL::Define::InstanceDefinable
6
- accepts_definitions :name, :type, :description, :default_value, :as, :prepare, :method_access
6
+ accepts_definitions :name, :type, :description, :default_value, :as, :prepare, :method_access, :deprecation_reason
7
7
  attr_reader :default_value
8
- attr_accessor :description, :name, :as
8
+ attr_accessor :description, :name, :as, :deprecation_reason
9
9
  attr_accessor :ast_node
10
10
  attr_accessor :method_access
11
11
  alias :graphql_name :name
12
12
 
13
- ensure_defined(:name, :description, :default_value, :type=, :type, :as, :expose_as, :prepare, :method_access)
13
+ ensure_defined(:name, :description, :default_value, :type=, :type, :as, :expose_as, :prepare, :method_access, :deprecation_reason)
14
14
 
15
15
  # @api private
16
16
  module DefaultPrepare
@@ -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