graphql 1.8.6 → 1.8.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +5 -5
  2. data/lib/generators/graphql/mutation_generator.rb +1 -1
  3. data/lib/generators/graphql/templates/base_enum.erb +3 -1
  4. data/lib/generators/graphql/templates/base_input_object.erb +3 -1
  5. data/lib/generators/graphql/templates/base_interface.erb +4 -2
  6. data/lib/generators/graphql/templates/base_object.erb +3 -1
  7. data/lib/generators/graphql/templates/base_union.erb +3 -1
  8. data/lib/generators/graphql/templates/enum.erb +5 -3
  9. data/lib/generators/graphql/templates/interface.erb +6 -4
  10. data/lib/generators/graphql/templates/loader.erb +14 -12
  11. data/lib/generators/graphql/templates/mutation.erb +9 -6
  12. data/lib/generators/graphql/templates/mutation_type.erb +8 -6
  13. data/lib/generators/graphql/templates/object.erb +6 -4
  14. data/lib/generators/graphql/templates/query_type.erb +13 -11
  15. data/lib/generators/graphql/templates/union.erb +5 -3
  16. data/lib/graphql/argument.rb +19 -2
  17. data/lib/graphql/base_type.rb +1 -1
  18. data/lib/graphql/define/instance_definable.rb +2 -0
  19. data/lib/graphql/enum_type.rb +1 -0
  20. data/lib/graphql/execution/instrumentation.rb +28 -20
  21. data/lib/graphql/field.rb +3 -3
  22. data/lib/graphql/input_object_type.rb +2 -1
  23. data/lib/graphql/query.rb +1 -9
  24. data/lib/graphql/query/variables.rb +1 -18
  25. data/lib/graphql/relay.rb +0 -1
  26. data/lib/graphql/relay/mongo_relation_connection.rb +10 -0
  27. data/lib/graphql/relay/mutation.rb +2 -1
  28. data/lib/graphql/schema.rb +5 -4
  29. data/lib/graphql/schema/base_64_bp.rb +25 -0
  30. data/lib/graphql/schema/base_64_encoder.rb +5 -1
  31. data/lib/graphql/schema/field.rb +52 -22
  32. data/lib/graphql/schema/interface.rb +2 -0
  33. data/lib/graphql/schema/list.rb +3 -15
  34. data/lib/graphql/schema/member.rb +8 -4
  35. data/lib/graphql/schema/member/base_dsl_methods.rb +12 -6
  36. data/lib/graphql/schema/member/has_arguments.rb +7 -0
  37. data/lib/graphql/schema/member/relay_shortcuts.rb +47 -0
  38. data/lib/graphql/schema/member/scoped.rb +21 -0
  39. data/lib/graphql/schema/non_null.rb +8 -17
  40. data/lib/graphql/schema/resolver.rb +99 -76
  41. data/lib/graphql/schema/unique_within_type.rb +4 -1
  42. data/lib/graphql/schema/wrapper.rb +29 -0
  43. data/lib/graphql/static_validation/validation_context.rb +1 -3
  44. data/lib/graphql/subscriptions/action_cable_subscriptions.rb +1 -1
  45. data/lib/graphql/type_kinds.rb +32 -8
  46. data/lib/graphql/types/relay/base_connection.rb +17 -3
  47. data/lib/graphql/types/relay/base_edge.rb +12 -0
  48. data/lib/graphql/version.rb +1 -1
  49. data/spec/generators/graphql/enum_generator_spec.rb +8 -6
  50. data/spec/generators/graphql/install_generator_spec.rb +24 -20
  51. data/spec/generators/graphql/interface_generator_spec.rb +6 -4
  52. data/spec/generators/graphql/loader_generator_spec.rb +30 -26
  53. data/spec/generators/graphql/mutation_generator_spec.rb +18 -13
  54. data/spec/generators/graphql/object_generator_spec.rb +12 -6
  55. data/spec/generators/graphql/union_generator_spec.rb +10 -4
  56. data/spec/graphql/authorization_spec.rb +55 -14
  57. data/spec/graphql/input_object_type_spec.rb +11 -0
  58. data/spec/graphql/language/generation_spec.rb +8 -6
  59. data/spec/graphql/language/nodes_spec.rb +8 -6
  60. data/spec/graphql/relay/connection_instrumentation_spec.rb +1 -1
  61. data/spec/graphql/relay/mongo_relation_connection_spec.rb +54 -0
  62. data/spec/graphql/schema/field_spec.rb +9 -0
  63. data/spec/graphql/schema/list_spec.rb +46 -0
  64. data/spec/graphql/schema/member/scoped_spec.rb +161 -0
  65. data/spec/graphql/schema/non_null_spec.rb +46 -0
  66. data/spec/graphql/schema/object_spec.rb +15 -0
  67. data/spec/graphql/schema/resolver_spec.rb +165 -25
  68. data/spec/graphql/subscriptions/serialize_spec.rb +0 -22
  69. data/spec/graphql/subscriptions_spec.rb +19 -31
  70. data/spec/support/global_id.rb +23 -0
  71. data/spec/support/lazy_helpers.rb +1 -1
  72. data/spec/support/star_trek/data.rb +19 -2
  73. data/spec/support/star_trek/schema.rb +37 -22
  74. data/spec/support/star_wars/schema.rb +24 -17
  75. metadata +220 -208
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: dd6e04d78aeb4850499bfa484e9482100ec3f67c536d4d9f3b327689c1425480
4
- data.tar.gz: 7ce2e0d06bd709d7ae9c7fb131656ddd5c7dca36fdf4fa2edb5727f73f213b74
2
+ SHA1:
3
+ metadata.gz: a2aa5dc86bfb37cc0c46b7974618bddc91b203b0
4
+ data.tar.gz: 92979d239d0fbd9a010261dec5d0b1285c617c3f
5
5
  SHA512:
