graphql 1.11.3 → 1.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (180) hide show
  1. checksums.yaml +4 -4
  2. data/lib/generators/graphql/core.rb +8 -0
  3. data/lib/generators/graphql/install_generator.rb +5 -5
  4. data/lib/generators/graphql/object_generator.rb +2 -0
  5. data/lib/generators/graphql/relay_generator.rb +63 -0
  6. data/lib/generators/graphql/templates/base_argument.erb +2 -0
  7. data/lib/generators/graphql/templates/base_connection.erb +8 -0
  8. data/lib/generators/graphql/templates/base_edge.erb +8 -0
  9. data/lib/generators/graphql/templates/base_enum.erb +2 -0
  10. data/lib/generators/graphql/templates/base_field.erb +2 -0
  11. data/lib/generators/graphql/templates/base_input_object.erb +2 -0
  12. data/lib/generators/graphql/templates/base_interface.erb +2 -0
  13. data/lib/generators/graphql/templates/base_mutation.erb +2 -0
  14. data/lib/generators/graphql/templates/base_object.erb +2 -0
  15. data/lib/generators/graphql/templates/base_scalar.erb +2 -0
  16. data/lib/generators/graphql/templates/base_union.erb +2 -0
  17. data/lib/generators/graphql/templates/enum.erb +2 -0
  18. data/lib/generators/graphql/templates/graphql_controller.erb +2 -0
  19. data/lib/generators/graphql/templates/interface.erb +2 -0
  20. data/lib/generators/graphql/templates/loader.erb +2 -0
  21. data/lib/generators/graphql/templates/mutation.erb +2 -0
  22. data/lib/generators/graphql/templates/mutation_type.erb +2 -0
  23. data/lib/generators/graphql/templates/node_type.erb +9 -0
  24. data/lib/generators/graphql/templates/object.erb +3 -1
  25. data/lib/generators/graphql/templates/query_type.erb +3 -3
  26. data/lib/generators/graphql/templates/scalar.erb +2 -0
  27. data/lib/generators/graphql/templates/schema.erb +10 -35
  28. data/lib/generators/graphql/templates/union.erb +3 -1
  29. data/lib/graphql.rb +55 -4
  30. data/lib/graphql/analysis/analyze_query.rb +7 -0
  31. data/lib/graphql/analysis/ast.rb +11 -2
  32. data/lib/graphql/analysis/ast/visitor.rb +9 -1
  33. data/lib/graphql/argument.rb +3 -3
  34. data/lib/graphql/backtrace.rb +28 -19
  35. data/lib/graphql/backtrace/legacy_tracer.rb +56 -0
  36. data/lib/graphql/backtrace/table.rb +22 -2
  37. data/lib/graphql/backtrace/tracer.rb +40 -8
  38. data/lib/graphql/backwards_compatibility.rb +1 -0
  39. data/lib/graphql/compatibility/execution_specification.rb +1 -0
  40. data/lib/graphql/compatibility/lazy_execution_specification.rb +2 -0
  41. data/lib/graphql/compatibility/query_parser_specification.rb +2 -0
  42. data/lib/graphql/compatibility/schema_parser_specification.rb +2 -0
  43. data/lib/graphql/dataloader.rb +197 -0
  44. data/lib/graphql/dataloader/null_dataloader.rb +21 -0
  45. data/lib/graphql/dataloader/request.rb +24 -0
  46. data/lib/graphql/dataloader/request_all.rb +22 -0
  47. data/lib/graphql/dataloader/source.rb +93 -0
  48. data/lib/graphql/define/assign_global_id_field.rb +2 -2
  49. data/lib/graphql/define/instance_definable.rb +32 -2
  50. data/lib/graphql/define/type_definer.rb +5 -5
  51. data/lib/graphql/deprecated_dsl.rb +5 -0
  52. data/lib/graphql/enum_type.rb +2 -0
  53. data/lib/graphql/execution/errors.rb +4 -0
  54. data/lib/graphql/execution/execute.rb +7 -0
  55. data/lib/graphql/execution/interpreter.rb +20 -6
  56. data/lib/graphql/execution/interpreter/arguments.rb +57 -5
  57. data/lib/graphql/execution/interpreter/arguments_cache.rb +8 -0
  58. data/lib/graphql/execution/interpreter/handles_raw_value.rb +0 -7
  59. data/lib/graphql/execution/interpreter/runtime.rb +251 -138
  60. data/lib/graphql/execution/multiplex.rb +20 -6
  61. data/lib/graphql/function.rb +4 -0
  62. data/lib/graphql/input_object_type.rb +2 -0
  63. data/lib/graphql/integer_decoding_error.rb +17 -0
  64. data/lib/graphql/interface_type.rb +3 -1
  65. data/lib/graphql/introspection.rb +96 -0
  66. data/lib/graphql/introspection/field_type.rb +7 -3
  67. data/lib/graphql/introspection/input_value_type.rb +6 -0
  68. data/lib/graphql/introspection/introspection_query.rb +6 -92
  69. data/lib/graphql/introspection/type_type.rb +7 -3
  70. data/lib/graphql/invalid_null_error.rb +1 -1
  71. data/lib/graphql/language/block_string.rb +24 -5
  72. data/lib/graphql/language/document_from_schema_definition.rb +50 -23
  73. data/lib/graphql/language/lexer.rb +7 -3
  74. data/lib/graphql/language/lexer.rl +7 -3
  75. data/lib/graphql/language/nodes.rb +1 -1
  76. data/lib/graphql/language/parser.rb +107 -103
  77. data/lib/graphql/language/parser.y +4 -0
  78. data/lib/graphql/language/sanitized_printer.rb +59 -26
  79. data/lib/graphql/name_validator.rb +6 -7
  80. data/lib/graphql/object_type.rb +2 -0
  81. data/lib/graphql/pagination/connection.rb +5 -1
  82. data/lib/graphql/pagination/connections.rb +15 -17
  83. data/lib/graphql/query.rb +8 -3
  84. data/lib/graphql/query/context.rb +38 -4
  85. data/lib/graphql/query/fingerprint.rb +2 -0
  86. data/lib/graphql/query/serial_execution.rb +1 -0
  87. data/lib/graphql/query/validation_pipeline.rb +4 -1
  88. data/lib/graphql/relay/array_connection.rb +2 -2
  89. data/lib/graphql/relay/base_connection.rb +7 -0
  90. data/lib/graphql/relay/connection_instrumentation.rb +4 -4
  91. data/lib/graphql/relay/connection_type.rb +1 -1
  92. data/lib/graphql/relay/mutation.rb +1 -0
  93. data/lib/graphql/relay/node.rb +3 -0
  94. data/lib/graphql/relay/range_add.rb +14 -5
  95. data/lib/graphql/relay/type_extensions.rb +2 -0
  96. data/lib/graphql/scalar_type.rb +2 -0
  97. data/lib/graphql/schema.rb +107 -38
  98. data/lib/graphql/schema/argument.rb +74 -5
  99. data/lib/graphql/schema/build_from_definition.rb +203 -86
  100. data/lib/graphql/schema/default_type_error.rb +2 -0
  101. data/lib/graphql/schema/directive.rb +76 -0
  102. data/lib/graphql/schema/directive/deprecated.rb +1 -1
  103. data/lib/graphql/schema/directive/flagged.rb +57 -0
  104. data/lib/graphql/schema/enum.rb +3 -0
  105. data/lib/graphql/schema/enum_value.rb +12 -6
  106. data/lib/graphql/schema/field.rb +59 -24
  107. data/lib/graphql/schema/field/connection_extension.rb +11 -9
  108. data/lib/graphql/schema/field/scope_extension.rb +1 -1
  109. data/lib/graphql/schema/input_object.rb +38 -25
  110. data/lib/graphql/schema/interface.rb +2 -1
  111. data/lib/graphql/schema/late_bound_type.rb +2 -2
  112. data/lib/graphql/schema/loader.rb +1 -0
  113. data/lib/graphql/schema/member.rb +4 -0
  114. data/lib/graphql/schema/member/base_dsl_methods.rb +1 -0
  115. data/lib/graphql/schema/member/build_type.rb +17 -7
  116. data/lib/graphql/schema/member/has_arguments.rb +70 -51
  117. data/lib/graphql/schema/member/has_deprecation_reason.rb +25 -0
  118. data/lib/graphql/schema/member/has_directives.rb +98 -0
  119. data/lib/graphql/schema/member/has_fields.rb +2 -2
  120. data/lib/graphql/schema/member/has_validators.rb +31 -0
  121. data/lib/graphql/schema/member/type_system_helpers.rb +3 -3
  122. data/lib/graphql/schema/object.rb +11 -0
  123. data/lib/graphql/schema/printer.rb +5 -4
  124. data/lib/graphql/schema/relay_classic_mutation.rb +4 -2
  125. data/lib/graphql/schema/resolver.rb +7 -0
  126. data/lib/graphql/schema/resolver/has_payload_type.rb +2 -0
  127. data/lib/graphql/schema/subscription.rb +20 -12
  128. data/lib/graphql/schema/timeout.rb +29 -15
  129. data/lib/graphql/schema/timeout_middleware.rb +2 -0
  130. data/lib/graphql/schema/unique_within_type.rb +1 -2
  131. data/lib/graphql/schema/validation.rb +10 -0
  132. data/lib/graphql/schema/validator.rb +163 -0
  133. data/lib/graphql/schema/validator/exclusion_validator.rb +31 -0
  134. data/lib/graphql/schema/validator/format_validator.rb +49 -0
  135. data/lib/graphql/schema/validator/inclusion_validator.rb +33 -0
  136. data/lib/graphql/schema/validator/length_validator.rb +57 -0
  137. data/lib/graphql/schema/validator/numericality_validator.rb +71 -0
  138. data/lib/graphql/schema/validator/required_validator.rb +68 -0
  139. data/lib/graphql/schema/warden.rb +2 -3
  140. data/lib/graphql/static_validation.rb +1 -0
  141. data/lib/graphql/static_validation/all_rules.rb +1 -0
  142. data/lib/graphql/static_validation/rules/fields_will_merge.rb +25 -17
  143. data/lib/graphql/static_validation/rules/input_object_names_are_unique.rb +30 -0
  144. data/lib/graphql/static_validation/rules/input_object_names_are_unique_error.rb +30 -0
  145. data/lib/graphql/static_validation/validation_timeout_error.rb +25 -0
  146. data/lib/graphql/static_validation/validator.rb +31 -7
  147. data/lib/graphql/subscriptions.rb +23 -16
  148. data/lib/graphql/subscriptions/action_cable_subscriptions.rb +21 -7
  149. data/lib/graphql/tracing.rb +2 -2
  150. data/lib/graphql/tracing/appoptics_tracing.rb +12 -2
  151. data/lib/graphql/tracing/platform_tracing.rb +4 -2
  152. data/lib/graphql/tracing/prometheus_tracing/graphql_collector.rb +4 -1
  153. data/lib/graphql/tracing/skylight_tracing.rb +1 -1
  154. data/lib/graphql/types/int.rb +9 -2
  155. data/lib/graphql/types/iso_8601_date_time.rb +2 -1
  156. data/lib/graphql/types/relay.rb +11 -3
  157. data/lib/graphql/types/relay/base_connection.rb +2 -90
  158. data/lib/graphql/types/relay/base_edge.rb +2 -34
  159. data/lib/graphql/types/relay/connection_behaviors.rb +123 -0
  160. data/lib/graphql/types/relay/default_relay.rb +27 -0
  161. data/lib/graphql/types/relay/edge_behaviors.rb +42 -0
  162. data/lib/graphql/types/relay/has_node_field.rb +41 -0
  163. data/lib/graphql/types/relay/has_nodes_field.rb +41 -0
  164. data/lib/graphql/types/relay/node.rb +2 -4
  165. data/lib/graphql/types/relay/node_behaviors.rb +15 -0
  166. data/lib/graphql/types/relay/node_field.rb +1 -19
  167. data/lib/graphql/types/relay/nodes_field.rb +1 -19
  168. data/lib/graphql/types/relay/page_info.rb +2 -14
  169. data/lib/graphql/types/relay/page_info_behaviors.rb +25 -0
  170. data/lib/graphql/types/string.rb +7 -1
  171. data/lib/graphql/unauthorized_error.rb +1 -1
  172. data/lib/graphql/union_type.rb +2 -0
  173. data/lib/graphql/upgrader/member.rb +1 -0
  174. data/lib/graphql/upgrader/schema.rb +1 -0
  175. data/lib/graphql/version.rb +1 -1
  176. data/readme.md +1 -1
  177. metadata +38 -9
  178. data/lib/graphql/types/relay/base_field.rb +0 -22
  179. data/lib/graphql/types/relay/base_interface.rb +0 -29
  180. 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: 8f64724e3b46476cf0a622ef5d5d1beb4360c7d5de031907d5173cb462928ee4
