graphql 2.0.3 → 2.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/generators/graphql/install_generator.rb +1 -1
- data/lib/graphql/introspection/type_type.rb +1 -1
- data/lib/graphql/introspection.rb +1 -1
- data/lib/graphql/pagination/array_connection.rb +4 -2
- data/lib/graphql/schema/field.rb +35 -35
- data/lib/graphql/schema/loader.rb +1 -1
- data/lib/graphql/schema/member/has_arguments.rb +13 -1
- data/lib/graphql/schema/member/has_fields.rb +1 -1
- data/lib/graphql/schema/relay_classic_mutation.rb +4 -0
- data/lib/graphql/schema/resolver.rb +3 -3
- data/lib/graphql/schema.rb +1 -0
- data/lib/graphql/types/iso_8601_date.rb +4 -1
- data/lib/graphql/types/iso_8601_date_time.rb +1 -0
- data/lib/graphql/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c31ecaae04f8ea6bca65c031a2a41d124d8a1e1dade016decfb047cae3f900ae
|
4
|
+
data.tar.gz: af77a6ac50b38ca0d23a08da8f63fea1ca8f14ef11ccda56de55e678518380c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6038fd4fe140b2196011e14cc61ba8b0ad72008b3cbe9d317bc87996fe6b42f7f289e188cd0d8c22a9d5f08c558d9774fa3533690355a16258b8276ad885e53
|
7
|
+
data.tar.gz: ff7c5db4532240f9c11d7f3008441f27c5b3a6948cfe942eaf337711436fe9c678de913a849a2e627689a15a08bb2f90f9a345185945308669447ec31dd61027
|
@@ -47,7 +47,7 @@ module Graphql
|
|
47
47
|
#
|
48
48
|
# Accept a `--batch` option which adds `GraphQL::Batch` setup.
|
49
49
|
#
|
50
|
-
# Use `--
|
50
|
+
# Use `--skip-graphiql` to skip `graphiql-rails` installation.
|
51
51
|
#
|
52
52
|
# TODO: also add base classes
|
53
53
|
class InstallGenerator < Rails::Generators::Base
|
@@ -35,9 +35,11 @@ module GraphQL
|
|
35
35
|
def load_nodes
|
36
36
|
@nodes ||= begin
|
37
37
|
sliced_nodes = if before && after
|
38
|
-
|
38
|
+
end_idx = index_from_cursor(before)-1
|
39
|
+
end_idx < 0 ? [] : items[index_from_cursor(after)..end_idx] || []
|
39
40
|
elsif before
|
40
|
-
|
41
|
+
end_idx = index_from_cursor(before)-2
|
42
|
+
end_idx < 0 ? [] : items[0..end_idx] || []
|
41
43
|
elsif after
|
42
44
|
items[index_from_cursor(after)..-1] || []
|
43
45
|
else
|
data/lib/graphql/schema/field.rb
CHANGED
@@ -28,6 +28,9 @@ module GraphQL
|
|
28
28
|
# @return [String] Method or hash key on the underlying object to look up
|
29
29
|
attr_reader :method_str
|
30
30
|
|
31
|
+
attr_reader :hash_key
|
32
|
+
attr_reader :dig_keys
|
33
|
+
|
31
34
|
# @return [Symbol] The method on the type to look up
|
32
35
|
def resolver_method
|
33
36
|
if @resolver_class
|
@@ -187,7 +190,7 @@ module GraphQL
|
|
187
190
|
# @param name [Symbol] The underscore-cased version of this field name (will be camelized for the GraphQL API)
|
188
191
|
# @param type [Class, GraphQL::BaseType, Array] The return type of this field
|
189
192
|
# @param owner [Class] The type that this field belongs to
|
190
|
-
# @param null [Boolean] `true` if this field may return `null`, `false` if it is never `null`
|
193
|
+
# @param null [Boolean] (defaults to `true`) `true` if this field may return `null`, `false` if it is never `null`
|
191
194
|
# @param description [String] Field description
|
192
195
|
# @param deprecation_reason [String] If present, the field is marked "deprecated" with this message
|
193
196
|
# @param method [Symbol] The method to call on the underlying object to resolve this field (defaults to `name`)
|
@@ -211,7 +214,7 @@ module GraphQL
|
|
211
214
|
# @param ast_node [Language::Nodes::FieldDefinition, nil] If this schema was parsed from definition, this AST node defined the field
|
212
215
|
# @param method_conflict_warning [Boolean] If false, skip the warning if this field's method conflicts with a built-in method
|
213
216
|
# @param validates [Array<Hash>] Configurations for validating this field
|
214
|
-
def initialize(type: nil, name: nil, owner: nil, null:
|
217
|
+
def initialize(type: nil, name: nil, owner: nil, null: nil, description: :not_given, deprecation_reason: nil, method: nil, hash_key: nil, dig: nil, resolver_method: nil, connection: nil, max_page_size: :not_given, scope: nil, introspection: false, camelize: true, trace: nil, complexity: nil, ast_node: nil, extras: EMPTY_ARRAY, extensions: EMPTY_ARRAY, connection_extension: self.class.connection_extension, resolver_class: nil, subscription_scope: nil, relay_node_field: false, relay_nodes_field: false, method_conflict_warning: true, broadcastable: nil, arguments: EMPTY_HASH, directives: EMPTY_HASH, validates: EMPTY_ARRAY, &definition_block)
|
215
218
|
if name.nil?
|
216
219
|
raise ArgumentError, "missing first `name` argument or keyword `name:`"
|
217
220
|
end
|
@@ -243,17 +246,22 @@ module GraphQL
|
|
243
246
|
end
|
244
247
|
end
|
245
248
|
|
246
|
-
|
247
|
-
method_name = method || hash_key || name_s
|
249
|
+
method_name = method || name_s
|
248
250
|
@dig_keys = dig
|
249
|
-
|
251
|
+
@hash_key = hash_key
|
250
252
|
|
251
253
|
@method_str = -method_name.to_s
|
252
254
|
@method_sym = method_name.to_sym
|
253
|
-
@resolver_method = resolver_method
|
255
|
+
@resolver_method = (resolver_method || name_s).to_sym
|
254
256
|
@complexity = complexity
|
255
257
|
@return_type_expr = type
|
256
|
-
@return_type_null = null
|
258
|
+
@return_type_null = if !null.nil?
|
259
|
+
null
|
260
|
+
elsif resolver_class
|
261
|
+
nil
|
262
|
+
else
|
263
|
+
true
|
264
|
+
end
|
257
265
|
@connection = connection
|
258
266
|
@has_max_page_size = max_page_size != :not_given
|
259
267
|
@max_page_size = max_page_size == :not_given ? nil : max_page_size
|
@@ -530,17 +538,13 @@ module GraphQL
|
|
530
538
|
attr_writer :type
|
531
539
|
|
532
540
|
def type
|
533
|
-
if @
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
# Not enough info to determine type
|
538
|
-
message = "Can't determine the return type for #{self.path}"
|
539
|
-
if @resolver_class
|
540
|
-
message += " (it has `resolver: #{@resolver_class}`, perhaps that class is missing a `type ...` declaration, or perhaps its type causes a cyclical loading issue)"
|
541
|
-
end
|
542
|
-
raise MissingReturnTypeError, message
|
541
|
+
if @resolver_class
|
542
|
+
return_type = @return_type_expr || @resolver_class.type_expr
|
543
|
+
if return_type.nil?
|
544
|
+
raise MissingReturnTypeError, "Can't determine the return type for #{self.path} (it has `resolver: #{@resolver_class}`, perhaps that class is missing a `type ...` declaration, or perhaps its type causes a cyclical loading issue)"
|
543
545
|
end
|
546
|
+
nullable = @return_type_null.nil? ? @resolver_class.null : @return_type_null
|
547
|
+
Member::BuildType.parse_type(return_type, null: nullable)
|
544
548
|
else
|
545
549
|
@type ||= Member::BuildType.parse_type(@return_type_expr, null: @return_type_null)
|
546
550
|
end
|
@@ -633,14 +637,13 @@ module GraphQL
|
|
633
637
|
obj = @resolver_class.new(object: obj, context: query_ctx, field: self)
|
634
638
|
end
|
635
639
|
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
if obj.respond_to?(resolver_method)
|
640
|
+
inner_object = obj.object
|
641
|
+
|
642
|
+
if @hash_key
|
643
|
+
inner_object[@hash_key]
|
644
|
+
elsif @dig_keys
|
645
|
+
inner_object.dig(*@dig_keys)
|
646
|
+
elsif obj.respond_to?(resolver_method)
|
644
647
|
method_to_call = resolver_method
|
645
648
|
method_receiver = obj
|
646
649
|
# Call the method with kwargs, if there are any
|
@@ -649,30 +652,27 @@ module GraphQL
|
|
649
652
|
else
|
650
653
|
obj.public_send(resolver_method)
|
651
654
|
end
|
652
|
-
elsif
|
653
|
-
inner_object
|
654
|
-
if @dig_keys
|
655
|
-
inner_object.dig(*@dig_keys)
|
656
|
-
elsif inner_object.key?(@method_sym)
|
655
|
+
elsif inner_object.is_a?(Hash)
|
656
|
+
if inner_object.key?(@method_sym)
|
657
657
|
inner_object[@method_sym]
|
658
658
|
else
|
659
659
|
inner_object[@method_str]
|
660
660
|
end
|
661
|
-
elsif
|
661
|
+
elsif inner_object.respond_to?(@method_sym)
|
662
662
|
method_to_call = @method_sym
|
663
663
|
method_receiver = obj.object
|
664
664
|
if ruby_kwargs.any?
|
665
|
-
|
665
|
+
inner_object.public_send(@method_sym, **ruby_kwargs)
|
666
666
|
else
|
667
|
-
|
667
|
+
inner_object.public_send(@method_sym)
|
668
668
|
end
|
669
669
|
else
|
670
670
|
raise <<-ERR
|
671
671
|
Failed to implement #{@owner.graphql_name}.#{@name}, tried:
|
672
672
|
|
673
673
|
- `#{obj.class}##{resolver_method}`, which did not exist
|
674
|
-
- `#{
|
675
|
-
- Looking up hash key `#{@method_sym.inspect}` or `#{@method_str.inspect}` on `#{
|
674
|
+
- `#{inner_object.class}##{@method_sym}`, which did not exist
|
675
|
+
- Looking up hash key `#{@method_sym.inspect}` or `#{@method_str.inspect}` on `#{inner_object}`, but it wasn't a Hash
|
676
676
|
|
677
677
|
To implement this field, define one of the methods above (and check for typos)
|
678
678
|
ERR
|
@@ -148,7 +148,19 @@ module GraphQL
|
|
148
148
|
end
|
149
149
|
elsif defined?(@resolver_class) && @resolver_class
|
150
150
|
all_defns = {}
|
151
|
-
|
151
|
+
@resolver_class.all_field_argument_definitions.each do |arg_defn|
|
152
|
+
key = arg_defn.graphql_name
|
153
|
+
case (current_value = all_defns[key])
|
154
|
+
when nil
|
155
|
+
all_defns[key] = arg_defn
|
156
|
+
when Array
|
157
|
+
current_value << arg_defn
|
158
|
+
when GraphQL::Schema::Argument
|
159
|
+
all_defns[key] = [current_value, arg_defn]
|
160
|
+
else
|
161
|
+
raise "Invariant: Unexpected argument definition, #{current_value.class}: #{current_value.inspect}"
|
162
|
+
end
|
163
|
+
end
|
152
164
|
all_defns.merge!(own_arguments)
|
153
165
|
else
|
154
166
|
all_defns = own_arguments
|
@@ -72,7 +72,7 @@ module GraphQL
|
|
72
72
|
def add_field(field_defn, method_conflict_warning: field_defn.method_conflict_warning?)
|
73
73
|
# Check that `field_defn.original_name` equals `resolver_method` and `method_sym` --
|
74
74
|
# that shows that no override value was given manually.
|
75
|
-
if method_conflict_warning && CONFLICT_FIELD_NAMES.include?(field_defn.resolver_method) && field_defn.original_name == field_defn.resolver_method && field_defn.original_name == field_defn.method_sym
|
75
|
+
if method_conflict_warning && CONFLICT_FIELD_NAMES.include?(field_defn.resolver_method) && field_defn.original_name == field_defn.resolver_method && field_defn.original_name == field_defn.method_sym && field_defn.hash_key.nil? && field_defn.dig_keys.nil?
|
76
76
|
warn(conflict_field_name_warning(field_defn))
|
77
77
|
end
|
78
78
|
prev_defn = own_fields[field_defn.name]
|
@@ -92,6 +92,10 @@ module GraphQL
|
|
92
92
|
dummy.own_arguments
|
93
93
|
end
|
94
94
|
|
95
|
+
def all_field_argument_definitions
|
96
|
+
dummy.all_argument_definitions
|
97
|
+
end
|
98
|
+
|
95
99
|
# Also apply this argument to the input type:
|
96
100
|
def argument(*args, own_argument: false, **kwargs, &block)
|
97
101
|
it = input_type # make sure any inherited arguments are already added to it
|
@@ -73,7 +73,7 @@ module GraphQL
|
|
73
73
|
context.schema.after_lazy(ready_val) do |is_ready, ready_early_return|
|
74
74
|
if ready_early_return
|
75
75
|
if is_ready != false
|
76
|
-
raise "Unexpected result from #ready? (expected `true`, `false` or `[false, {...}]`): [#{
|
76
|
+
raise "Unexpected result from #ready? (expected `true`, `false` or `[false, {...}]`): [#{is_ready.inspect}, #{ready_early_return.inspect}]"
|
77
77
|
else
|
78
78
|
ready_early_return
|
79
79
|
end
|
@@ -216,8 +216,8 @@ module GraphQL
|
|
216
216
|
get_argument(name, context)
|
217
217
|
end
|
218
218
|
|
219
|
-
def
|
220
|
-
|
219
|
+
def all_field_argument_definitions
|
220
|
+
all_argument_definitions
|
221
221
|
end
|
222
222
|
|
223
223
|
# Default `:resolve` set below.
|
data/lib/graphql/schema.rb
CHANGED
@@ -14,6 +14,7 @@ module GraphQL
|
|
14
14
|
# own Date type.
|
15
15
|
class ISO8601Date < GraphQL::Schema::Scalar
|
16
16
|
description "An ISO 8601-encoded date"
|
17
|
+
specified_by_url "https://tools.ietf.org/html/rfc3339"
|
17
18
|
|
18
19
|
# @param value [Date,Time,DateTime,String]
|
19
20
|
# @return [String]
|
@@ -22,7 +23,7 @@ module GraphQL
|
|
22
23
|
end
|
23
24
|
|
24
25
|
# @param str_value [String, Date, DateTime, Time]
|
25
|
-
# @return [Date]
|
26
|
+
# @return [Date, nil]
|
26
27
|
def self.coerce_input(value, ctx)
|
27
28
|
if value.is_a?(::Date)
|
28
29
|
value
|
@@ -30,6 +31,8 @@ module GraphQL
|
|
30
31
|
value.to_date
|
31
32
|
elsif value.is_a?(::Time)
|
32
33
|
value.to_date
|
34
|
+
elsif value.nil?
|
35
|
+
nil
|
33
36
|
else
|
34
37
|
Date.iso8601(value)
|
35
38
|
end
|
@@ -17,6 +17,7 @@ module GraphQL
|
|
17
17
|
# own DateTime type.
|
18
18
|
class ISO8601DateTime < GraphQL::Schema::Scalar
|
19
19
|
description "An ISO 8601-encoded datetime"
|
20
|
+
specified_by_url "https://tools.ietf.org/html/rfc3339"
|
20
21
|
|
21
22
|
# It's not compatible with Rails' default,
|
22
23
|
# i.e. ActiveSupport::JSON::Encoder.time_precision (3 by default)
|
data/lib/graphql/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Mosolgo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: benchmark-ips
|
@@ -596,7 +596,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
596
596
|
- !ruby/object:Gem::Version
|
597
597
|
version: '0'
|
598
598
|
requirements: []
|
599
|
-
rubygems_version: 3.
|
599
|
+
rubygems_version: 3.2.32
|
600
600
|
signing_key:
|
601
601
|
specification_version: 4
|
602
602
|
summary: A GraphQL language and runtime for Ruby
|