6
- metadata.gz: 0e99115b2252b94e62536c6cad695d0a036ad7065088d5c7071aef3037aff58179aba02c199f68f18adaaec3a3cf1def9048c69946b7256170233a0fc989ee8d
7
- data.tar.gz: 047d6ff12f0f9937829f77f9db0febe25e9fc70cc4810dde9700f9c5f83931b4e7de2b5e6ffa7c2a9d30407fd56fff0e0f0d38c4af9e3233d94bc4ae8090bad7
6
+ metadata.gz: 26ccb7f54465c14158a933a4bbc52eaba9576725ea06ce1a5425128fd39ad133013383ffa650bc6bbbdf16030bf232ab021da6a1c39ee20933d294b49d5d8d57
7
+ data.tar.gz: 7ec6717d6a3cf091189269e92d991cd49fdec20802d68cb7c83d60b9ab615535ad626c8163a5022e713f4c9f875bfaec1430b51098ec3e55eca5e91ff6e1a622
@@ -38,7 +38,7 @@ module Graphql
38
38
  sentinel = /class .*MutationType\s*<\s*[^\s]+?\n/m
39
39
  in_root do
40
40
  gsub_file "#{options[:directory]}/types/mutation_type.rb", / \# TODO\: Add Mutations as fields\s*\n/m, ""
41
- inject_into_file "#{options[:directory]}/types/mutation_type.rb", " field :#{field_name}, mutation: Mutations::#{mutation_name}\n", after: sentinel, verbose: false, force: false
41
+ inject_into_file "#{options[:directory]}/types/mutation_type.rb", " field :#{field_name}, mutation: Mutations::#{mutation_name}\n", after: sentinel, verbose: false, force: false
42
42
  end
43
43
  end
44
44
 
@@ -1,2 +1,4 @@
1
- class Types::BaseEnum < GraphQL::Schema::Enum
1
+ module Types
2
+ class BaseEnum < GraphQL::Schema::Enum
3
+ end
2
4
  end
@@ -1,2 +1,4 @@
1
- class Types::BaseInputObject < GraphQL::Schema::InputObject
1
+ module Types
2
+ class BaseInputObject < GraphQL::Schema::InputObject
3
+ end
2
4
  end
