graphql 1.8.8 → 1.8.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/lib/graphql/base_type.rb +1 -1
  3. data/lib/graphql/compatibility/execution_specification/specification_schema.rb +1 -2
  4. data/lib/graphql/enum_type.rb +4 -0
  5. data/lib/graphql/execution/execute.rb +2 -2
  6. data/lib/graphql/field.rb +1 -7
  7. data/lib/graphql/schema.rb +25 -3
  8. data/lib/graphql/schema/argument.rb +3 -4
  9. data/lib/graphql/schema/field.rb +19 -4
  10. data/lib/graphql/types/iso_8601_date_time.rb +15 -1
  11. data/lib/graphql/version.rb +1 -1
  12. data/readme.md +1 -1
  13. data/spec/graphql/analysis/analyze_query_spec.rb +1 -1
  14. data/spec/graphql/base_type_spec.rb +3 -3
  15. data/spec/graphql/enum_type_spec.rb +1 -1
  16. data/spec/graphql/execution/lazy_spec.rb +18 -1
  17. data/spec/graphql/execution/typecast_spec.rb +20 -20
  18. data/spec/graphql/field_spec.rb +1 -1
  19. data/spec/graphql/input_object_type_spec.rb +25 -0
  20. data/spec/graphql/interface_type_spec.rb +4 -4
  21. data/spec/graphql/introspection/input_value_type_spec.rb +1 -1
  22. data/spec/graphql/object_type_spec.rb +32 -27
  23. data/spec/graphql/query/executor_spec.rb +2 -2
  24. data/spec/graphql/schema/argument_spec.rb +27 -0
  25. data/spec/graphql/schema/field_spec.rb +16 -0
  26. data/spec/graphql/schema/interface_spec.rb +2 -2
  27. data/spec/graphql/schema/relay_classic_mutation_spec.rb +36 -0
  28. data/spec/graphql/schema/traversal_spec.rb +10 -10
  29. data/spec/graphql/schema/type_expression_spec.rb +2 -2
  30. data/spec/graphql/schema/validation_spec.rb +1 -1
  31. data/spec/graphql/types/iso_8601_date_time_spec.rb +25 -0
  32. data/spec/graphql/union_type_spec.rb +2 -2
  33. data/spec/integration/rails/graphql/input_object_type_spec.rb +4 -4
  34. data/spec/integration/rails/graphql/query/variables_spec.rb +7 -7
  35. data/spec/integration/rails/graphql/schema_spec.rb +6 -5
  36. data/spec/integration/tmp/app/graphql/types/page_type.rb +4 -0
  37. data/spec/support/dummy/data.rb +20 -17
  38. data/spec/support/dummy/schema.rb +271 -281
  39. data/spec/support/jazz.rb +45 -0
  40. data/spec/support/lazy_helpers.rb +13 -4
  41. metadata +216 -212
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c8642c253947a56246003a995f373e3088b70848
4
- data.tar.gz: 0e027e906d12ff726e144220849ac216b66dc56d
3
+ metadata.gz: 4378912bdbb59ceaa6006848e6eda269f1185df1
4
+ data.tar.gz: 5dd1788b97f608a67ffa5c27f6848a575f996daa
5
5
  SHA512:
6
- metadata.gz: cfabff78ee8e8bb710ee73bfcb191d7b040a55eb042a2b94cf8d8d3169671b954aa13901c095124a516d593f49d21f1c9f2f63ed2731308e77e74fbffad9d726
7
- data.tar.gz: d924393eea98ab77207c0fa35abc579373f650000e66b82cd181f1e5286b58d8794e29fcc4f3796f3b8db6f0dec0c7293e8244275cdceb0f45f39bde556f8f89
6
+ metadata.gz: 3f9e4c341f98a13ad1018c0ae9b5c1f1063f5c5cbf8485b29c164f485f79257b8dc148db9fb959fdad9e8aa9f3d4eb05648a27b9a2168387ca3649b994f200ab
7
+ data.tar.gz: e5cbe104fb2f6d06f4fdf0cf51f931367845f933440e8143897207af1bfb7302c6ae7fca0d823cc3b593bb5f83545c3c030a00c6c5a9d008b9f545a1666a52dd
@@ -187,7 +187,7 @@ module GraphQL
187
187
  resolve_related_type(type_arg.call)