4
- data.tar.gz: 9b8098bab2bfdc704bf98dc011a452f1bce8c480c9435f1b37a79430ee81bc06
3
+ metadata.gz: 433f1170eb17ab192761efcd8c27cf9efe5f952ab47b501baca270e33d6007cd
4
+ data.tar.gz: c56045f746385ae37ebd0f82116aad10782e9265c13e0e85e39488ef3db02c74
5
5
  SHA512:
6
- metadata.gz: 6dabc15fe0688fc37233e23f5bc5647bf55ad176456257c088e15a87f7fabc07b6da43e86efcd9e982ecfc8b47c6eca331a0ced9a82f20076c21aa4ccf20f223
7
- data.tar.gz: d98a3193ab5759d206aabf9db378c38c669cbc2752f4b8908484fcf2cbee9012f00721403ffe999cd19e43016a6b27bd2c0f5f1dc602b93543772f1e7a4791b5
6
+ metadata.gz: 6d580c78b6b659602067fcfd3043eff7ef2b20da1d50c1ca2b234614d864e1a232cb65e7456cfdf85764523f30bd5232823ea19b4664208aef875cc68e2e5fc9
7
+ data.tar.gz: 172bc16fadfeee1f022646498dd2ce359bd885fb96ddbeeab50f7583d27811501e583194dd582a7cf47d63545c2fe00c4fa4625b6b247155f537ff4a6de60ac1
@@ -41,6 +41,14 @@ module Graphql
41
41
  end
