graphql 1.11.10 → 1.12.0
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/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/analysis/analyze_query.rb +7 -0
- data/lib/graphql/analysis/ast/visitor.rb +9 -1
- data/lib/graphql/analysis/ast.rb +11 -2
- 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/backtrace.rb +28 -19
- data/lib/graphql/backwards_compatibility.rb +1 -0
- 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/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/dataloader.rb +197 -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 +5 -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/arguments.rb +51 -14
- data/lib/graphql/execution/interpreter/handles_raw_value.rb +0 -7
- data/lib/graphql/execution/interpreter/runtime.rb +210 -124
- data/lib/graphql/execution/interpreter.rb +10 -6
- 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/interface_type.rb +3 -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/context.rb +4 -0
- data/lib/graphql/query/serial_execution.rb +1 -0
- data/lib/graphql/query/validation_pipeline.rb +1 -1
- data/lib/graphql/query.rb +2 -0
- 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/argument.rb +25 -7
- data/lib/graphql/schema/build_from_definition.rb +139 -51
- data/lib/graphql/schema/directive/flagged.rb +57 -0
- data/lib/graphql/schema/directive.rb +76 -0
- data/lib/graphql/schema/enum.rb +3 -0
- data/lib/graphql/schema/enum_value.rb +12 -6
- data/lib/graphql/schema/field/connection_extension.rb +3 -2
- data/lib/graphql/schema/field.rb +28 -9
- data/lib/graphql/schema/input_object.rb +33 -22
- data/lib/graphql/schema/interface.rb +1 -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 +24 -6
- 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/member.rb +4 -0
- data/lib/graphql/schema/object.rb +11 -0
- data/lib/graphql/schema/printer.rb +5 -4
- data/lib/graphql/schema/resolver/has_payload_type.rb +2 -0
- data/lib/graphql/schema/resolver.rb +7 -0
- data/lib/graphql/schema/subscription.rb +19 -1
- data/lib/graphql/schema/timeout_middleware.rb +2 -0
- data/lib/graphql/schema/validation.rb +2 -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/schema/validator.rb +163 -0
- data/lib/graphql/schema.rb +72 -49
- data/lib/graphql/static_validation/base_visitor.rb +0 -3
- data/lib/graphql/static_validation/rules/fields_will_merge.rb +4 -4
- data/lib/graphql/static_validation/rules/fragments_are_finite.rb +2 -2
- data/lib/graphql/static_validation/validation_context.rb +1 -6
- data/lib/graphql/static_validation/validator.rb +12 -14
- data/lib/graphql/subscriptions.rb +17 -20
- data/lib/graphql/tracing/appoptics_tracing.rb +3 -1
- data/lib/graphql/tracing/platform_tracing.rb +3 -1
- data/lib/graphql/tracing/skylight_tracing.rb +1 -1
- data/lib/graphql/tracing.rb +2 -2
- data/lib/graphql/types/relay/base_connection.rb +2 -92
- data/lib/graphql/types/relay/base_edge.rb +2 -35
- 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/relay.rb +11 -3
- 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/lib/graphql.rb +38 -4
- metadata +31 -6
- 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
@@ -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
|
+
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],
|
@@ -16,6 +16,7 @@ module GraphQL
|
|
16
16
|
# @param query_object [GraphQL::Query] the query object for this execution
|
17
17
|
# @return [Hash] a spec-compliant GraphQL result, as a hash
|
18
18
|
def execute(ast_operation, root_type, query_object)
|
19
|
+
warn "#{self.class} will be removed in GraphQL-Ruby 2.0, please upgrade to the Interpreter: https://graphql-ruby.org/queries/interpreter.html"
|
19
20
|
operation_resolution.resolve(
|
20
21
|
query_object.irep_selection,
|
21
22
|
root_type,
|
@@ -72,7 +72,7 @@ module GraphQL
|
|
72
72
|
elsif @operation_name_error
|
73
73
|
@validation_errors << @operation_name_error
|
74
74
|
else
|
75
|
-
validation_result = @schema.static_validator.validate(@query, validate: @validate, timeout: @schema.validate_timeout
|
75
|
+
validation_result = @schema.static_validator.validate(@query, validate: @validate, timeout: @schema.validate_timeout)
|
76
76
|
@validation_errors.concat(validation_result[:errors])
|
77
77
|
@internal_representation = validation_result[:irep]
|
78
78
|
|
data/lib/graphql/query.rb
CHANGED
@@ -59,6 +59,13 @@ module GraphQL
|
|
59
59
|
# @param parent [Object] The object which this collection belongs to
|
60
60
|
# @param context [GraphQL::Query::Context] The context from the field being resolved
|
61
61
|
def initialize(nodes, arguments, field: nil, max_page_size: nil, parent: nil, context: nil)
|
62
|
+
warn "GraphQL::Relay::BaseConnection (used for #{self.class}) will be removed from GraphQL-Ruby 2.0, use GraphQL::Pagination::Connections instead: https://graphql-ruby.org/pagination/overview.html"
|
63
|
+
|
64
|
+
deprecated_caller = caller(0, 10).find { |c| !c.include?("lib/graphql") }
|
65
|
+
if deprecated_caller
|
66
|
+
warn " -> called from #{deprecated_caller}"
|
67
|
+
end
|
68
|
+
|
62
69
|
@context = context
|
63
70
|
@nodes = nodes
|
64
71
|
@arguments = arguments
|
@@ -10,10 +10,10 @@ module GraphQL
|
|
10
10
|
def self.default_arguments
|
11
11
|
@default_arguments ||= begin
|
12
12
|
argument_definitions = [
|
13
|
-
["first", GraphQL::
|
14
|
-
["after", GraphQL::
|
15
|
-
["last", GraphQL::
|
16
|
-
["before", GraphQL::
|
13
|
+
["first", GraphQL::DEPRECATED_INT_TYPE, "Returns the first _n_ elements from the list."],
|
14
|
+
["after", GraphQL::DEPRECATED_STRING_TYPE, "Returns the elements in the list that come after the specified cursor."],
|
15
|
+
["last", GraphQL::DEPRECATED_INT_TYPE, "Returns the last _n_ elements from the list."],
|
16
|
+
["before", GraphQL::DEPRECATED_STRING_TYPE, "Returns the elements in the list that come before the specified cursor."],
|
17
17
|
]
|
18
18
|
|
19
19
|
argument_definitions.reduce({}) do |memo, arg_defn|
|
@@ -20,7 +20,7 @@ module GraphQL
|
|
20
20
|
# Any call that would trigger `wrapped_type.ensure_defined`
|
21
21
|
# must be inside this lazy block, otherwise we get weird
|
22
22
|
# cyclical dependency errors :S
|
23
|
-
ObjectType.
|
23
|
+
ObjectType.deprecated_define do
|
24
24
|
type_name = wrapped_type.is_a?(GraphQL::BaseType) ? wrapped_type.name : wrapped_type.graphql_name
|
25
25
|
edge_type ||= wrapped_type.edge_type
|
26
26
|
name("#{type_name}Connection")
|
@@ -30,6 +30,7 @@ module GraphQL
|
|
30
30
|
alias :input_fields :arguments
|
31
31
|
|
32
32
|
def initialize
|
33
|
+
warn "GraphQL::Relay::Mutation will be removed from GraphQL-Ruby 2.0, use GraphQL::Schema::RelayClassicMutation instead: https://graphql-ruby.org/mutations/mutation_classes"
|
33
34
|
@fields = {}
|
34
35
|
@arguments = {}
|
35
36
|
@has_generated_return_type = false
|
data/lib/graphql/relay/node.rb
CHANGED
@@ -5,6 +5,7 @@ module GraphQL
|
|
5
5
|
module Node
|
6
6
|
# @return [GraphQL::Field] a field for finding objects by their global ID.
|
7
7
|
def self.field(**kwargs, &block)
|
8
|
+
warn "GraphQL::Relay::Node.field will be removed from GraphQL-Ruby 2.0, use GraphQL::Types::Relay::NodeField instead"
|
8
9
|
# We have to define it fresh each time because
|
9
10
|
# its name will be modified and its description
|
10
11
|
# _may_ be modified.
|
@@ -18,6 +19,7 @@ module GraphQL
|
|
18
19
|
end
|
19
20
|
|
20
21
|
def self.plural_field(**kwargs, &block)
|
22
|
+
warn "GraphQL::Relay::Nodes.field will be removed from GraphQL-Ruby 2.0, use GraphQL::Types::Relay::NodesField instead"
|
21
23
|
field = GraphQL::Types::Relay::NodesField.graphql_definition
|
22
24
|
|
23
25
|
if kwargs.any? || block
|
@@ -29,6 +31,7 @@ module GraphQL
|
|
29
31
|
|
30
32
|
# @return [GraphQL::InterfaceType] The interface which all Relay types must implement
|
31
33
|
def self.interface
|
34
|
+
warn "GraphQL::Relay::Node.interface will be removed from GraphQL-Ruby 2.0, use GraphQL::Types::Relay::Node instead"
|
32
35
|
@interface ||= GraphQL::Types::Relay::Node.graphql_definition
|
33
36
|
end
|
34
37
|
end
|
@@ -12,6 +12,7 @@ module GraphQL
|
|
12
12
|
# Define a custom connection type for this object type
|
13
13
|
# @return [GraphQL::ObjectType]
|
14
14
|
def define_connection(**kwargs, &block)
|
15
|
+
warn ".connection_type and .define_connection will be removed from GraphQL-Ruby 2.0, use class-based type definitions instead: https://graphql-ruby.org/schema/class_based_api.html"
|
15
16
|
GraphQL::Relay::ConnectionType.create_type(self, **kwargs, &block)
|
16
17
|
end
|
17
18
|
|
@@ -23,6 +24,7 @@ module GraphQL
|
|
23
24
|
# Define a custom edge type for this object type
|
24
25
|
# @return [GraphQL::ObjectType]
|
25
26
|
def define_edge(**kwargs, &block)
|
27
|
+
warn ".edge_type and .define_edge will be removed from GraphQL-Ruby 2.0, use class-based type definitions instead: https://graphql-ruby.org/schema/class_based_api.html"
|
26
28
|
GraphQL::Relay::EdgeType.create_type(self, **kwargs, &block)
|
27
29
|
end
|
28
30
|
end
|
data/lib/graphql/scalar_type.rb
CHANGED
@@ -10,6 +10,10 @@ module GraphQL
|
|
10
10
|
include GraphQL::Schema::Member::AcceptsDefinition
|
11
11
|
include GraphQL::Schema::Member::HasPath
|
12
12
|
include GraphQL::Schema::Member::HasAstNode
|
13
|
+
include GraphQL::Schema::Member::HasDirectives
|
14
|
+
include GraphQL::Schema::Member::HasDeprecationReason
|
15
|
+
include GraphQL::Schema::Member::HasValidators
|
16
|
+
include GraphQL::Schema::FindInheritedValue::EmptyObjects
|
13
17
|
|
14
18
|
NO_DEFAULT = :__no_default__
|
15
19
|
|
@@ -45,8 +49,10 @@ module GraphQL
|
|
45
49
|
# @param camelize [Boolean] if true, the name will be camelized when building the schema
|
46
50
|
# @param from_resolver [Boolean] if true, a Resolver class defined this argument
|
47
51
|
# @param method_access [Boolean] If false, don't build method access on legacy {Query::Arguments} instances.
|
52
|
+
# @param directives [Hash{Class => Hash}]
|
48
53
|
# @param deprecation_reason [String]
|
49
|
-
|
54
|
+
# @param validates [Hash, nil] Options for building validators, if any should be applied
|
55
|
+
def initialize(arg_name = nil, type_expr = nil, desc = nil, required:, type: nil, name: nil, loads: nil, description: nil, ast_node: nil, default_value: NO_DEFAULT, as: nil, from_resolver: false, camelize: true, prepare: nil, method_access: true, owner:, validates: nil, directives: nil, deprecation_reason: nil, &definition_block)
|
50
56
|
arg_name ||= name
|
51
57
|
@name = -(camelize ? Member::BuildType.camelize(arg_name.to_s) : arg_name.to_s)
|
52
58
|
@type_expr = type_expr || type
|
@@ -63,6 +69,14 @@ module GraphQL
|
|
63
69
|
@method_access = method_access
|
64
70
|
self.deprecation_reason = deprecation_reason
|
65
71
|
|
72
|
+
if directives
|
73
|
+
directives.each do |dir_class, dir_options|
|
74
|
+
directive(dir_class, **dir_options)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
self.validates(validates)
|
79
|
+
|
66
80
|
if definition_block
|
67
81
|
if definition_block.arity == 1
|
68
82
|
instance_exec(self, &definition_block)
|
@@ -94,14 +108,16 @@ module GraphQL
|
|
94
108
|
# @return [String] Deprecation reason for this argument
|
95
109
|
def deprecation_reason(text = nil)
|
96
110
|
if text
|
97
|
-
|
98
|
-
@deprecation_reason = text
|
111
|
+
self.deprecation_reason = text
|
99
112
|
else
|
100
|
-
|
113
|
+
super()
|
101
114
|
end
|
102
115
|
end
|
103
116
|
|
104
|
-
|
117
|
+
def deprecation_reason=(new_reason)
|
118
|
+
validate_deprecated_or_optional(null: @null, deprecation_reason: new_reason)
|
119
|
+
super
|
120
|
+
end
|
105
121
|
|
106
122
|
def visible?(context)
|
107
123
|
true
|
@@ -157,8 +173,8 @@ module GraphQL
|
|
157
173
|
if NO_DEFAULT != @default_value
|
158
174
|
argument.default_value = @default_value
|
159
175
|
end
|
160
|
-
if
|
161
|
-
argument.deprecation_reason =
|
176
|
+
if self.deprecation_reason
|
177
|
+
argument.deprecation_reason = self.deprecation_reason
|
162
178
|
end
|
163
179
|
argument
|
164
180
|
end
|
@@ -199,6 +215,8 @@ module GraphQL
|
|
199
215
|
value = value.prepare
|
200
216
|
end
|
201
217
|
|
218
|
+
Schema::Validator.validate!(validators, obj, context, value)
|
219
|
+
|
202
220
|
if @prepare.nil?
|
203
221
|
value
|
204
222
|
elsif @prepare.is_a?(String) || @prepare.is_a?(Symbol)
|