188
188
  when String
189
189
  # Get a constant by this name
190
- Object.const_get(type_arg)
190
+ resolve_related_type(Object.const_get(type_arg))
191
191
  else
192
192
  if type_arg.respond_to?(:graphql_definition)
193
193
  type_arg.graphql_definition
@@ -49,8 +49,7 @@ module GraphQL
49
49
  end
50
50
 
51
51
  module TestMiddleware
52
- # TODO: Once deprecated `next_middleware` argument becomes unsupported, add `&` to the argument
53
- def self.call(parent_type, parent_object, field_definition, field_args, query_context, next_middleware)
52
+ def self.call(parent_type, parent_object, field_definition, field_args, query_context, &next_middleware)
54
53
  query_context[:middleware_log] && query_context[:middleware_log] << field_definition.name
55
54
  next_middleware.call
56
55
  end
@@ -169,6 +169,10 @@ module GraphQL
169
169
  def coerce_non_null_input(value_name, ctx)
170
170
  if @values_by_name.key?(value_name)
171
171
  @values_by_name.fetch(value_name).value
172
+ elsif match_by_value = @values_by_name.find { |k, v| v.value == value_name }
173
+ # this is for matching default values, which are "inputs", but they're
174
+ # the Ruby value, not the GraphQL string.
175
+ match_by_value[1].value
172
176
  else
173
177
  nil
174
178
  end
@@ -142,11 +142,11 @@ module GraphQL
142
142
  # If the returned object is finished, continue to coerce
143
143
  # and resolve child fields
144
144
  def continue_or_wait(raw_value, field_type, field_ctx)