42
42
  end
43
43
 
44
+ def module_namespacing_when_supported
45
+ if defined?(module_namespacing)
46
+ module_namespacing { yield }
47
+ else
48
+ yield
49
+ end
50
+ end
51
+
44
52
  private
45
53
 
46
54
  def schema_name
@@ -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
@@ -1,4 +1,6 @@
1
+ <% module_namespacing_when_supported do -%>
1
2
  module Types
2
3
  class BaseArgument < GraphQL::Schema::Argument
3
4
  end
4
5
  end
6
+ <% 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 -%>
@@ -1,4 +1,6 @@
1
+ <% module_namespacing_when_supported do -%>
1
2
  module Types
2
3
  class BaseEnum < GraphQL::Schema::Enum
3
4
  end
4
5
  end
6
+ <% end -%>
@@ -1,5 +1,7 @@
1
+ <% module_namespacing_when_supported do -%>
1
2
  module Types
2
3
  class BaseField < GraphQL::Schema::Field
3
4
  argument_class Types::BaseArgument
4
5
  end
5
6
  end
7
+ <% end -%>
@@ -1,5 +1,7 @@
1
+ <% module_namespacing_when_supported do -%>
1
2
  module Types
2
3
  class BaseInputObject < GraphQL::Schema::InputObject