@@ -1,3 +1,5 @@
1
- module Types::BaseInterface
2
- include GraphQL::Schema::Interface
1
+ module Types
2
+ module BaseInterface
3
+ include GraphQL::Schema::Interface
4
+ end
3
5
  end
@@ -1,2 +1,4 @@
1
- class Types::BaseObject < GraphQL::Schema::Object
1
+ module Types
2
+ class BaseObject < GraphQL::Schema::Object
3
+ end
2
4
  end
@@ -1,2 +1,4 @@
1
- class Types::BaseUnion < GraphQL::Schema::Union
1
+ module Types
2
+ class BaseUnion < GraphQL::Schema::Union
3
+ end
2
4
  end
@@ -1,3 +1,5 @@
1
- class <%= type_ruby_name %> < Types::BaseEnum
2
- <% prepared_values.each do |v| %> value "<%= v[0] %>"<%= v.length > 1 ? ", value: #{v[1]}" : "" %>
3
- <% end %>end
1
+ module Types
2
+ class <%= type_ruby_name.split('::')[-1] %> < Types::BaseEnum
3
+ <% prepared_values.each do |v| %> value "<%= v[0] %>"<%= v.length > 1 ? ", value: #{v[1]}" : "" %>
4
+ <% end %> end
5
+ end
@@ -1,4 +1,6 @@
1
- module <%= type_ruby_name %>
2
- include Types::BaseInterface
3
- <% normalized_fields.each do |f| %> <%= f.to_ruby %>
4
- <% end %>end
1
+ module Types
2
+ module <%= type_ruby_name.split('::')[-1] %>
3
+ include Types::BaseInterface
4
+ <% normalized_fields.each do |f| %> <%= f.to_ruby %>
5
+ <% end %> end
6
+ end
@@ -1,15 +1,17 @@
1
- class Loaders::<%= class_name %> < GraphQL::Batch::Loader
2
- # Define `initialize` to store grouping arguments, eg
3
- #
4
- # Loaders::<%= class_name %>.for(group).load(value)
5
- #
6
- # def initialize()
7
- # end
1
+ module Loaders
2
+ class <%= class_name %> < GraphQL::Batch::Loader
3
+ # Define `initialize` to store grouping arguments, eg
4
+ #
5
+ # Loaders::<%= class_name %>.for(group).load(value)
6
+ #
7
+ # def initialize()
8
+ # end
8
9
 
9
- # `keys` contains each key from `.load(key)`.
10
- # Find the corresponding values, then
11
- # call `fulfill(key, value)` or `fulfill(key, nil)`
12
- # for each key.
13
- def perform(keys)
10
+ # `keys` contains each key from `.load(key)`.
11
+ # Find the corresponding values, then
12
+ # call `fulfill(key, value)` or `fulfill(key, nil)`
13
+ # for each key.
14
+ def perform(keys)
15
+ end
14
16
  end
15
17
  end
@@ -1,11 +1,14 @@
1
- class Mutations::<%= mutation_name %> < GraphQL::Schema::RelayClassicMutation
2
- # TODO: define return fields
3
- # return_field :post, Types::PostType
1
+ module Mutations
2
+ class <%= mutation_name %> < GraphQL::Schema::RelayClassicMutation
3
+ # TODO: define return fields
4
+ # field :post, Types::PostType, null: false
4
5
 
5
- # TODO: define arguments
6
- # input_field :name, !types.String
6
+ # TODO: define arguments
7
+ # argument :name, String, required: true
7
8
 
8
- def resolve(**inputs)
9
9
  # TODO: define resolve method
10
+ # def resolve(name:)
11
+ # { post: ... }
12
+ # end
10
13
  end
11
14
  end
@@ -1,8 +1,10 @@
1
- class Types::MutationType < Types::BaseObject
2
- # TODO: remove me
3
- field :test_field, String, null: false,
4
- description: "An example field added by the generator"
5
- def test_field
6
- "Hello World"
1
+ module Types
2
+ class MutationType < Types::BaseObject
3
+ # TODO: remove me
4
+ field :test_field, String, null: false,
5
+ description: "An example field added by the generator"
6
+ def test_field
7
+ "Hello World"
8
+ end
7
9
  end