145
- if (lazy_method = field_ctx.schema.lazy_method_name(raw_value))
145
+ if field_ctx.schema.lazy?(raw_value)
146
146
  field_ctx.value = Execution::Lazy.new {
147
147
  inner_value = begin
148
148
  begin
149
- raw_value.public_send(lazy_method)
149
+ field_ctx.schema.sync_lazy(raw_value)
150
150
  rescue GraphQL::UnauthorizedError => err
151
151
  field_ctx.schema.unauthorized_object(err)
152
152
  end
@@ -323,13 +323,7 @@ module GraphQL
323
323
 
324
324
  module DefaultLazyResolve
325
325
  def self.call(obj, args, ctx)
326
- method_name = ctx.schema.lazy_method_name(obj)
327
- next_obj = obj.public_send(method_name)
328
- if ctx.schema.lazy?(next_obj)
329
- call(next_obj, args, ctx)
330
- else
331
- next_obj
332
- end
326
+ ctx.schema.sync_lazy(obj)
333
327
  end
334
328
  end
335
329
  end
@@ -657,7 +657,7 @@ module GraphQL
657
657
  :static_validator, :introspection_system,
658
658
  :query_analyzers, :tracers, :instrumenters,
659
659
  :query_execution_strategy, :mutation_execution_strategy, :subscription_execution_strategy,
660
- :validate, :multiplex_analyzers, :lazy?, :lazy_method_name, :after_lazy,
660
+ :validate, :multiplex_analyzers, :lazy?, :lazy_method_name, :after_lazy, :sync_lazy,
661
661
  # Configuration
662
662
  :max_complexity=, :max_depth=,
663
663
  :metadata,
@@ -1001,9 +1001,9 @@ module GraphQL
1001
1001
  # - After resolving `value`, if it's registered with `lazy_resolve` (eg, `Promise`)
1002
1002
  # @api private
1003
1003
  def after_lazy(value)
1004
- if (lazy_method = lazy_method_name(value))
1004
+ if lazy?(value)
1005
1005
  GraphQL::Execution::Lazy.new do
1006
- result = value.public_send(lazy_method)
1006
+ result = sync_lazy(value)
1007
1007
  # The returned result might also be lazy, so check it, too
1008
1008
  after_lazy(result) do |final_result|
1009
1009
  yield(final_result) if block_given?
@@ -1014,6 +1014,28 @@ module GraphQL
1014
1014
  end
1015
1015
  end
1016
1016
 
1017
+ # Override this method to handle lazy objects in a custom way.
1018
+ # @param value [Object] an instance of a class registered with {.lazy_resolve}
1019
+ # @param ctx [GraphQL::Query::Context] the context for this query
1020
+ # @return [Object] A GraphQL-ready (non-lazy) object
1021
+ def self.sync_lazy(value)
1022
+ yield(value)
1023
+ end
1024
+
1025
+ # @see Schema.sync_lazy for a hook to override
1026
+ # @api private
1027
+ def sync_lazy(value)
1028
+ self.class.sync_lazy(value) { |v|
1029
+ lazy_method = lazy_method_name(v)
1030
+ if lazy_method
1031
+ synced_value = value.public_send(lazy_method)
1032
+ sync_lazy(synced_value)
1033
+ else
1034
+ v
1035
+ end
1036
+ }
1037
+ end
1038
+
1017
1039
  protected
1018
1040
 
1019
1041
  def rescues?
@@ -97,12 +97,11 @@ module GraphQL
97
97
  # Used by the runtime.
98
98
  # @api private
99
99
  def prepare_value(obj, value)
100
- case @prepare
101
- when nil
100
+ if @prepare.nil?
102
101
  value
103
- when Symbol, String
102
+ elsif @prepare.is_a?(String) || @prepare.is_a?(Symbol)
104
103
  obj.public_send(@prepare, value)
105
- when Proc
104
+ elsif @prepare.respond_to?(:call)
106
105
  @prepare.call(value, obj.context)
107
106
  else
108
107
  raise "Invalid prepare for #{@owner.name}.name: #{@prepare.inspect}"
@@ -126,7 +126,7 @@ module GraphQL
126
126
  # @param complexity [Numeric] When provided, set the complexity for this field
127
127
  # @param scope [Boolean] If true, the return type's `.scope_items` method will be called on the return value
128
128
  # @param subscription_scope [Symbol, String] A key in `context` which will be used to scope subscription payloads
129
- def initialize(type: nil, name: nil, owner: nil, null: nil, field: nil, function: nil, description: nil, deprecation_reason: nil, method: nil, connection: nil, max_page_size: nil, scope: nil, resolve: nil, introspection: false, hash_key: nil, camelize: true, complexity: 1, extras: [], resolver_class: nil, subscription_scope: nil, arguments: {}, &definition_block)
129
+ def initialize(type: nil, name: nil, owner: nil, null: nil, field: nil, function: nil, description: nil, deprecation_reason: nil, method: nil, connection: nil, max_page_size: nil, scope: nil, resolve: nil, introspection: false, hash_key: nil, camelize: true, trace: nil, complexity: 1, extras: [], resolver_class: nil, subscription_scope: nil, arguments: {}, &definition_block)
130
130
 
131
131
  if name.nil?
132
132
  raise ArgumentError, "missing first `name` argument or keyword `name:`"
@@ -170,6 +170,7 @@ module GraphQL
170
170
  @extras = extras
171
171
  @resolver_class = resolver_class
172
172
  @scope = scope
173
+ @trace = trace
173
174
 
174
175
  # Override the default from HasArguments
175
176
  @own_arguments = {}
@@ -186,7 +187,7 @@ module GraphQL
186
187
 
187
188
  if definition_block
188
189
  if definition_block.arity == 1
189
- instance_exec(self, &definition_block)
190
+ yield self
190
191
  else
191
192
  instance_eval(&definition_block)
192
193
  end
@@ -258,6 +259,10 @@ module GraphQL
258
259
  field_defn.metadata[:resolver] = @resolver_class
259
260
  end
260
261
 
262
+ if !@trace.nil?
263
+ field_defn.trace = @trace
264
+ end
265
+
261
266
  field_defn.resolve = self.method(:resolve_field)
262
267
  field_defn.connection = connection?
263
268
  field_defn.connection_max_page_size = @max_page_size
@@ -401,6 +406,17 @@ module GraphQL
401
406
  end
402
407
  end
403
408
 
409
+ # @param ctx [GraphQL::Query::Context::FieldResolutionContext]
410
+ def fetch_extra(extra_name, ctx)
411
+ if respond_to?(extra_name)
412
+ self.public_send(extra_name)
413
+ elsif ctx.respond_to?(extra_name)
414
+ ctx.public_send(extra_name)
415
+ else
416
+ raise NotImplementedError, "Unknown field extra for #{self.path}: #{extra_name.inspect}"
417
+ end
418
+ end
419
+
404
420
  NO_ARGS = {}.freeze
405
421
 
406
422
  def public_send_field(obj, graphql_args, field_ctx)
@@ -424,8 +440,7 @@ module GraphQL
424
440
  end
425
441
 
426
442
  @extras.each do |extra_arg|
427
- # TODO: provide proper tests for `:ast_node`, `:irep_node`, `:parent`, others?
428
- ruby_kwargs[extra_arg] = field_ctx.public_send(extra_arg)
443
+ ruby_kwargs[extra_arg] = fetch_extra(extra_arg, field_ctx)
429
444
  end
430
445
  else
431
446
  ruby_kwargs = NO_ARGS
@@ -15,10 +15,24 @@ module GraphQL
15
15
  class ISO8601DateTime < GraphQL::Schema::Scalar
16
16
  description "An ISO 8601-encoded datetime"
17
17
 
18
+ # It's not compatible with Rails' default,
19
+ # i.e. ActiveSupport::JSON::Encoder.time_precision (3 by default)
20
+ DEFAULT_TIME_PRECISION = 0
21
+
22
+ # @return [Integer]
23
+ def self.time_precision
24
+ @time_precision || DEFAULT_TIME_PRECISION
25
+ end
26
+
27
+ # @param [Integer] value
28
+ def self.time_precision=(value)
29
+ @time_precision = value
30
+ end
31
+
18
32
  # @param value [DateTime]
19
33
  # @return [String]
20
34
  def self.coerce_result(value, _ctx)
21
- value.iso8601
35
+ value.iso8601(time_precision)
22
36
  end
23
37
 
24
38
  # @param str_value [String]
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module GraphQL
3
- VERSION = "1.8.8"
3
+ VERSION = "1.8.9"
4
4
  end
data/readme.md CHANGED
@@ -37,7 +37,7 @@ Or, see ["Getting Started"](https://rmosolgo.github.io/graphql-ruby/).
37
37
 
38
38
  ## Upgrade
39
39
 
40
- I also sell [GraphQL::Pro](http://graphql.pro) which provides several features on top of the GraphQL runtime, including [authorization](http://rmosolgo.github.io/graphql-ruby/pro/authorization), [Pusher-based subscriptions](http://graphql-ruby.org/subscriptions/pusher_implementation) and [persisted queries](http://rmosolgo.github.io/graphql-ruby/operation_store/overview). Besides that, Pro customers get email support and an opportunity to support graphql-ruby's development!
40
+ I also sell [GraphQL::Pro](http://graphql.pro) which provides several features on top of the GraphQL runtime, including [Pundit authorization](http://rmosolgo.github.io/graphql-ruby/authorization/pundit_integration), [CanCan authorization](http://rmosolgo.github.io/graphql-ruby/authorization/can_can_integration), [Pusher-based subscriptions](http://graphql-ruby.org/subscriptions/pusher_implementation) and [persisted queries](http://rmosolgo.github.io/graphql-ruby/operation_store/overview). Besides that, Pro customers get email support and an opportunity to support graphql-ruby's development!
41
41
 
42
42
  ## Goals
43
43
 
@@ -78,7 +78,7 @@ describe GraphQL::Analysis do
78
78
 
79
79
  it "calls the defined analyzers" do
80
80
  collected_types, node_counts = reduce_result
81
- expected_visited_types = [Dummy::DairyAppQueryType, Dummy::CheeseType, GraphQL::INT_TYPE, GraphQL::STRING_TYPE]
81
+ expected_visited_types = [Dummy::DairyAppQuery.graphql_definition, Dummy::Cheese.graphql_definition, GraphQL::INT_TYPE, GraphQL::STRING_TYPE]
82
82
  assert_equal expected_visited_types, collected_types
83
83
  expected_node_counts = {
84
84
  GraphQL::Language::Nodes::OperationDefinition => 1,
@@ -11,7 +11,7 @@ describe GraphQL::BaseType do
11
11
  end
12
12
 
13
13
  it "can be compared" do
14
- obj_type = Dummy::MilkType
14
+ obj_type = Dummy::Milk.graphql_definition
15
15
  assert_equal(!GraphQL::INT_TYPE, !GraphQL::INT_TYPE)
16
16
  refute_equal(!GraphQL::FLOAT_TYPE, GraphQL::FLOAT_TYPE)
17
17
  assert_equal(
@@ -25,7 +25,7 @@ describe GraphQL::BaseType do
25
25
  end
26
26
 
27
27
  it "Accepts arbitrary metadata" do
28
- assert_equal ["Cheese"], Dummy::CheeseType.metadata[:class_names]
28
+ assert_equal ["Cheese"], Dummy::Cheese.graphql_definition.metadata[:class_names]
29
29
  end
30
30
 
31
31
  describe "#name" do
@@ -63,7 +63,7 @@ describe GraphQL::BaseType do
63
63
  end
64
64
 
65
65
  describe "forwards-compat with new api" do
66
- let(:type_defn) { Dummy::CheeseType }
66
+ let(:type_defn) { Dummy::Cheese.graphql_definition }
67
67
  it "responds to new methods" do
68
68
  assert_equal "Cheese", type_defn.graphql_name
69
69
  assert_equal type_defn, type_defn.graphql_definition
@@ -2,7 +2,7 @@
2
2
  require "spec_helper"
3
3
 
4
4
  describe GraphQL::EnumType do
5
- let(:enum) { Dummy::DairyAnimalEnum }
5
+ let(:enum) { Dummy::DairyAnimal.graphql_definition }
6
6
 
7
7
  it "coerces names to underlying values" do
8
8
  assert_equal("YAK", enum.coerce_isolated_input("YAK"))
@@ -155,6 +155,23 @@ describe GraphQL::Execution::Lazy do
155
155
  end
156
156
  end
157
157
 
158
+ describe "Schema#sync_lazy(object)" do
159
+ it "Passes objects to that hook at runtime" do
160
+ res = run_query <<-GRAPHQL
161
+ {
162
+ a: nullableNestedSum(value: 1001) { value }
163
+ b: nullableNestedSum(value: 1013) { value }
164
+ c: nullableNestedSum(value: 1002) { value }
165
+ }
166
+ GRAPHQL
167
+
168
+ # This odd, non-adding behavior is hacked into `#sync_lazy`
169
+ assert_equal 101, res["data"]["a"]["value"]
170
+ assert_equal 113, res["data"]["b"]["value"]
171
+ assert_equal 102, res["data"]["c"]["value"]
172
+ end
173
+ end
174
+
158
175
  describe "LazyMethodMap" do
159
176
  class SubWrapper < LazyHelpers::Wrapper; end
160
177
 
@@ -165,7 +182,7 @@ describe GraphQL::Execution::Lazy do
165
182
  map.set(LazyHelpers::SumAll, :value)
166
183
  b = LazyHelpers::Wrapper.new(1)
167
184
  sub_b = LazyHelpers::Wrapper.new(2)
168
- s = LazyHelpers::SumAll.new({}, 3)
185
+ s = LazyHelpers::SumAll.new(3)
169
186
  assert_equal(:item, map.get(b))
170
187
  assert_equal(:item, map.get(sub_b))
171
188
  assert_equal(:value, map.get(s))
@@ -8,36 +8,36 @@ describe GraphQL::Execution::Typecast do
8
8
  end
9
9
 
10
10
  it "counts the same type as a subtype" do
11
- assert subtype?(Dummy::MilkType, Dummy::MilkType)
12
- assert !subtype?(Dummy::MilkType, Dummy::CheeseType)
13
- assert subtype?(Dummy::MilkType.to_list_type.to_non_null_type, Dummy::MilkType.to_list_type.to_non_null_type)
11
+ assert subtype?(Dummy::Milk.graphql_definition, Dummy::Milk.graphql_definition)
12
+ assert !subtype?(Dummy::Milk.graphql_definition, Dummy::Cheese.graphql_definition)
13
+ assert subtype?(Dummy::Milk.graphql_definition.to_list_type.to_non_null_type, Dummy::Milk.graphql_definition.to_list_type.to_non_null_type)
14
14
  end
15
15
 
16
16
  it "counts member types as subtypes" do
17
- assert subtype?(Dummy::EdibleInterface, Dummy::CheeseType)
18
- assert subtype?(Dummy::EdibleInterface, Dummy::MilkType)
19
- assert subtype?(Dummy::DairyProductUnion, Dummy::MilkType)
20
- assert subtype?(Dummy::DairyProductUnion, Dummy::CheeseType)
17
+ assert subtype?(Dummy::Edible.graphql_definition, Dummy::Cheese.graphql_definition)
18
+ assert subtype?(Dummy::Edible.graphql_definition, Dummy::Milk.graphql_definition)
19
+ assert subtype?(Dummy::DairyProduct.graphql_definition, Dummy::Milk.graphql_definition)
20
+ assert subtype?(Dummy::DairyProduct.graphql_definition, Dummy::Cheese.graphql_definition)
21
21
 
22
- assert !subtype?(Dummy::DairyAppQueryType, Dummy::DairyProductUnion)
23
- assert !subtype?(Dummy::CheeseType, Dummy::DairyProductUnion)
24
- assert !subtype?(Dummy::EdibleInterface, Dummy::DairyProductUnion)
25
- assert !subtype?(Dummy::EdibleInterface, GraphQL::STRING_TYPE)
26
- assert !subtype?(Dummy::EdibleInterface, Dummy::DairyProductInputType)
22
+ assert !subtype?(Dummy::DairyAppQuery.graphql_definition, Dummy::DairyProduct.graphql_definition)
23
+ assert !subtype?(Dummy::Cheese.graphql_definition, Dummy::DairyProduct.graphql_definition)
24
+ assert !subtype?(Dummy::Edible.graphql_definition, Dummy::DairyProduct.graphql_definition)
25
+ assert !subtype?(Dummy::Edible.graphql_definition, GraphQL::STRING_TYPE)
26
+ assert !subtype?(Dummy::Edible.graphql_definition, Dummy::DairyProductInput.graphql_definition)
27
27
  end
28
28
 
29
29
  it "counts lists as subtypes if their inner types are subtypes" do
30
- assert subtype?(Dummy::EdibleInterface.to_list_type, Dummy::MilkType.to_list_type)
31
- assert subtype?(Dummy::DairyProductUnion.to_list_type, Dummy::MilkType.to_list_type)
32
- assert !subtype?(Dummy::CheeseType.to_list_type, Dummy::DairyProductUnion.to_list_type)
33
- assert !subtype?(Dummy::EdibleInterface.to_list_type, Dummy::DairyProductUnion.to_list_type)
34
- assert !subtype?(Dummy::EdibleInterface.to_list_type, GraphQL::STRING_TYPE.to_list_type)
30
+ assert subtype?(Dummy::Edible.graphql_definition.to_list_type, Dummy::Milk.graphql_definition.to_list_type)
31
+ assert subtype?(Dummy::DairyProduct.graphql_definition.to_list_type, Dummy::Milk.graphql_definition.to_list_type)
32
+ assert !subtype?(Dummy::Cheese.graphql_definition.to_list_type, Dummy::DairyProduct.graphql_definition.to_list_type)
33
+ assert !subtype?(Dummy::Edible.graphql_definition.to_list_type, Dummy::DairyProduct.graphql_definition.to_list_type)
34
+ assert !subtype?(Dummy::Edible.graphql_definition.to_list_type, GraphQL::STRING_TYPE.to_list_type)
35
35
  end
36
36
 
37
37
  it "counts non-null types as subtypes of nullable parent types" do
38
- assert subtype?(Dummy::MilkType, Dummy::MilkType.to_non_null_type)
39
- assert subtype?(Dummy::EdibleInterface, Dummy::MilkType.to_non_null_type)
40
- assert subtype?(Dummy::EdibleInterface.to_non_null_type, Dummy::MilkType.to_non_null_type)
38
+ assert subtype?(Dummy::Milk.graphql_definition, Dummy::Milk.graphql_definition.to_non_null_type)
39
+ assert subtype?(Dummy::Edible.graphql_definition, Dummy::Milk.graphql_definition.to_non_null_type)
40
+ assert subtype?(Dummy::Edible.graphql_definition.to_non_null_type, Dummy::Milk.graphql_definition.to_non_null_type)
41
41
  assert subtype?(
42
42
  GraphQL::STRING_TYPE.to_non_null_type.to_list_type,
43
43
  GraphQL::STRING_TYPE.to_non_null_type.to_list_type.to_non_null_type,
@@ -116,7 +116,7 @@ describe GraphQL::Field do
116
116
 
117
117
  describe "#metadata" do
118
118
  it "accepts user-defined metadata" do
119
- similar_cheese_field = Dummy::CheeseType.get_field("similarCheese")
119
+ similar_cheese_field = Dummy::Cheese.graphql_definition.get_field("similarCheese")
120
120
  assert_equal [:cheeses, :milks], similar_cheese_field.metadata[:joins]
121
121
  end
122
122
  end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+
4
+ describe GraphQL::InputObjectType do
5
+ describe 'default values' do
6
+ describe 'when the type is an enum with underlying ruby values' do
7
+ it 'provides the default value' do
8
+ TestEnum = GraphQL::EnumType.define do
9
+ name 'Test'
10
+
11
+ value 'A', 'Represents an authorized agent in our system.', value: 'a'
12
+ value 'B', 'Agent is disabled, web app access is denied.', value: 'b'
13
+ end
14
+
15
+ class TestInput < GraphQL::Schema::InputObject
16
+ argument :foo, TestEnum, 'TestEnum', required: false, default_value: 'a'
17
+ end
18
+
19
+ test_input_type = TestInput.to_graphql
20
+ default_test_input_value = test_input_type.coerce_isolated_input({})
21
+ assert_equal default_test_input_value[:foo], 'a'
22
+ end
23
+ end
24
+ end
25
+ end
@@ -2,11 +2,11 @@
2
2
  require "spec_helper"
3
3
 
4
4
  describe GraphQL::InterfaceType do
5
- let(:interface) { Dummy::EdibleInterface }
5
+ let(:interface) { Dummy::Edible.graphql_definition }
6
6
  let(:dummy_query_context) { OpenStruct.new(schema: Dummy::Schema) }
7
7
 
8
8
  it "has possible types" do
9
- assert_equal([Dummy::CheeseType, Dummy::HoneyType, Dummy::MilkType], Dummy::Schema.possible_types(interface))
9
+ assert_equal([Dummy::Cheese.graphql_definition, Dummy::Honey.graphql_definition, Dummy::Milk.graphql_definition], Dummy::Schema.possible_types(interface))
10
10
  end
11
11
 
12
12
  describe "query evaluation" do
@@ -96,11 +96,11 @@ describe GraphQL::InterfaceType do
96
96
  it "copies orphan types without affecting the original" do
97
97
  interface = GraphQL::InterfaceType.define do
98
98
  name "AInterface"
99
- orphan_types [Dummy::HoneyType]
99
+ orphan_types [Dummy::Honey]
100
100
  end
101
101
 
102
102
  interface_2 = interface.dup
103
- interface_2.orphan_types << Dummy::CheeseType
103
+ interface_2.orphan_types << Dummy::Cheese
104
104
  assert_equal 1, interface.orphan_types.size
105
105
  assert_equal 2, interface_2.orphan_types.size
106
106
  end