3
4
  argument_class Types::BaseArgument
4
5
  end
5
6
  end
7
+ <% end -%>
@@ -1,3 +1,4 @@
1
+ <% module_namespacing_when_supported do -%>
1
2
  module Types
2
3
  module BaseInterface
3
4
  include GraphQL::Schema::Interface
@@ -5,3 +6,4 @@ module Types
5
6
  field_class Types::BaseField
6
7
  end
7
8
  end
9
+ <% end -%>
@@ -1,3 +1,4 @@
1
+ <% module_namespacing_when_supported do -%>
1
2
  module Mutations
2
3
  class BaseMutation < GraphQL::Schema::RelayClassicMutation
3
4
  argument_class Types::BaseArgument
@@ -6,3 +7,4 @@ module Mutations
6
7
  object_class Types::BaseObject
7
8
  end
8
9
  end
10
+ <% end -%>
@@ -1,5 +1,7 @@
1
+ <% module_namespacing_when_supported do -%>
1
2
  module Types
2
3
  class BaseObject < GraphQL::Schema::Object
3
4
  field_class Types::BaseField
4
5
  end
5
6
  end
7
+ <% end -%>
@@ -1,4 +1,6 @@
1
+ <% module_namespacing_when_supported do -%>
1
2
  module Types
2
3
  class BaseScalar < GraphQL::Schema::Scalar