8
10
  end
@@ -1,4 +1,6 @@
1
- class <%= type_ruby_name %> < Types::BaseObject
2
- <% if options.node %> implements GraphQL::Relay::Node.interface
3
- <% end %><% normalized_fields.each do |f| %> <%= f.to_ruby %>
4
- <% end %>end
1
+ module Types
2
+ class <%= type_ruby_name.split('::')[-1] %> < Types::BaseObject
3
+ <% if options.node %> implements GraphQL::Relay::Node.interface
4
+ <% end %><% normalized_fields.each do |f| %> <%= f.to_ruby %>
5
+ <% end %> end
6
+ end
@@ -1,13 +1,15 @@
1
- class Types::QueryType < Types::BaseObject
2
- # Add root-level fields here.
3
- # They will be entry points for queries on your schema.
1
+ module Types
2
+ class QueryType < Types::BaseObject
3
+ # Add root-level fields here.
4
+ # They will be entry points for queries on your schema.
4
5
 
5
- # TODO: remove me
6
- field :test_field, String, null: false,
7
- description: "An example field added by the generator"
8
- def test_field
9
- "Hello World!"
10
- end
6
+ # TODO: remove me
7
+ field :test_field, String, null: false,
8
+ description: "An example field added by the generator"
9
+ def test_field
10
+ "Hello World!"
11
+ end
11
12
  <% if options[:relay] %>
12
- field :node, field: GraphQL::Relay::Node.field
13
- <% end %>end
13
+ field :node, field: GraphQL::Relay::Node.field
14
+ <% end %> end
15
+ end
@@ -1,3 +1,5 @@
1
- class <%= type_ruby_name %> < Types::BaseUnion
2
- <% if possible_types.any? %> possible_types [<%= normalized_possible_types.join(", ") %>]
3
- <% end %>end
1
+ module Types
2
+ class <%= type_ruby_name.split('::')[-1] %> < Types::BaseUnion
3
+ <% if possible_types.any? %> possible_types [<%= normalized_possible_types.join(", ") %>]
4
+ <% end %> end
5
+ end
@@ -36,7 +36,8 @@ module GraphQL
36
36
  class Argument
37
37
  include GraphQL::Define::InstanceDefinable
38
38
  accepts_definitions :name, :type, :description, :default_value, :as, :prepare
39
- attr_accessor :type, :description, :default_value, :name, :as
39
+ attr_reader :default_value
40
+ attr_accessor :description, :name, :as
40
41
  attr_accessor :ast_node
41
42
  alias :graphql_name :name
42
43
 
@@ -65,7 +66,7 @@ module GraphQL
65
66
  @default_value = nil
66
67
  else
67
68
  @has_default_value = true
68
- @default_value = new_default_value
69
+ @default_value = GraphQL::Argument.deep_stringify(new_default_value)
69
70
  end
70
71
  end
71
72
 
@@ -127,5 +128,21 @@ module GraphQL
127
128
  GraphQL::Argument.define(kwargs, &block)
128
129
  end
129
130
  end
131
+
132
+ # @api private
133
+ def self.deep_stringify(val)
134
+ case val
135
+ when Array
136
+ val.map { |v| deep_stringify(v) }
137
+ when Hash
138
+ new_val = {}
139
+ val.each do |k, v|
140
+ new_val[k.to_s] = deep_stringify(v)
141
+ end
142
+ new_val
143
+ else
144
+ val
145
+ end
146
+ end
130
147
  end
131
148
  end
@@ -35,7 +35,7 @@ module GraphQL
35
35
  end
36
36
 
37
37
  # @return [String] the name of this type, must be unique within a Schema
38
- attr_accessor :name
38
+ attr_reader :name
39
39
  # Future-compatible alias
40
40
  # @see {GraphQL::SchemaMember}
41
41
  alias :graphql_name :name
@@ -177,6 +177,7 @@ module GraphQL
177
177
  pending_methods = @pending_methods
