graphql 1.8.8 → 1.8.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/graphql/base_type.rb +1 -1
- data/lib/graphql/compatibility/execution_specification/specification_schema.rb +1 -2
- data/lib/graphql/enum_type.rb +4 -0
- data/lib/graphql/execution/execute.rb +2 -2
- data/lib/graphql/field.rb +1 -7
- data/lib/graphql/schema.rb +25 -3
- data/lib/graphql/schema/argument.rb +3 -4
- data/lib/graphql/schema/field.rb +19 -4
- data/lib/graphql/types/iso_8601_date_time.rb +15 -1
- data/lib/graphql/version.rb +1 -1
- data/readme.md +1 -1
- data/spec/graphql/analysis/analyze_query_spec.rb +1 -1
- data/spec/graphql/base_type_spec.rb +3 -3
- data/spec/graphql/enum_type_spec.rb +1 -1
- data/spec/graphql/execution/lazy_spec.rb +18 -1
- data/spec/graphql/execution/typecast_spec.rb +20 -20
- data/spec/graphql/field_spec.rb +1 -1
- data/spec/graphql/input_object_type_spec.rb +25 -0
- data/spec/graphql/interface_type_spec.rb +4 -4
- data/spec/graphql/introspection/input_value_type_spec.rb +1 -1
- data/spec/graphql/object_type_spec.rb +32 -27
- data/spec/graphql/query/executor_spec.rb +2 -2
- data/spec/graphql/schema/argument_spec.rb +27 -0
- data/spec/graphql/schema/field_spec.rb +16 -0
- data/spec/graphql/schema/interface_spec.rb +2 -2
- data/spec/graphql/schema/relay_classic_mutation_spec.rb +36 -0
- data/spec/graphql/schema/traversal_spec.rb +10 -10
- data/spec/graphql/schema/type_expression_spec.rb +2 -2
- data/spec/graphql/schema/validation_spec.rb +1 -1
- data/spec/graphql/types/iso_8601_date_time_spec.rb +25 -0
- data/spec/graphql/union_type_spec.rb +2 -2
- data/spec/integration/rails/graphql/input_object_type_spec.rb +4 -4
- data/spec/integration/rails/graphql/query/variables_spec.rb +7 -7
- data/spec/integration/rails/graphql/schema_spec.rb +6 -5
- data/spec/integration/tmp/app/graphql/types/page_type.rb +4 -0
- data/spec/support/dummy/data.rb +20 -17
- data/spec/support/dummy/schema.rb +271 -281
- data/spec/support/jazz.rb +45 -0
- data/spec/support/lazy_helpers.rb +13 -4
- metadata +216 -212
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4378912bdbb59ceaa6006848e6eda269f1185df1
|
4
|
+
data.tar.gz: 5dd1788b97f608a67ffa5c27f6848a575f996daa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f9e4c341f98a13ad1018c0ae9b5c1f1063f5c5cbf8485b29c164f485f79257b8dc148db9fb959fdad9e8aa9f3d4eb05648a27b9a2168387ca3649b994f200ab
|
7
|
+
data.tar.gz: e5cbe104fb2f6d06f4fdf0cf51f931367845f933440e8143897207af1bfb7302c6ae7fca0d823cc3b593bb5f83545c3c030a00c6c5a9d008b9f545a1666a52dd
|
data/lib/graphql/base_type.rb
CHANGED
@@ -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
|
-
|
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
|
data/lib/graphql/enum_type.rb
CHANGED
@@ -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
|
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
|
-
|
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
|
data/lib/graphql/field.rb
CHANGED
@@ -323,13 +323,7 @@ module GraphQL
|
|
323
323
|
|
324
324
|
module DefaultLazyResolve
|
325
325
|
def self.call(obj, args, ctx)
|
326
|
-
|
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
|
data/lib/graphql/schema.rb
CHANGED
@@ -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 (
|
1004
|
+
if lazy?(value)
|
1005
1005
|
GraphQL::Execution::Lazy.new do
|
1006
|
-
result = value
|
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
|
-
|
101
|
-
when nil
|
100
|
+
if @prepare.nil?
|
102
101
|
value
|
103
|
-
|
102
|
+
elsif @prepare.is_a?(String) || @prepare.is_a?(Symbol)
|
104
103
|
obj.public_send(@prepare, value)
|
105
|
-
|
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}"
|
data/lib/graphql/schema/field.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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]
|
data/lib/graphql/version.rb
CHANGED
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/
|
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::
|
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::
|
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::
|
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::
|
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
|
@@ -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(
|
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::
|
12
|
-
assert !subtype?(Dummy::
|
13
|
-
assert subtype?(Dummy::
|
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::
|
18
|
-
assert subtype?(Dummy::
|
19
|
-
assert subtype?(Dummy::
|
20
|
-
assert subtype?(Dummy::
|
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::
|
23
|
-
assert !subtype?(Dummy::
|
24
|
-
assert !subtype?(Dummy::
|
25
|
-
assert !subtype?(Dummy::
|
26
|
-
assert !subtype?(Dummy::
|
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::
|
31
|
-
assert subtype?(Dummy::
|
32
|
-
assert !subtype?(Dummy::
|
33
|
-
assert !subtype?(Dummy::
|
34
|
-
assert !subtype?(Dummy::
|
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::
|
39
|
-
assert subtype?(Dummy::
|
40
|
-
assert subtype?(Dummy::
|
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,
|
data/spec/graphql/field_spec.rb
CHANGED
@@ -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::
|
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::
|
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::
|
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::
|
99
|
+
orphan_types [Dummy::Honey]
|
100
100
|
end
|
101
101
|
|
102
102
|
interface_2 = interface.dup
|
103
|
-
interface_2.orphan_types << Dummy::
|
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
|