3
4
  end
4
5
  end
6
+ <% end -%>
@@ -1,4 +1,6 @@
1
+ <% module_namespacing_when_supported do -%>
1
2
  module Types
2
3
  class BaseUnion < GraphQL::Schema::Union
3
4
  end
4
5
  end
6
+ <% end -%>
@@ -1,5 +1,7 @@
1
+ <% module_namespacing_when_supported do -%>
1
2
  module Types
2
3
  class <%= type_ruby_name.split('::')[-1] %> < Types::BaseEnum
3
4
  <% prepared_values.each do |v| %> value "<%= v[0] %>"<%= v.length > 1 ? ", value: #{v[1]}" : "" %>
4
5
  <% end %> end
5
6
  end
7
+ <% end -%>
@@ -1,3 +1,4 @@
1
+ <% module_namespacing_when_supported do -%>
1
2
  class GraphqlController < ApplicationController
2
3
  # If accessing from outside this domain, nullify the session
3
4
  # This allows for outside API access while preventing CSRF attacks,
@@ -48,3 +49,4 @@ class GraphqlController < ApplicationController
48
49
  render json: { errors: [{ message: e.message, backtrace: e.backtrace }], data: {} }, status: 500
49
50
  end
50
51
  end
52
+ <% end -%>
@@ -1,6 +1,8 @@
1
+ <% module_namespacing_when_supported do -%>
1
2
  module Types
2
3
  module <%= type_ruby_name.split('::')[-1] %>
3
4
  include Types::BaseInterface
4
5
  <% normalized_fields.each do |f| %> <%= f.to_ruby %>
5
6
  <% end %> end
6
7
  end
8
+ <% end -%>
@@ -1,3 +1,4 @@
1
+ <% module_namespacing_when_supported do -%>
1
2
  module Loaders
2
3
  class <%= class_name %> < GraphQL::Batch::Loader
3
4
  # Define `initialize` to store grouping arguments, eg
@@ -15,3 +16,4 @@ module Loaders
15
16
  end
16
17
  end
17
18
  end
19
+ <% end -%>
@@ -1,3 +1,4 @@
1
+ <% module_namespacing_when_supported do -%>
1
2
  module Mutations
2
3
  class <%= mutation_name %> < BaseMutation
3
4
  # TODO: define return fields
@@ -12,3 +13,4 @@ module Mutations
12
13
  # end
13
14
  end
14
15
  end