178
178
  self.singleton_class.class_eval {
179
179
  pending_methods.each do |method|
180
+ undef_method(method.name) if method_defined?(method.name)
180
181
  define_method(method.name, method)
181
182
  end
182
183
  }
@@ -200,6 +201,7 @@ module GraphQL
200
201
  @pending_methods = method_names.map { |n| self.class.instance_method(n) }
201
202
  self.singleton_class.class_eval do
202
203
  method_names.each do |method_name|
204
+ undef_method(method_name) if method_defined?(method_name)
203
205
  define_method(method_name) { |*args, &block|
204
206
  ensure_defined
205
207
  self.send(method_name, *args, &block)
@@ -141,6 +141,7 @@ module GraphQL
141
141
  attr_accessor :ast_node
142
142
  ensure_defined(*ATTRIBUTES)
143
143
 
144
+ undef name=
144
145
  def name=(new_name)
145
146
  # Validate that the name is correct
146
147
  GraphQL::NameValidator.validate!(new_name)
@@ -51,30 +51,38 @@ module GraphQL
51
51
 
52
52
  # Call each before hook, and if they all succeed, yield.
53
53
  # If they don't all succeed, call after_ for each one that succeeded.
54
- def call_hooks(instrumenters, object, before_hook_name, after_hook_name, i = 0)
55
- if i >= instrumenters.length
56
- # We've reached the end of the instrumenters, so start exiting the call stack.
57
- # (This will eventually call the originally-passed block.)
58
- yield
59
- else
60
- # Get the next instrumenter and call the before_hook.
61
- instrumenter = instrumenters[i]
62
- instrumenter.public_send(before_hook_name, object)
63
- # At this point, the before_hook did _not_ raise an error.
64
- # (If it did raise an error, we wouldn't reach this point.)
65
- # So we should guarantee that we run the after_hook.
54
+ def call_hooks(instrumenters, object, before_hook_name, after_hook_name)
55
+ begin
56
+ successful = []
57
+ instrumenters.each do |instrumenter|
58
+ instrumenter.public_send(before_hook_name, object)
59
+ successful << instrumenter
60
+ end
61
+
62
+ # if any before hooks raise an exception, quit calling before hooks,
63
+ # but call the after hooks on anything that succeeded but also
64
+ # raise the exception that came from the before hook.
65
+ rescue => e
66
+ raise call_after_hooks(successful, object, after_hook_name, e)
67
+ end
68
+
69
+ begin
70
+ yield # Call the user code
71
+ ensure
72
+ ex = call_after_hooks(successful, object, after_hook_name, nil)
73
+ raise ex if ex
74
+ end
75
+ end
76
+
77
+ def call_after_hooks(instrumenters, object, after_hook_name, ex)
78
+ instrumenters.reverse.each do |instrumenter|
66
79
  begin
67
- # Call the next instrumenter on the list,
68
- # basically passing along the original block
69
- call_hooks(instrumenters, object, before_hook_name, after_hook_name, i + 1) {
70
- yield
71
- }
72
- ensure
73
- # Regardless of how the next instrumenter in the list behaves,
74
- # call the after_hook of this instrumenter
75
80
  instrumenter.public_send(after_hook_name, object)
81
+ rescue => e
82
+ ex = e
76
83
  end
77
84
  end
85
+ ex
78
86
  end
79
87
  end
80
88
  end
@@ -156,7 +156,7 @@ module GraphQL
156
156
  attr_reader :lazy_resolve_proc
157
157
 
158
158
  # @return [String] The name of this field on its {GraphQL::ObjectType} (or {GraphQL::InterfaceType})
159
- attr_accessor :name
159
+ attr_reader :name
160
160
  alias :graphql_name :name
161
161
 
162
162
  # @return [String, nil] The client-facing description of this field
@@ -175,10 +175,10 @@ module GraphQL
175
175
  attr_accessor :complexity
176
176
 
177
177
  # @return [Symbol, nil] The method to call on `obj` to return this field (overrides {#name} if present)
178
- attr_accessor :property
178
+ attr_reader :property
179
179
 
180
180
  # @return [Object, nil] The key to access with `obj.[]` to resolve this field (overrides {#name} if present)
181
- attr_accessor :hash_key
181
+ attr_reader :hash_key
182
182
 
183
183
  # @return [Object, GraphQL::Function] The function used to derive this field
184
184
  attr_accessor :function
@@ -93,7 +93,8 @@ module GraphQL
93
93
  coerced_value = input_field_defn.type.coerce_input(field_value, ctx)
94
94
  input_values[input_key] = input_field_defn.prepare(coerced_value, ctx)
95
95
  elsif input_field_defn.default_value?
96
- input_values[input_key] = input_field_defn.default_value
96
+ coerced_value = input_field_defn.type.coerce_input(input_field_defn.default_value, ctx)
97
+ input_values[input_key] = coerced_value
97
98
  defaults_used << input_key
98
99
  end
99
100
  end
@@ -29,7 +29,7 @@ module GraphQL
29
29
  end
30
30
  end
31
31
 
32
- attr_reader :schema, :context, :warden, :provided_variables
32
+ attr_reader :schema, :context, :provided_variables
33
33
 
34
34
  # The value for root types
35
35
  attr_accessor :root_value
@@ -60,9 +60,6 @@ module GraphQL
60
60
  # @return [String, nil] the triggered event, if this query is a subscription update
61
61
  attr_reader :subscription_topic
62
62
 
63
- # @return [String, nil]
64
- attr_reader :operation_name
65
-
66
63
  attr_reader :tracers
67
64
 
68
65
  # Prepare query `query_string` on `schema`
@@ -220,11 +217,6 @@ module GraphQL
220
217
  @arguments_cache[irep_or_ast_node][definition]
221
218
  end
222
219
 
223
- # @return [GraphQL::Language::Nodes::OperationDefinition, nil]
224
- def selected_operation
225
- with_prepared_ast { @selected_operation }
226
- end
227
-
228
220
  def validation_pipeline
229
221
  with_prepared_ast { @validation_pipeline }
230
222
  end
@@ -14,7 +14,7 @@ module GraphQL
14
14
  schema = ctx.schema
15
15
  @context = ctx
16
16
 
17
- @provided_variables = deep_stringify(provided_variables)
17
+ @provided_variables = GraphQL::Argument.deep_stringify(provided_variables)
18
18
  @errors = []
19
19
  @storage = ast_variables.each_with_object({}) do |ast_variable, memo|
20
20
  # Find the right value for this variable:
@@ -52,23 +52,6 @@ module GraphQL
52
52
  end
53
53
 
54
54
  def_delegators :@storage, :length, :key?, :[], :fetch, :to_h
55
-
56
- private
57
-
58
- def deep_stringify(val)
59
- case val
60
- when Array
61
- val.map { |v| deep_stringify(v) }
62
- when Hash
63
- new_val = {}
64
- val.each do |k, v|
65
- new_val[k.to_s] = deep_stringify(v)
66
- end
67
- new_val
68
- else
69
- val
70
- end
71
- end
72
55
  end
73
56
  end
74
57
  end
@@ -1,5 +1,4 @@
1
1
  # frozen_string_literal: true
2
- require 'base64'
3
2
 
4
3
  require 'graphql/relay/page_info'
5
4
  require 'graphql/relay/edge'
@@ -36,5 +36,15 @@ module GraphQL
36
36
  if defined?(Mongoid::Criteria)
37
37
  BaseConnection.register_connection_implementation(Mongoid::Criteria, MongoRelationConnection)
38
38
  end
39
+
40
+ # Mongoid 5 and 6
41
+ if defined?(Mongoid::Relations::Targets::Enumerable)
42
+ BaseConnection.register_connection_implementation(Mongoid::Relations::Targets::Enumerable, MongoRelationConnection)
43
+ end
44
+
45
+ # Mongoid 7
46
+ if defined?(Mongoid::Association::Referenced::HasMany::Targets::Enumerable)
47
+ BaseConnection.register_connection_implementation(Mongoid::Association::Referenced::HasMany::Targets::Enumerable, MongoRelationConnection)
48
+ end
39
49
  end
40
50
  end