graphql 1.11.6 → 1.12.3
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 +5 -5
- data/lib/generators/graphql/object_generator.rb +2 -0
- data/lib/generators/graphql/relay_generator.rb +63 -0
- data/lib/generators/graphql/templates/base_connection.erb +8 -0
- data/lib/generators/graphql/templates/base_edge.erb +8 -0
- data/lib/generators/graphql/templates/node_type.erb +9 -0
- data/lib/generators/graphql/templates/object.erb +1 -1
- data/lib/generators/graphql/templates/query_type.erb +1 -3
- data/lib/generators/graphql/templates/schema.erb +8 -35
- data/lib/graphql.rb +39 -4
- data/lib/graphql/analysis/analyze_query.rb +7 -0
- data/lib/graphql/analysis/ast.rb +11 -2
- data/lib/graphql/analysis/ast/visitor.rb +9 -1
- data/lib/graphql/backtrace.rb +28 -19
- data/lib/graphql/backtrace/legacy_tracer.rb +56 -0
- data/lib/graphql/backtrace/table.rb +22 -2
- data/lib/graphql/backtrace/tracer.rb +40 -9
- data/lib/graphql/backwards_compatibility.rb +2 -1
- data/lib/graphql/base_type.rb +1 -1
- data/lib/graphql/compatibility/execution_specification.rb +1 -0
- data/lib/graphql/compatibility/lazy_execution_specification.rb +2 -0
- data/lib/graphql/compatibility/query_parser_specification.rb +2 -0
- data/lib/graphql/compatibility/schema_parser_specification.rb +2 -0
- data/lib/graphql/dataloader.rb +198 -0
- data/lib/graphql/dataloader/null_dataloader.rb +21 -0
- data/lib/graphql/dataloader/request.rb +24 -0
- data/lib/graphql/dataloader/request_all.rb +22 -0
- data/lib/graphql/dataloader/source.rb +93 -0
- data/lib/graphql/define/assign_global_id_field.rb +1 -1
- data/lib/graphql/define/instance_definable.rb +32 -2
- data/lib/graphql/define/type_definer.rb +5 -5
- data/lib/graphql/deprecated_dsl.rb +7 -2
- data/lib/graphql/deprecation.rb +13 -0
- data/lib/graphql/enum_type.rb +2 -0
- data/lib/graphql/execution/errors.rb +4 -0
- data/lib/graphql/execution/execute.rb +7 -0
- data/lib/graphql/execution/interpreter.rb +10 -6
- data/lib/graphql/execution/interpreter/arguments.rb +57 -5
- data/lib/graphql/execution/interpreter/arguments_cache.rb +8 -0
- data/lib/graphql/execution/interpreter/handles_raw_value.rb +0 -7
- data/lib/graphql/execution/interpreter/runtime.rb +219 -117
- data/lib/graphql/execution/multiplex.rb +20 -6
- data/lib/graphql/function.rb +4 -0
- data/lib/graphql/input_object_type.rb +2 -0
- data/lib/graphql/integer_decoding_error.rb +17 -0
- data/lib/graphql/interface_type.rb +3 -1
- data/lib/graphql/internal_representation/document.rb +2 -2
- data/lib/graphql/internal_representation/rewrite.rb +1 -1
- data/lib/graphql/invalid_null_error.rb +1 -1
- data/lib/graphql/language/document_from_schema_definition.rb +50 -23
- data/lib/graphql/object_type.rb +2 -0
- data/lib/graphql/pagination/connection.rb +5 -1
- data/lib/graphql/pagination/connections.rb +6 -16
- data/lib/graphql/query.rb +6 -1
- data/lib/graphql/query/arguments.rb +1 -1
- data/lib/graphql/query/context.rb +8 -1
- data/lib/graphql/query/serial_execution.rb +1 -0
- data/lib/graphql/query/validation_pipeline.rb +1 -1
- data/lib/graphql/relay/array_connection.rb +2 -2
- data/lib/graphql/relay/base_connection.rb +7 -0
- data/lib/graphql/relay/connection_instrumentation.rb +4 -4
- data/lib/graphql/relay/connection_type.rb +1 -1
- data/lib/graphql/relay/mutation.rb +1 -0
- data/lib/graphql/relay/node.rb +3 -0
- data/lib/graphql/relay/type_extensions.rb +2 -0
- data/lib/graphql/scalar_type.rb +2 -0
- data/lib/graphql/schema.rb +80 -29
- data/lib/graphql/schema/argument.rb +25 -7
- data/lib/graphql/schema/build_from_definition.rb +139 -51
- data/lib/graphql/schema/default_type_error.rb +2 -0
- data/lib/graphql/schema/directive.rb +76 -0
- data/lib/graphql/schema/directive/flagged.rb +57 -0
- data/lib/graphql/schema/enum.rb +3 -0
- data/lib/graphql/schema/enum_value.rb +12 -6
- data/lib/graphql/schema/field.rb +50 -22
- data/lib/graphql/schema/field/connection_extension.rb +3 -2
- data/lib/graphql/schema/field/scope_extension.rb +1 -1
- data/lib/graphql/schema/input_object.rb +33 -22
- data/lib/graphql/schema/interface.rb +1 -0
- data/lib/graphql/schema/member.rb +4 -0
- data/lib/graphql/schema/member/base_dsl_methods.rb +1 -0
- data/lib/graphql/schema/member/build_type.rb +3 -3
- data/lib/graphql/schema/member/has_arguments.rb +67 -50
- data/lib/graphql/schema/member/has_deprecation_reason.rb +25 -0
- data/lib/graphql/schema/member/has_directives.rb +98 -0
- data/lib/graphql/schema/member/has_validators.rb +31 -0
- data/lib/graphql/schema/member/type_system_helpers.rb +1 -1
- data/lib/graphql/schema/middleware_chain.rb +1 -1
- data/lib/graphql/schema/object.rb +11 -0
- data/lib/graphql/schema/printer.rb +5 -4
- data/lib/graphql/schema/relay_classic_mutation.rb +1 -1
- data/lib/graphql/schema/resolver.rb +7 -0
- data/lib/graphql/schema/resolver/has_payload_type.rb +2 -0
- data/lib/graphql/schema/subscription.rb +19 -1
- data/lib/graphql/schema/timeout_middleware.rb +3 -1
- data/lib/graphql/schema/validation.rb +4 -2
- data/lib/graphql/schema/validator.rb +163 -0
- data/lib/graphql/schema/validator/exclusion_validator.rb +31 -0
- data/lib/graphql/schema/validator/format_validator.rb +49 -0
- data/lib/graphql/schema/validator/inclusion_validator.rb +33 -0
- data/lib/graphql/schema/validator/length_validator.rb +57 -0
- data/lib/graphql/schema/validator/numericality_validator.rb +71 -0
- data/lib/graphql/schema/validator/required_validator.rb +68 -0
- data/lib/graphql/static_validation.rb +1 -0
- data/lib/graphql/static_validation/all_rules.rb +1 -0
- data/lib/graphql/static_validation/rules/fields_will_merge.rb +25 -17
- data/lib/graphql/static_validation/rules/input_object_names_are_unique.rb +30 -0
- data/lib/graphql/static_validation/rules/input_object_names_are_unique_error.rb +30 -0
- data/lib/graphql/static_validation/validation_timeout_error.rb +25 -0
- data/lib/graphql/static_validation/validator.rb +32 -9
- data/lib/graphql/subscriptions.rb +17 -20
- data/lib/graphql/subscriptions/subscription_root.rb +1 -1
- data/lib/graphql/tracing.rb +2 -2
- data/lib/graphql/tracing/appoptics_tracing.rb +3 -1
- data/lib/graphql/tracing/platform_tracing.rb +4 -2
- data/lib/graphql/tracing/prometheus_tracing/graphql_collector.rb +4 -1
- data/lib/graphql/tracing/skylight_tracing.rb +1 -1
- data/lib/graphql/types/int.rb +9 -2
- data/lib/graphql/types/relay.rb +11 -3
- data/lib/graphql/types/relay/base_connection.rb +2 -91
- data/lib/graphql/types/relay/base_edge.rb +2 -34
- data/lib/graphql/types/relay/connection_behaviors.rb +123 -0
- data/lib/graphql/types/relay/default_relay.rb +27 -0
- data/lib/graphql/types/relay/edge_behaviors.rb +42 -0
- data/lib/graphql/types/relay/has_node_field.rb +41 -0
- data/lib/graphql/types/relay/has_nodes_field.rb +41 -0
- data/lib/graphql/types/relay/node.rb +2 -4
- data/lib/graphql/types/relay/node_behaviors.rb +15 -0
- data/lib/graphql/types/relay/node_field.rb +1 -19
- data/lib/graphql/types/relay/nodes_field.rb +1 -19
- data/lib/graphql/types/relay/page_info.rb +2 -14
- data/lib/graphql/types/relay/page_info_behaviors.rb +25 -0
- data/lib/graphql/types/string.rb +7 -1
- data/lib/graphql/union_type.rb +2 -0
- data/lib/graphql/upgrader/member.rb +1 -0
- data/lib/graphql/upgrader/schema.rb +1 -0
- data/lib/graphql/version.rb +1 -1
- data/readme.md +1 -1
- metadata +53 -9
- data/lib/graphql/types/relay/base_field.rb +0 -22
- data/lib/graphql/types/relay/base_interface.rb +0 -29
- data/lib/graphql/types/relay/base_object.rb +0 -26
@@ -29,11 +29,13 @@ module GraphQL
|
|
29
29
|
|
30
30
|
include Tracing::Traceable
|
31
31
|
|
32
|
-
attr_reader :context, :queries, :schema, :max_complexity
|
32
|
+
attr_reader :context, :queries, :schema, :max_complexity, :dataloader
|
33
33
|
def initialize(schema:, queries:, context:, max_complexity:)
|
34
34
|
@schema = schema
|
35
35
|
@queries = queries
|
36
|
+
@queries.each { |q| q.multiplex = self }
|
36
37
|
@context = context
|
38
|
+
@context[:dataloader] = @dataloader = @schema.dataloader_class.new(context)
|
37
39
|
@tracers = schema.tracers + (context[:tracers] || [])
|
38
40
|
# Support `context: {backtrace: true}`
|
39
41
|
if context[:backtrace] && !@tracers.include?(GraphQL::Backtrace::Tracer)
|
@@ -79,20 +81,30 @@ module GraphQL
|
|
79
81
|
multiplex.schema.query_execution_strategy.begin_multiplex(multiplex)
|
80
82
|
queries = multiplex.queries
|
81
83
|
# Do as much eager evaluation of the query as possible
|
82
|
-
results =
|
83
|
-
|
84
|
+
results = []
|
85
|
+
queries.each_with_index do |query, idx|
|
86
|
+
multiplex.dataloader.enqueue {
|
87
|
+
results[idx] = begin_query(query, multiplex)
|
88
|
+
}
|
84
89
|
end
|
85
90
|
|
91
|
+
multiplex.dataloader.run
|
92
|
+
|
86
93
|
# Then, work through lazy results in a breadth-first way
|
87
|
-
multiplex.
|
94
|
+
multiplex.dataloader.enqueue {
|
95
|
+
multiplex.schema.query_execution_strategy.finish_multiplex(results, multiplex)
|
96
|
+
}
|
97
|
+
multiplex.dataloader.run
|
88
98
|
|
89
99
|
# Then, find all errors and assign the result to the query object
|
90
|
-
results.each_with_index
|
100
|
+
results.each_with_index do |data_result, idx|
|
91
101
|
query = queries[idx]
|
92
102
|
finish_query(data_result, query, multiplex)
|
93
103
|
# Get the Query::Result, not the Hash
|
94
|
-
query.result
|
104
|
+
results[idx] = query.result
|
95
105
|
end
|
106
|
+
|
107
|
+
results
|
96
108
|
rescue Exception
|
97
109
|
# TODO rescue at a higher level so it will catch errors in analysis, too
|
98
110
|
# Assign values here so that the query's `@executed` becomes true
|
@@ -144,6 +156,8 @@ module GraphQL
|
|
144
156
|
|
145
157
|
# use the old `query_execution_strategy` etc to run this query
|
146
158
|
def run_one_legacy(schema, query)
|
159
|
+
GraphQL::Deprecation.warn "Multiplex.run_one_legacy will be removed from GraphQL-Ruby 2.0, upgrade to the Interpreter to avoid this deprecated codepath: https://graphql-ruby.org/queries/interpreter.html"
|
160
|
+
|
147
161
|
query.result_values = if !query.valid?
|
148
162
|
all_errors = query.validation_errors + query.analysis_errors + query.context.errors
|
149
163
|
if all_errors.any?
|
data/lib/graphql/function.rb
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
module GraphQL
|
3
3
|
# @api deprecated
|
4
4
|
class Function
|
5
|
+
def self.inherited(subclass)
|
6
|
+
GraphQL::Deprecation.warn "GraphQL::Function (used for #{subclass}) will be removed from GraphQL-Ruby 2.0, please upgrade to resolvers: https://graphql-ruby.org/fields/resolvers.html"
|
7
|
+
end
|
8
|
+
|
5
9
|
# @return [Hash<String => GraphQL::Argument>] Arguments, keyed by name
|
6
10
|
def arguments
|
7
11
|
self.class.arguments
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module GraphQL
|
3
|
+
# This error is raised when `Types::Int` is given an input value outside of 32-bit integer range.
|
4
|
+
#
|
5
|
+
# For really big integer values, consider `GraphQL::Types::BigInt`
|
6
|
+
#
|
7
|
+
# @see GraphQL::Types::Int which raises this error
|
8
|
+
class IntegerDecodingError < GraphQL::RuntimeTypeError
|
9
|
+
# The value which couldn't be decoded
|
10
|
+
attr_reader :integer_value
|
11
|
+
|
12
|
+
def initialize(value)
|
13
|
+
@integer_value = value
|
14
|
+
super("Integer out of bounds: #{value}. \nConsider using GraphQL::Types::BigInt instead.")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -2,10 +2,12 @@
|
|
2
2
|
module GraphQL
|
3
3
|
# @api deprecated
|
4
4
|
class InterfaceType < GraphQL::BaseType
|
5
|
+
extend Define::InstanceDefinable::DeprecatedDefine
|
6
|
+
|
5
7
|
accepts_definitions :fields, :orphan_types, :resolve_type, field: GraphQL::Define::AssignObjectField
|
6
8
|
|
7
9
|
attr_accessor :fields, :orphan_types, :resolve_type_proc
|
8
|
-
attr_writer :type_membership_class
|
10
|
+
attr_writer :type_membership_class
|
9
11
|
ensure_defined :fields, :orphan_types, :resolve_type_proc, :resolve_type
|
10
12
|
|
11
13
|
def initialize
|
@@ -14,12 +14,12 @@ module GraphQL
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def [](key)
|
17
|
-
warn "#{self.class}#[] is deprecated; use `operation_definitions[]` instead"
|
17
|
+
GraphQL::Deprecation.warn "#{self.class}#[] is deprecated; use `operation_definitions[]` instead"
|
18
18
|
operation_definitions[key]
|
19
19
|
end
|
20
20
|
|
21
21
|
def each(&block)
|
22
|
-
warn "#{self.class}#each is deprecated; use `operation_definitions.each` instead"
|
22
|
+
GraphQL::Deprecation.warn "#{self.class}#each is deprecated; use `operation_definitions.each` instead"
|
23
23
|
operation_definitions.each(&block)
|
24
24
|
end
|
25
25
|
end
|
@@ -60,7 +60,7 @@ module GraphQL
|
|
60
60
|
|
61
61
|
# @return [Hash<String, Node>] Roots of this query
|
62
62
|
def operations
|
63
|
-
warn "#{self.class}#operations is deprecated; use `document.operation_definitions` instead"
|
63
|
+
GraphQL::Deprecation.warn "#{self.class}#operations is deprecated; use `document.operation_definitions` instead"
|
64
64
|
@document.operation_definitions
|
65
65
|
end
|
66
66
|
|
@@ -39,7 +39,7 @@ module GraphQL
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def inspect
|
42
|
-
if name.nil? && parent_class.respond_to?(:mutation) && (mutation = parent_class.mutation)
|
42
|
+
if (name.nil? || parent_class.name.nil?) && parent_class.respond_to?(:mutation) && (mutation = parent_class.mutation)
|
43
43
|
"#{mutation.inspect}::#{parent_class.graphql_name}::InvalidNullError"
|
44
44
|
else
|
45
45
|
super
|
@@ -49,6 +49,8 @@ module GraphQL
|
|
49
49
|
subscription: (s = warden.root_type_for_operation("subscription")) && s.graphql_name,
|
50
50
|
# This only supports directives from parsing,
|
51
51
|
# use a custom printer to add to this list.
|
52
|
+
#
|
53
|
+
# `@schema.directives` is covered by `build_definition_nodes`
|
52
54
|
directives: ast_directives(@schema),
|
53
55
|
)
|
54
56
|
end
|
@@ -59,7 +61,7 @@ module GraphQL
|
|
59
61
|
interfaces: warden.interfaces(object_type).sort_by(&:graphql_name).map { |iface| build_type_name_node(iface) },
|
60
62
|
fields: build_field_nodes(warden.fields(object_type)),
|
61
63
|
description: object_type.description,
|
62
|
-
directives:
|
64
|
+
directives: directives(object_type),
|
63
65
|
)
|
64
66
|
end
|
65
67
|
|
@@ -69,7 +71,7 @@ module GraphQL
|
|
69
71
|
arguments: build_argument_nodes(warden.arguments(field)),
|
70
72
|
type: build_type_name_node(field.type),
|
71
73
|
description: field.description,
|
72
|
-
directives:
|
74
|
+
directives: directives(field),
|
73
75
|
)
|
74
76
|
end
|
75
77
|
|
@@ -78,7 +80,7 @@ module GraphQL
|
|
78
80
|
name: union_type.graphql_name,
|
79
81
|
description: union_type.description,
|
80
82
|
types: warden.possible_types(union_type).sort_by(&:graphql_name).map { |type| build_type_name_node(type) },
|
81
|
-
directives:
|
83
|
+
directives: directives(union_type),
|
82
84
|
)
|
83
85
|
end
|
84
86
|
|
@@ -87,7 +89,7 @@ module GraphQL
|
|
87
89
|
name: interface_type.graphql_name,
|
88
90
|
description: interface_type.description,
|
89
91
|
fields: build_field_nodes(warden.fields(interface_type)),
|
90
|
-
directives:
|
92
|
+
directives: directives(interface_type),
|
91
93
|
)
|
92
94
|
end
|
93
95
|
|
@@ -98,7 +100,7 @@ module GraphQL
|
|
98
100
|
build_enum_value_node(enum_value)
|
99
101
|
end,
|
100
102
|
description: enum_type.description,
|
101
|
-
directives:
|
103
|
+
directives: directives(enum_type),
|
102
104
|
)
|
103
105
|
end
|
104
106
|
|
@@ -106,7 +108,7 @@ module GraphQL
|
|
106
108
|
GraphQL::Language::Nodes::EnumValueDefinition.new(
|
107
109
|
name: enum_value.graphql_name,
|
108
110
|
description: enum_value.description,
|
109
|
-
directives:
|
111
|
+
directives: directives(enum_value),
|
110
112
|
)
|
111
113
|
end
|
112
114
|
|
@@ -114,7 +116,7 @@ module GraphQL
|
|
114
116
|
GraphQL::Language::Nodes::ScalarTypeDefinition.new(
|
115
117
|
name: scalar_type.graphql_name,
|
116
118
|
description: scalar_type.description,
|
117
|
-
directives:
|
119
|
+
directives: directives(scalar_type),
|
118
120
|
)
|
119
121
|
end
|
120
122
|
|
@@ -130,7 +132,7 @@ module GraphQL
|
|
130
132
|
description: argument.description,
|
131
133
|
type: build_type_name_node(argument.type),
|
132
134
|
default_value: default_value,
|
133
|
-
directives:
|
135
|
+
directives: directives(argument),
|
134
136
|
)
|
135
137
|
|
136
138
|
argument_node
|
@@ -141,7 +143,7 @@ module GraphQL
|
|
141
143
|
name: input_object.graphql_name,
|
142
144
|
fields: build_argument_nodes(warden.arguments(input_object)),
|
143
145
|
description: input_object.description,
|
144
|
-
directives:
|
146
|
+
directives: directives(input_object),
|
145
147
|
)
|
146
148
|
end
|
147
149
|
|
@@ -155,7 +157,7 @@ module GraphQL
|
|
155
157
|
end
|
156
158
|
|
157
159
|
def build_directive_location_nodes(locations)
|
158
|
-
locations.map { |location| build_directive_location_node(location) }
|
160
|
+
locations.sort.map { |location| build_directive_location_node(location) }
|
159
161
|
end
|
160
162
|
|
161
163
|
def build_directive_location_node(location)
|
@@ -283,14 +285,37 @@ module GraphQL
|
|
283
285
|
(schema.subscription.nil? || schema.subscription.graphql_name == 'Subscription')
|
284
286
|
end
|
285
287
|
|
286
|
-
def
|
287
|
-
|
288
|
+
def directives(member)
|
289
|
+
definition_directives(member)
|
290
|
+
end
|
288
291
|
|
289
|
-
|
290
|
-
if member.respond_to?(:
|
291
|
-
|
292
|
-
|
292
|
+
def definition_directives(member)
|
293
|
+
dirs = if !member.respond_to?(:directives) || member.directives.empty?
|
294
|
+
[]
|
295
|
+
else
|
296
|
+
member.directives.map do |dir|
|
297
|
+
args = []
|
298
|
+
dir.arguments.argument_values.each_value do |arg_value|
|
299
|
+
arg_defn = arg_value.definition
|
300
|
+
if arg_defn.default_value? && arg_value.value == arg_defn.default_value
|
301
|
+
next
|
302
|
+
else
|
303
|
+
value_node = build_default_value(arg_value.value, arg_value.definition.type)
|
304
|
+
args << GraphQL::Language::Nodes::Argument.new(
|
305
|
+
name: arg_value.definition.name,
|
306
|
+
value: value_node,
|
307
|
+
)
|
308
|
+
end
|
309
|
+
end
|
310
|
+
GraphQL::Language::Nodes::Directive.new(
|
311
|
+
name: dir.class.graphql_name,
|
312
|
+
arguments: args
|
313
|
+
)
|
314
|
+
end
|
315
|
+
end
|
293
316
|
|
317
|
+
# This is just for printing legacy `.define { ... }` schemas, where `deprecation_reason` isn't added to `.directives`.
|
318
|
+
if !member.respond_to?(:directives) && member.respond_to?(:deprecation_reason) && (reason = member.deprecation_reason)
|
294
319
|
arguments = []
|
295
320
|
|
296
321
|
if reason != GraphQL::Schema::Directive::DEFAULT_DEPRECATION_REASON
|
@@ -300,15 +325,17 @@ module GraphQL
|
|
300
325
|
)
|
301
326
|
end
|
302
327
|
|
303
|
-
|
304
|
-
GraphQL::
|
305
|
-
|
306
|
-
|
307
|
-
)
|
308
|
-
]
|
328
|
+
dirs << GraphQL::Language::Nodes::Directive.new(
|
329
|
+
name: GraphQL::Directive::DeprecatedDirective.graphql_name,
|
330
|
+
arguments: arguments
|
331
|
+
)
|
309
332
|
end
|
310
333
|
|
311
|
-
|
334
|
+
dirs
|
335
|
+
end
|
336
|
+
|
337
|
+
def ast_directives(member)
|
338
|
+
member.ast_node ? member.ast_node.directives : []
|
312
339
|
end
|
313
340
|
|
314
341
|
attr_reader :schema, :warden, :always_include_schema,
|
data/lib/graphql/object_type.rb
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
module GraphQL
|
3
3
|
# @api deprecated
|
4
4
|
class ObjectType < GraphQL::BaseType
|
5
|
+
extend Define::InstanceDefinable::DeprecatedDefine
|
6
|
+
|
5
7
|
accepts_definitions :interfaces, :fields, :mutation, :relay_node_type, field: GraphQL::Define::AssignObjectField
|
6
8
|
accepts_definitions implements: ->(type, *interfaces, inherit: false) { type.implements(interfaces, inherit: inherit) }
|
7
9
|
|
@@ -53,10 +53,11 @@ module GraphQL
|
|
53
53
|
# @param last [Integer, nil] Limit parameter from the client, if provided
|
54
54
|
# @param before [String, nil] A cursor for pagination, if the client provided one.
|
55
55
|
# @param max_page_size [Integer, nil] A configured value to cap the result size. Applied as `first` if neither first or last are given.
|
56
|
-
def initialize(items, parent: nil, context: nil, first: nil, after: nil, max_page_size: :not_given, last: nil, before: nil, edge_class: nil)
|
56
|
+
def initialize(items, parent: nil, field: nil, context: nil, first: nil, after: nil, max_page_size: :not_given, last: nil, before: nil, edge_class: nil)
|
57
57
|
@items = items
|
58
58
|
@parent = parent
|
59
59
|
@context = context
|
60
|
+
@field = field
|
60
61
|
@first_value = first
|
61
62
|
@after_value = after
|
62
63
|
@last_value = last
|
@@ -118,6 +119,9 @@ module GraphQL
|
|
118
119
|
# @return [Class] A wrapper class for edges of this connection
|
119
120
|
attr_accessor :edge_class
|
120
121
|
|
122
|
+
# @return [GraphQL::Schema::Field] The field this connection was returned by
|
123
|
+
attr_accessor :field
|
124
|
+
|
121
125
|
# @return [Array<Object>] A slice of {items}, constrained by {@first_value}/{@after_value}/{@last_value}/{@before_value}
|
122
126
|
def nodes
|
123
127
|
raise PaginationImplementationMissingError, "Implement #{self.class}#nodes to paginate `@items`"
|
@@ -6,20 +6,13 @@ module GraphQL
|
|
6
6
|
#
|
7
7
|
# Attach as a plugin.
|
8
8
|
#
|
9
|
-
# @example Using new default connections
|
10
|
-
# class MySchema < GraphQL::Schema
|
11
|
-
# use GraphQL::Pagination::Connections
|
12
|
-
# end
|
13
|
-
#
|
14
9
|
# @example Adding a custom wrapper
|
15
10
|
# class MySchema < GraphQL::Schema
|
16
|
-
# use GraphQL::Pagination::Connections
|
17
11
|
# connections.add(MyApp::SearchResults, MyApp::SearchResultsConnection)
|
18
12
|
# end
|
19
13
|
#
|
20
14
|
# @example Removing default connection support for arrays (they can still be manually wrapped)
|
21
15
|
# class MySchema < GraphQL::Schema
|
22
|
-
# use GraphQL::Pagination::Connections
|
23
16
|
# connections.delete(Array)
|
24
17
|
# end
|
25
18
|
#
|
@@ -29,14 +22,10 @@ module GraphQL
|
|
29
22
|
end
|
30
23
|
|
31
24
|
def self.use(schema_defn)
|
32
|
-
if schema_defn.
|
33
|
-
|
34
|
-
else
|
35
|
-
# Unwrap a `.define` object
|
36
|
-
schema_defn = schema_defn.target
|
37
|
-
schema_defn.connections = self.new(schema: schema_defn)
|
38
|
-
schema_defn.class.connections = schema_defn.connections
|
25
|
+
if schema_defn.plugins.any? { |(plugin, args)| plugin == self }
|
26
|
+
GraphQL::Deprecation.warn("#{self} is now the default, remove `use #{self}` from #{caller(2,1).first}")
|
39
27
|
end
|
28
|
+
schema_defn.connections = self.new(schema: schema_defn)
|
40
29
|
end
|
41
30
|
|
42
31
|
def initialize(schema:)
|
@@ -76,9 +65,9 @@ module GraphQL
|
|
76
65
|
|
77
66
|
# Used by the runtime to wrap values in connection wrappers.
|
78
67
|
# @api Private
|
79
|
-
def wrap(field, parent, items, arguments, context
|
68
|
+
def wrap(field, parent, items, arguments, context)
|
80
69
|
return items if GraphQL::Execution::Interpreter::RawValue === items
|
81
|
-
|
70
|
+
wrappers = context ? context.namespace(:connections)[:all_wrappers] : all_wrappers
|
82
71
|
impl = wrapper_for(items, wrappers: wrappers)
|
83
72
|
|
84
73
|
if impl.nil?
|
@@ -89,6 +78,7 @@ module GraphQL
|
|
89
78
|
items,
|
90
79
|
context: context,
|
91
80
|
parent: parent,
|
81
|
+
field: field,
|
92
82
|
max_page_size: field.max_page_size || context.schema.default_max_page_size,
|
93
83
|
first: arguments[:first],
|
94
84
|
after: arguments[:after],
|
data/lib/graphql/query.rb
CHANGED
@@ -88,6 +88,7 @@ module GraphQL
|
|
88
88
|
schema = schema.graphql_definition
|
89
89
|
end
|
90
90
|
@schema = schema
|
91
|
+
@interpreter = @schema.interpreter?
|
91
92
|
@filter = schema.default_filter.merge(except: except, only: only)
|
92
93
|
@context = schema.context_class.new(query: self, object: root_value, values: context)
|
93
94
|
@warden = warden
|
@@ -148,7 +149,11 @@ module GraphQL
|
|
148
149
|
@query_string ||= (document ? document.to_query_string : nil)
|
149
150
|
end
|
150
151
|
|
151
|
-
|
152
|
+
def interpreter?
|
153
|
+
@interpreter
|
154
|
+
end
|
155
|
+
|
156
|
+
attr_accessor :multiplex
|
152
157
|
|
153
158
|
def subscription_update?
|
154
159
|
@subscription_topic && subscription?
|
@@ -22,7 +22,7 @@ module GraphQL
|
|
22
22
|
method_names.each do |method_name|
|
23
23
|
# Don't define a helper method if it would override something.
|
24
24
|
if method_defined?(method_name)
|
25
|
-
warn(
|
25
|
+
GraphQL::Deprecation.warn(
|
26
26
|
"Unable to define a helper for argument with name '#{method_name}' "\
|
27
27
|
"as this is a reserved name. Add `method_access: false` to stop this warning."
|
28
28
|
)
|
@@ -158,6 +158,10 @@ module GraphQL
|
|
158
158
|
@scoped_context = {}
|
159
159
|
end
|
160
160
|
|
161
|
+
def dataloader
|
162
|
+
@dataloader ||= query.multiplex.dataloader
|
163
|
+
end
|
164
|
+
|
161
165
|
# @api private
|
162
166
|
attr_writer :interpreter
|
163
167
|
|
@@ -167,7 +171,10 @@ module GraphQL
|
|
167
171
|
# @api private
|
168
172
|
attr_accessor :scoped_context
|
169
173
|
|
170
|
-
|
174
|
+
def []=(key, value)
|
175
|
+
@provided_values[key] = value
|
176
|
+
end
|
177
|
+
|
171
178
|
def_delegators :@query, :trace, :interpreter?
|
172
179
|
|
173
180
|
# @!method []=(key, value)
|