16
+ <% end -%>
@@ -1,3 +1,4 @@
1
+ <% module_namespacing_when_supported do -%>
1
2
  module Types
2
3
  class MutationType < Types::BaseObject
3
4
  # TODO: remove me
@@ -8,3 +9,4 @@ module Types
8
9
  end
9
10
  end
10
11
  end
12
+ <% 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,6 +1,8 @@
1
+ <% module_namespacing_when_supported do -%>
1
2
  module Types
2
3
  class <%= type_ruby_name.split('::')[-1] %> < Types::BaseObject
3
- <% if options.node %> implements GraphQL::Relay::Node.interface
4
+ <% if options.node %> implements GraphQL::Types::Relay::Node
4
5
  <% end %><% normalized_fields.each do |f| %> <%= f.to_ruby %>
5
6
  <% end %> end
6
7
  end
8
+ <% end -%>
@@ -1,3 +1,4 @@
1
+ <% module_namespacing_when_supported do -%>
1
2
  module Types
2
3
  class QueryType < Types::BaseObject
3
4
  # Add root-level fields here.
@@ -9,7 +10,6 @@ module Types
9
10
  def test_field
10
11
  "Hello World!"
11
12
  end
12
- <% if options[:relay] %>
13
- field :node, field: GraphQL::Relay::Node.field
14
- <% end %> end
13
+ end
15
14
  end
15
+ <% end -%>
@@ -1,3 +1,4 @@
1
+ <% module_namespacing_when_supported do -%>
1
2
  module Types
2
3
  class <%= type_ruby_name.split('::')[-1] %> < Types::BaseScalar
3
4
  def self.coerce_input(input_value, context)
@@ -11,3 +12,4 @@ module Types
11
12
  end
12
13
  end
13
14
  end
15
+ <% end -%>
@@ -1,40 +1,15 @@
1
+ <% module_namespacing_when_supported do -%>
1
2
  class <%= schema_name %> < GraphQL::Schema
2
3
  query(Types::QueryType)
3
-
4
- # Opt in to the new runtime (default in future graphql-ruby versions)
5
- use GraphQL::Execution::Interpreter
6
- use GraphQL::Analysis::AST
7
-
8
- # Add built-in connections for pagination
9
- use GraphQL::Pagination::Connections
10
- <% if options[:relay] %>
11
- # Relay Object Identification:
12
-
13
- # Return a string UUID for `object`
14
- def self.id_from_object(object, type_definition, query_ctx)
15
- # Here's a simple implementation which:
16
- # - joins the type name & object.id
17
- # - encodes it with base64:
18
- # GraphQL::Schema::UniqueWithinType.encode(type_definition.name, object.id)
19
- end
20
-
21
- # Given a string UUID, find the object
22
- def self.object_from_id(id, query_ctx)
23
- # For example, to decode the UUIDs generated above:
24
- # type_name, item_id = GraphQL::Schema::UniqueWithinType.decode(id)
25
- #
26
- # Then, based on `type_name` and `id`
27
- # find an object in your application
28
- # ...
29
- end
30
-
31
- # Object Resolution
32
- 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)
33
10
  # TODO: Implement this function
34
- # to return the correct type for `obj`
11
+ # to return the correct object type for `obj`
35
12
  raise(GraphQL::RequiredImplementationMissingError)
36
13
  end
37
- <% end %><% if options[:batch] %>
38
- # GraphQL::Batch setup:
39
- use GraphQL::Batch
40
- <% end %>end
14
+ end
15
+ <% end -%>
@@ -1,5 +1,7 @@
1
+ <% module_namespacing_when_supported do -%>
1
2
  module Types
2
3
  class <%= type_ruby_name.split('::')[-1] %> < Types::BaseUnion
3
- <% if possible_types.any? %> possible_types [<%= normalized_possible_types.join(", ") %>]
4
+ <% if possible_types.any? %> possible_types <%= normalized_possible_types.join(", ") %>
4
5
  <% end %> end
5
6
  end
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