graphql 1.13.0 → 1.13.4
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.
Potentially problematic release.
This version of graphql might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/lib/generators/graphql/core.rb +3 -1
- data/lib/generators/graphql/install_generator.rb +9 -2
- data/lib/graphql/analysis/ast/field_usage.rb +6 -2
- data/lib/graphql/base_type.rb +4 -2
- data/lib/graphql/boolean_type.rb +1 -1
- data/lib/graphql/directive/deprecated_directive.rb +1 -1
- data/lib/graphql/directive/include_directive.rb +1 -1
- data/lib/graphql/directive/skip_directive.rb +1 -1
- data/lib/graphql/execution/interpreter/runtime.rb +11 -7
- data/lib/graphql/execution/multiplex.rb +3 -0
- data/lib/graphql/float_type.rb +1 -1
- data/lib/graphql/id_type.rb +1 -1
- data/lib/graphql/int_type.rb +1 -1
- data/lib/graphql/language/block_string.rb +2 -2
- data/lib/graphql/language/document_from_schema_definition.rb +7 -3
- data/lib/graphql/language/nodes.rb +11 -2
- data/lib/graphql/pagination/active_record_relation_connection.rb +43 -6
- data/lib/graphql/pagination/relation_connection.rb +57 -27
- data/lib/graphql/query/context.rb +10 -0
- data/lib/graphql/relay/global_id_resolve.rb +1 -1
- data/lib/graphql/relay/page_info.rb +1 -1
- data/lib/graphql/schema/argument.rb +8 -10
- data/lib/graphql/schema/directive.rb +5 -1
- data/lib/graphql/schema/enum.rb +3 -1
- data/lib/graphql/schema/enum_value.rb +2 -0
- data/lib/graphql/schema/field.rb +139 -62
- data/lib/graphql/schema/field_extension.rb +89 -2
- data/lib/graphql/schema/input_object.rb +18 -1
- data/lib/graphql/schema/interface.rb +3 -1
- data/lib/graphql/schema/introspection_system.rb +1 -1
- data/lib/graphql/schema/list.rb +3 -1
- data/lib/graphql/schema/member/accepts_definition.rb +7 -2
- data/lib/graphql/schema/member/cached_graphql_definition.rb +29 -2
- data/lib/graphql/schema/non_null.rb +7 -1
- data/lib/graphql/schema/object.rb +3 -1
- data/lib/graphql/schema/relay_classic_mutation.rb +8 -0
- data/lib/graphql/schema/resolver.rb +19 -13
- data/lib/graphql/schema/scalar.rb +2 -0
- data/lib/graphql/schema/traversal.rb +1 -1
- data/lib/graphql/schema/union.rb +2 -0
- data/lib/graphql/schema/validator/required_validator.rb +29 -15
- data/lib/graphql/schema/validator.rb +4 -7
- data/lib/graphql/schema.rb +24 -8
- data/lib/graphql/static_validation/all_rules.rb +1 -0
- data/lib/graphql/static_validation/rules/fields_will_merge.rb +14 -7
- data/lib/graphql/static_validation/rules/query_root_exists.rb +17 -0
- data/lib/graphql/static_validation/rules/query_root_exists_error.rb +26 -0
- data/lib/graphql/static_validation/rules/required_arguments_are_present.rb +2 -0
- data/lib/graphql/static_validation/rules/variable_usages_are_allowed.rb +6 -0
- data/lib/graphql/string_type.rb +1 -1
- data/lib/graphql/subscriptions/action_cable_subscriptions.rb +2 -0
- data/lib/graphql/subscriptions/serialize.rb +22 -2
- data/lib/graphql/tracing/active_support_notifications_tracing.rb +6 -20
- data/lib/graphql/tracing/notifications_tracing.rb +59 -0
- data/lib/graphql/types/relay/connection_behaviors.rb +26 -9
- data/lib/graphql/types/relay/default_relay.rb +5 -1
- data/lib/graphql/types/relay/edge_behaviors.rb +13 -2
- data/lib/graphql/types/relay/node_field.rb +14 -3
- data/lib/graphql/types/relay/nodes_field.rb +13 -3
- data/lib/graphql/version.rb +1 -1
- data/lib/graphql.rb +1 -1
- metadata +5 -2
@@ -173,7 +173,7 @@ Some late-bound types couldn't be resolved:
|
|
173
173
|
end
|
174
174
|
when Class
|
175
175
|
if member.respond_to?(:graphql_definition)
|
176
|
-
graphql_member = member.graphql_definition
|
176
|
+
graphql_member = member.graphql_definition(silence_deprecation_warning: true)
|
177
177
|
visit(schema, graphql_member, context_description)
|
178
178
|
else
|
179
179
|
raise GraphQL::Schema::InvalidTypeError.new("Unexpected traversal member: #{member} (#{member.class.name})")
|
data/lib/graphql/schema/union.rb
CHANGED
@@ -14,7 +14,7 @@ module GraphQL
|
|
14
14
|
# argument :ingredient_id, ID, required: true
|
15
15
|
# argument :cups, Integer, required: false
|
16
16
|
# argument :tablespoons, Integer, required: false
|
17
|
-
# argument :teaspoons, Integer, required:
|
17
|
+
# argument :teaspoons, Integer, required: false
|
18
18
|
# validates required: { one_of: [:cups, :tablespoons, :teaspoons] }
|
19
19
|
# end
|
20
20
|
#
|
@@ -28,11 +28,23 @@ module GraphQL
|
|
28
28
|
# validates required: { one_of: [:node_id, [:object_type, :object_id]] }
|
29
29
|
# end
|
30
30
|
#
|
31
|
+
# @example require _some_ value for an argument, even if it's null
|
32
|
+
# field :update_settings, AccountSettings do
|
33
|
+
# # `required: :nullable` means this argument must be given, but may be `null`
|
34
|
+
# argument :age, Integer, required: :nullable
|
35
|
+
# end
|
36
|
+
#
|
31
37
|
class RequiredValidator < Validator
|
32
38
|
# @param one_of [Symbol, Array<Symbol>] An argument, or a list of arguments, that represents a valid set of inputs for this field
|
33
39
|
# @param message [String]
|
34
|
-
def initialize(one_of
|
35
|
-
@one_of = one_of
|
40
|
+
def initialize(one_of: nil, argument: nil, message: "%{validated} has the wrong arguments", **default_options)
|
41
|
+
@one_of = if one_of
|
42
|
+
one_of
|
43
|
+
elsif argument
|
44
|
+
[argument]
|
45
|
+
else
|
46
|
+
raise ArgumentError, "`one_of:` or `argument:` must be given in `validates required: {...}`"
|
47
|
+
end
|
36
48
|
@message = message
|
37
49
|
super(**default_options)
|
38
50
|
end
|
@@ -40,19 +52,21 @@ module GraphQL
|
|
40
52
|
def validate(_object, _context, value)
|
41
53
|
matched_conditions = 0
|
42
54
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
55
|
+
if !value.nil?
|
56
|
+
@one_of.each do |one_of_condition|
|
57
|
+
case one_of_condition
|
58
|
+
when Symbol
|
59
|
+
if value.key?(one_of_condition)
|
60
|
+
matched_conditions += 1
|
61
|
+
end
|
62
|
+
when Array
|
63
|
+
if one_of_condition.all? { |k| value.key?(k) }
|
64
|
+
matched_conditions += 1
|
65
|
+
break
|
66
|
+
end
|
67
|
+
else
|
68
|
+
raise ArgumentError, "Unknown one_of condition: #{one_of_condition.inspect}"
|
53
69
|
end
|
54
|
-
else
|
55
|
-
raise ArgumentError, "Unknown one_of condition: #{one_of_condition.inspect}"
|
56
70
|
end
|
57
71
|
end
|
58
72
|
|
@@ -48,16 +48,13 @@ module GraphQL
|
|
48
48
|
EMPTY_ARRAY
|
49
49
|
else
|
50
50
|
validates_hash = validates_hash.dup
|
51
|
-
allow_null = validates_hash.delete(:allow_null)
|
52
|
-
allow_blank = validates_hash.delete(:allow_blank)
|
53
51
|
|
54
|
-
# This could be {...}.compact on Ruby 2.4+
|
55
52
|
default_options = {}
|
56
|
-
if
|
57
|
-
default_options[:allow_null] = allow_null
|
53
|
+
if validates_hash[:allow_null]
|
54
|
+
default_options[:allow_null] = validates_hash.delete(:allow_null)
|
58
55
|
end
|
59
|
-
if
|
60
|
-
default_options[:allow_blank] = allow_blank
|
56
|
+
if validates_hash[:allow_blank]
|
57
|
+
default_options[:allow_blank] = validates_hash.delete(:allow_blank)
|
61
58
|
end
|
62
59
|
|
63
60
|
# allow_nil or allow_blank are the _only_ validations:
|
data/lib/graphql/schema.rb
CHANGED
@@ -845,7 +845,7 @@ module GraphQL
|
|
845
845
|
# - Cause the Schema instance to be created, if it hasn't been created yet
|
846
846
|
# - Delegate to that instance
|
847
847
|
# Eventually, the methods will be moved into this class, removing the need for the singleton.
|
848
|
-
def_delegators :
|
848
|
+
def_delegators :deprecated_graphql_definition,
|
849
849
|
# Execution
|
850
850
|
:execution_strategy_for_operation,
|
851
851
|
# Configuration
|
@@ -854,6 +854,10 @@ module GraphQL
|
|
854
854
|
:id_from_object=, :object_from_id=,
|
855
855
|
:remove_handler
|
856
856
|
|
857
|
+
def deprecated_graphql_definition
|
858
|
+
graphql_definition(silence_deprecation_warning: true)
|
859
|
+
end
|
860
|
+
|
857
861
|
# @return [GraphQL::Subscriptions]
|
858
862
|
attr_accessor :subscriptions
|
859
863
|
|
@@ -896,8 +900,15 @@ module GraphQL
|
|
896
900
|
@find_cache[path] ||= @finder.find(path)
|
897
901
|
end
|
898
902
|
|
899
|
-
def graphql_definition
|
900
|
-
@graphql_definition ||=
|
903
|
+
def graphql_definition(silence_deprecation_warning: false)
|
904
|
+
@graphql_definition ||= begin
|
905
|
+
unless silence_deprecation_warning
|
906
|
+
message = "Legacy `.graphql_definition` objects are deprecated and will be removed in GraphQL-Ruby 2.0. Use a class-based definition instead."
|
907
|
+
caller_message = "\n\nCalled on #{self.inspect} from:\n #{caller(1, 25).map { |l| " #{l}" }.join("\n")}"
|
908
|
+
GraphQL::Deprecation.warn(message + caller_message)
|
909
|
+
end
|
910
|
+
to_graphql(silence_deprecation_warning: silence_deprecation_warning)
|
911
|
+
end
|
901
912
|
end
|
902
913
|
|
903
914
|
def default_filter
|
@@ -929,19 +940,20 @@ module GraphQL
|
|
929
940
|
find_inherited_value(:plugins, EMPTY_ARRAY) + own_plugins
|
930
941
|
end
|
931
942
|
|
943
|
+
prepend Schema::Member::CachedGraphQLDefinition::DeprecatedToGraphQL
|
932
944
|
def to_graphql
|
933
945
|
schema_defn = self.new
|
934
946
|
schema_defn.raise_definition_error = true
|
935
|
-
schema_defn.query = query && query.graphql_definition
|
936
|
-
schema_defn.mutation = mutation && mutation.graphql_definition
|
937
|
-
schema_defn.subscription = subscription && subscription.graphql_definition
|
947
|
+
schema_defn.query = query && query.graphql_definition(silence_deprecation_warning: true)
|
948
|
+
schema_defn.mutation = mutation && mutation.graphql_definition(silence_deprecation_warning: true)
|
949
|
+
schema_defn.subscription = subscription && subscription.graphql_definition(silence_deprecation_warning: true)
|
938
950
|
schema_defn.validate_timeout = validate_timeout
|
939
951
|
schema_defn.validate_max_errors = validate_max_errors
|
940
952
|
schema_defn.max_complexity = max_complexity
|
941
953
|
schema_defn.error_bubbling = error_bubbling
|
942
954
|
schema_defn.max_depth = max_depth
|
943
955
|
schema_defn.default_max_page_size = default_max_page_size
|
944
|
-
schema_defn.orphan_types = orphan_types.map(
|
956
|
+
schema_defn.orphan_types = orphan_types.map { |t| t.graphql_definition(silence_deprecation_warning: true) }
|
945
957
|
schema_defn.disable_introspection_entry_points = disable_introspection_entry_points?
|
946
958
|
schema_defn.disable_schema_introspection_entry_point = disable_schema_introspection_entry_point?
|
947
959
|
schema_defn.disable_type_introspection_entry_point = disable_type_introspection_entry_point?
|
@@ -1235,7 +1247,11 @@ module GraphQL
|
|
1235
1247
|
when Module
|
1236
1248
|
type_or_name
|
1237
1249
|
else
|
1238
|
-
raise ArgumentError,
|
1250
|
+
raise ArgumentError, <<-ERR
|
1251
|
+
Invariant: unexpected field owner for #{field_name.inspect}: #{type_or_name.inspect} (#{type_or_name.class})
|
1252
|
+
|
1253
|
+
This is probably a bug in GraphQL-Ruby, please report this error on GitHub: https://github.com/rmosolgo/graphql-ruby/issues/new?template=bug_report.md
|
1254
|
+
ERR
|
1239
1255
|
end
|
1240
1256
|
|
1241
1257
|
if parent_type.kind.fields? && (field = parent_type.get_field(field_name, context))
|
@@ -33,6 +33,7 @@ module GraphQL
|
|
33
33
|
GraphQL::StaticValidation::VariablesAreUsedAndDefined,
|
34
34
|
GraphQL::StaticValidation::VariableUsagesAreAllowed,
|
35
35
|
GraphQL::StaticValidation::MutationRootExists,
|
36
|
+
GraphQL::StaticValidation::QueryRootExists,
|
36
37
|
GraphQL::StaticValidation::SubscriptionRootExists,
|
37
38
|
GraphQL::StaticValidation::InputObjectNamesAreUnique,
|
38
39
|
]
|
@@ -50,15 +50,15 @@ module GraphQL
|
|
50
50
|
@arg_conflicts = nil
|
51
51
|
|
52
52
|
yield
|
53
|
-
|
54
|
-
field_conflicts.each_value { |error| add_error(error) }
|
55
|
-
arg_conflicts.each_value { |error| add_error(error) }
|
53
|
+
# don't initialize these if they weren't initialized in the block:
|
54
|
+
@field_conflicts && @field_conflicts.each_value { |error| add_error(error) }
|
55
|
+
@arg_conflicts && @arg_conflicts.each_value { |error| add_error(error) }
|
56
56
|
end
|
57
57
|
|
58
58
|
def conflicts_within_selection_set(node, parent_type)
|
59
59
|
return if parent_type.nil?
|
60
60
|
|
61
|
-
fields, fragment_spreads = fields_and_fragments_from_selection(node, owner_type: parent_type, parents:
|
61
|
+
fields, fragment_spreads = fields_and_fragments_from_selection(node, owner_type: parent_type, parents: nil)
|
62
62
|
|
63
63
|
# (A) Find find all conflicts "within" the fields of this selection set.
|
64
64
|
find_conflicts_within(fields)
|
@@ -198,10 +198,14 @@ module GraphQL
|
|
198
198
|
response_keys.each do |key, fields|
|
199
199
|
next if fields.size < 2
|
200
200
|
# find conflicts within nodes
|
201
|
-
|
202
|
-
|
201
|
+
i = 0
|
202
|
+
while i < fields.size
|
203
|
+
j = i + 1
|
204
|
+
while j < fields.size
|
203
205
|
find_conflict(key, fields[i], fields[j])
|
206
|
+
j += 1
|
204
207
|
end
|
208
|
+
i += 1
|
205
209
|
end
|
206
210
|
end
|
207
211
|
end
|
@@ -243,7 +247,9 @@ module GraphQL
|
|
243
247
|
end
|
244
248
|
|
245
249
|
def find_conflicts_between_sub_selection_sets(field1, field2, mutually_exclusive:)
|
246
|
-
return if field1.definition.nil? ||
|
250
|
+
return if field1.definition.nil? ||
|
251
|
+
field2.definition.nil? ||
|
252
|
+
(field1.node.selections.empty? && field2.node.selections.empty?)
|
247
253
|
|
248
254
|
return_type1 = field1.definition.type.unwrap
|
249
255
|
return_type2 = field2.definition.type.unwrap
|
@@ -323,6 +329,7 @@ module GraphQL
|
|
323
329
|
if node.selections.empty?
|
324
330
|
NO_SELECTIONS
|
325
331
|
else
|
332
|
+
parents ||= []
|
326
333
|
fields, fragment_spreads = find_fields_and_fragments(node.selections, owner_type: owner_type, parents: parents, fields: [], fragment_spreads: [])
|
327
334
|
response_keys = fields.group_by { |f| f.node.alias || f.node.name }
|
328
335
|
[response_keys, fragment_spreads]
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module GraphQL
|
3
|
+
module StaticValidation
|
4
|
+
module QueryRootExists
|
5
|
+
def on_operation_definition(node, _parent)
|
6
|
+
if (node.operation_type == 'query' || node.operation_type.nil?) && context.warden.root_type_for_operation("query").nil?
|
7
|
+
add_error(GraphQL::StaticValidation::QueryRootExistsError.new(
|
8
|
+
'Schema is not configured for queries',
|
9
|
+
nodes: node
|
10
|
+
))
|
11
|
+
else
|
12
|
+
super
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module GraphQL
|
3
|
+
module StaticValidation
|
4
|
+
class QueryRootExistsError < StaticValidation::Error
|
5
|
+
|
6
|
+
def initialize(message, path: nil, nodes: [])
|
7
|
+
super(message, path: path, nodes: nodes)
|
8
|
+
end
|
9
|
+
|
10
|
+
# A hash representation of this Message
|
11
|
+
def to_h
|
12
|
+
extensions = {
|
13
|
+
"code" => code,
|
14
|
+
}
|
15
|
+
|
16
|
+
super.merge({
|
17
|
+
"extensions" => extensions
|
18
|
+
})
|
19
|
+
end
|
20
|
+
|
21
|
+
def code
|
22
|
+
"missingQueryConfiguration"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -16,6 +16,8 @@ module GraphQL
|
|
16
16
|
private
|
17
17
|
|
18
18
|
def assert_required_args(ast_node, defn)
|
19
|
+
args = defn.arguments(context.query.context)
|
20
|
+
return if args.empty?
|
19
21
|
present_argument_names = ast_node.arguments.map(&:name)
|
20
22
|
required_argument_names = context.warden.arguments(defn)
|
21
23
|
.select { |a| a.type.kind.non_null? && !a.default_value? && context.warden.get_argument(defn, a.name) }
|
@@ -68,6 +68,12 @@ module GraphQL
|
|
68
68
|
arg_defn = context.warden.get_argument(argument_owner, arg_node.name)
|
69
69
|
arg_defn_type = arg_defn.type
|
70
70
|
|
71
|
+
# If the argument is non-null, but it was given a default value,
|
72
|
+
# then treat it as nullable in practice, see https://github.com/rmosolgo/graphql-ruby/issues/3793
|
73
|
+
if arg_defn_type.non_null? && arg_defn.default_value?
|
74
|
+
arg_defn_type = arg_defn_type.of_type
|
75
|
+
end
|
76
|
+
|
71
77
|
var_inner_type = var_type.unwrap
|
72
78
|
arg_inner_type = arg_defn_type.unwrap
|
73
79
|
|
data/lib/graphql/string_type.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
GraphQL::STRING_TYPE = GraphQL::Types::String.graphql_definition
|
2
|
+
GraphQL::STRING_TYPE = GraphQL::Types::String.graphql_definition(silence_deprecation_warning: true)
|
@@ -216,6 +216,8 @@ module GraphQL
|
|
216
216
|
# The channel was closed, forget about it.
|
217
217
|
def delete_subscription(subscription_id)
|
218
218
|
query = @subscriptions.delete(subscription_id)
|
219
|
+
# In case this came from the server, tell the client to unsubscribe:
|
220
|
+
@action_cable.server.broadcast(stream_subscription_name(subscription_id), { more: false })
|
219
221
|
# This can be `nil` when `.trigger` happens inside an unsubscribed ActionCable channel,
|
220
222
|
# see https://github.com/rmosolgo/graphql-ruby/issues/2478
|
221
223
|
if query
|
@@ -71,9 +71,17 @@ module GraphQL
|
|
71
71
|
when SYMBOL_KEY
|
72
72
|
value[SYMBOL_KEY].to_sym
|
73
73
|
when TIMESTAMP_KEY
|
74
|
-
timestamp_class_name,
|
74
|
+
timestamp_class_name, *timestamp_args = value[TIMESTAMP_KEY]
|
75
75
|
timestamp_class = Object.const_get(timestamp_class_name)
|
76
|
-
|
76
|
+
if defined?(ActiveSupport::TimeWithZone) && timestamp_class <= ActiveSupport::TimeWithZone
|
77
|
+
zone_name, timestamp_s = timestamp_args
|
78
|
+
zone = ActiveSupport::TimeZone[zone_name]
|
79
|
+
raise "Zone #{zone_name} not found, unable to deserialize" unless zone
|
80
|
+
zone.strptime(timestamp_s, TIMESTAMP_FORMAT)
|
81
|
+
else
|
82
|
+
timestamp_s = timestamp_args.first
|
83
|
+
timestamp_class.strptime(timestamp_s, TIMESTAMP_FORMAT)
|
84
|
+
end
|
77
85
|
when OPEN_STRUCT_KEY
|
78
86
|
ostruct_values = load_value(value[OPEN_STRUCT_KEY])
|
79
87
|
OpenStruct.new(ostruct_values)
|
@@ -123,6 +131,18 @@ module GraphQL
|
|
123
131
|
{ SYMBOL_KEY => obj.to_s }
|
124
132
|
elsif obj.respond_to?(:to_gid_param)
|
125
133
|
{GLOBALID_KEY => obj.to_gid_param}
|
134
|
+
elsif defined?(ActiveSupport::TimeWithZone) && obj.is_a?(ActiveSupport::TimeWithZone) && obj.class.name != Time.name
|
135
|
+
# This handles a case where Rails prior to 7 would
|
136
|
+
# make the class ActiveSupport::TimeWithZone return "Time" for
|
137
|
+
# its name. In Rails 7, it will now return "ActiveSupport::TimeWithZone",
|
138
|
+
# which happens to be incompatible with expectations we have
|
139
|
+
# with what a Time class supports ( notably, strptime in `load_value` ).
|
140
|
+
#
|
141
|
+
# This now passes along the name of the zone, such that a future deserialization
|
142
|
+
# of this string will use the correct time zone from the ActiveSupport TimeZone
|
143
|
+
# list to produce the time.
|
144
|
+
#
|
145
|
+
{ TIMESTAMP_KEY => [obj.class.name, obj.time_zone.name, obj.strftime(TIMESTAMP_FORMAT)] }
|
126
146
|
elsif obj.is_a?(Date) || obj.is_a?(Time)
|
127
147
|
# DateTime extends Date; for TimeWithZone, call `.utc` first.
|
128
148
|
{ TIMESTAMP_KEY => [obj.class.name, obj.strftime(TIMESTAMP_FORMAT)] }
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'graphql/tracing/notifications_tracing'
|
4
|
+
|
3
5
|
module GraphQL
|
4
6
|
module Tracing
|
5
7
|
# This implementation forwards events to ActiveSupport::Notifications
|
@@ -8,27 +10,11 @@ module GraphQL
|
|
8
10
|
# @see KEYS for event names
|
9
11
|
module ActiveSupportNotificationsTracing
|
10
12
|
# A cache of frequently-used keys to avoid needless string allocations
|
11
|
-
KEYS =
|
12
|
-
|
13
|
-
"parse" => "parse.graphql",
|
14
|
-
"validate" => "validate.graphql",
|
15
|
-
"analyze_multiplex" => "analyze_multiplex.graphql",
|
16
|
-
"analyze_query" => "analyze_query.graphql",
|
17
|
-
"execute_query" => "execute_query.graphql",
|
18
|
-
"execute_query_lazy" => "execute_query_lazy.graphql",
|
19
|
-
"execute_field" => "execute_field.graphql",
|
20
|
-
"execute_field_lazy" => "execute_field_lazy.graphql",
|
21
|
-
"authorized" => "authorized.graphql",
|
22
|
-
"authorized_lazy" => "authorized_lazy.graphql",
|
23
|
-
"resolve_type" => "resolve_type.graphql",
|
24
|
-
"resolve_type_lazy" => "resolve_type.graphql",
|
25
|
-
}
|
13
|
+
KEYS = NotificationsTracing::KEYS
|
14
|
+
NOTIFICATIONS_ENGINE = NotificationsTracing.new(ActiveSupport::Notifications) if defined?(ActiveSupport)
|
26
15
|
|
27
|
-
def self.trace(key, metadata)
|
28
|
-
|
29
|
-
ActiveSupport::Notifications.instrument(prefixed_key, metadata) do
|
30
|
-
yield
|
31
|
-
end
|
16
|
+
def self.trace(key, metadata, &blk)
|
17
|
+
NOTIFICATIONS_ENGINE.trace(key, metadata, &blk)
|
32
18
|
end
|
33
19
|
end
|
34
20
|
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GraphQL
|
4
|
+
module Tracing
|
5
|
+
# This implementation forwards events to a notification handler (i.e.
|
6
|
+
# ActiveSupport::Notifications or Dry::Monitor::Notifications)
|
7
|
+
# with a `graphql` suffix.
|
8
|
+
#
|
9
|
+
# @see KEYS for event names
|
10
|
+
class NotificationsTracing
|
11
|
+
# A cache of frequently-used keys to avoid needless string allocations
|
12
|
+
KEYS = {
|
13
|
+
"lex" => "lex.graphql",
|
14
|
+
"parse" => "parse.graphql",
|
15
|
+
"validate" => "validate.graphql",
|
16
|
+
"analyze_multiplex" => "analyze_multiplex.graphql",
|
17
|
+
"analyze_query" => "analyze_query.graphql",
|
18
|
+
"execute_query" => "execute_query.graphql",
|
19
|
+
"execute_query_lazy" => "execute_query_lazy.graphql",
|
20
|
+
"execute_field" => "execute_field.graphql",
|
21
|
+
"execute_field_lazy" => "execute_field_lazy.graphql",
|
22
|
+
"authorized" => "authorized.graphql",
|
23
|
+
"authorized_lazy" => "authorized_lazy.graphql",
|
24
|
+
"resolve_type" => "resolve_type.graphql",
|
25
|
+
"resolve_type_lazy" => "resolve_type.graphql",
|
26
|
+
}
|
27
|
+
|
28
|
+
MAX_KEYS_SIZE = 100
|
29
|
+
|
30
|
+
# Initialize a new NotificationsTracing instance
|
31
|
+
#
|
32
|
+
# @param [Object] notifications_engine The notifications engine to use
|
33
|
+
def initialize(notifications_engine)
|
34
|
+
@notifications_engine = notifications_engine
|
35
|
+
end
|
36
|
+
|
37
|
+
# Sends a GraphQL tracing event to the notification handler
|
38
|
+
#
|
39
|
+
# @example
|
40
|
+
# . notifications_engine = Dry::Monitor::Notifications.new(:graphql)
|
41
|
+
# . tracer = GraphQL::Tracing::NotificationsTracing.new(notifications_engine)
|
42
|
+
# . tracer.trace("lex") { ... }
|
43
|
+
#
|
44
|
+
# @param [string] key The key for the event
|
45
|
+
# @param [Hash] metadata The metadata for the event
|
46
|
+
# @yield The block to execute for the event
|
47
|
+
def trace(key, metadata, &blk)
|
48
|
+
prefixed_key = KEYS[key] || "#{key}.graphql"
|
49
|
+
|
50
|
+
# Cache the new keys while making sure not to induce a memory leak
|
51
|
+
if KEYS.size < MAX_KEYS_SIZE
|
52
|
+
KEYS[key] ||= prefixed_key
|
53
|
+
end
|
54
|
+
|
55
|
+
@notifications_engine.instrument(prefixed_key, metadata, &blk)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -35,7 +35,8 @@ module GraphQL
|
|
35
35
|
# It's called when you subclass this base connection, trying to use the
|
36
36
|
# class name to set defaults. You can call it again in the class definition
|
37
37
|
# to override the default (or provide a value, if the default lookup failed).
|
38
|
-
|
38
|
+
# @param field_options [Hash] Any extra keyword arguments to pass to the `field :edges, ...` and `field :nodes, ...` configurations
|
39
|
+
def edge_type(edge_type_class, edge_class: GraphQL::Relay::Edge, node_type: edge_type_class.node_type, nodes_field: self.has_nodes_field, node_nullable: self.node_nullable, edges_nullable: self.edges_nullable, edge_nullable: self.edge_nullable, field_options: nil)
|
39
40
|
# Set this connection's graphql name
|
40
41
|
node_type_name = node_type.graphql_name
|
41
42
|
|
@@ -43,13 +44,22 @@ module GraphQL
|
|
43
44
|
@edge_type = edge_type_class
|
44
45
|
@edge_class = edge_class
|
45
46
|
|
46
|
-
|
47
|
+
base_field_options = {
|
48
|
+
name: :edges,
|
49
|
+
type: [edge_type_class, null: edge_nullable],
|
47
50
|
null: edges_nullable,
|
48
51
|
description: "A list of edges.",
|
49
52
|
legacy_edge_class: edge_class, # This is used by the old runtime only, for EdgesInstrumentation
|
50
|
-
connection: false
|
53
|
+
connection: false,
|
54
|
+
}
|
51
55
|
|
52
|
-
|
56
|
+
if field_options
|
57
|
+
base_field_options.merge!(field_options)
|
58
|
+
end
|
59
|
+
|
60
|
+
field(**base_field_options)
|
61
|
+
|
62
|
+
define_nodes_field(node_nullable, field_options: field_options) if nodes_field
|
53
63
|
|
54
64
|
description("The connection type for #{node_type_name}.")
|
55
65
|
end
|
@@ -60,8 +70,8 @@ module GraphQL
|
|
60
70
|
end
|
61
71
|
|
62
72
|
# Add the shortcut `nodes` field to this connection and its subclasses
|
63
|
-
def nodes_field(node_nullable: self.node_nullable)
|
64
|
-
define_nodes_field(node_nullable)
|
73
|
+
def nodes_field(node_nullable: self.node_nullable, field_options: nil)
|
74
|
+
define_nodes_field(node_nullable, field_options: field_options)
|
65
75
|
end
|
66
76
|
|
67
77
|
def authorized?(obj, ctx)
|
@@ -118,11 +128,18 @@ module GraphQL
|
|
118
128
|
|
119
129
|
private
|
120
130
|
|
121
|
-
def define_nodes_field(nullable)
|
122
|
-
|
131
|
+
def define_nodes_field(nullable, field_options: nil)
|
132
|
+
base_field_options = {
|
133
|
+
name: :nodes,
|
134
|
+
type: [@node_type, null: nullable],
|
123
135
|
null: nullable,
|
124
136
|
description: "A list of nodes.",
|
125
|
-
connection: false
|
137
|
+
connection: false,
|
138
|
+
}
|
139
|
+
if field_options
|
140
|
+
base_field_options.merge!(field_options)
|
141
|
+
end
|
142
|
+
field(**base_field_options)
|
126
143
|
end
|
127
144
|
end
|
128
145
|
|
@@ -17,7 +17,11 @@ module GraphQL
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def to_graphql
|
20
|
-
type_defn =
|
20
|
+
type_defn = if method(:to_graphql).super_method.arity
|
21
|
+
super(silence_deprecation_warning: true)
|
22
|
+
else
|
23
|
+
super
|
24
|
+
end
|
21
25
|
type_defn.default_relay = default_relay?
|
22
26
|
type_defn
|
23
27
|
end
|
@@ -16,11 +16,22 @@ module GraphQL
|
|
16
16
|
#
|
17
17
|
# @param node_type [Class] A `Schema::Object` subclass
|
18
18
|
# @param null [Boolean]
|
19
|
-
|
19
|
+
# @param field_options [Hash] Any extra arguments to pass to the `field :node` configuration
|
20
|
+
def node_type(node_type = nil, null: self.node_nullable, field_options: nil)
|
20
21
|
if node_type
|
21
22
|
@node_type = node_type
|
22
23
|
# Add a default `node` field
|
23
|
-
|
24
|
+
base_field_options = {
|
25
|
+
name: :node,
|
26
|
+
type: node_type,
|
27
|
+
null: null,
|
28
|
+
description: "The item at the end of the edge.",
|
29
|
+
connection: false,
|
30
|
+
}
|
31
|
+
if field_options
|
32
|
+
base_field_options.merge!(field_options)
|
33
|
+
end
|
34
|
+
field(**base_field_options)
|
24
35
|
end
|
25
36
|
@node_type
|
26
37
|
end
|
@@ -2,8 +2,7 @@
|
|
2
2
|
module GraphQL
|
3
3
|
module Types
|
4
4
|
module Relay
|
5
|
-
#
|
6
|
-
# or use it for inspiration for your own field definition.
|
5
|
+
# Don't use this field directly, instead, use one of these approaches:
|
7
6
|
#
|
8
7
|
# @example Adding this field directly
|
9
8
|
# include GraphQL::Types::Relay::HasNodeField
|
@@ -19,7 +18,19 @@ module GraphQL
|
|
19
18
|
# context.schema.object_from_id(id, context)
|
20
19
|
# end
|
21
20
|
#
|
22
|
-
|
21
|
+
def self.const_missing(const_name)
|
22
|
+
if const_name == :NodeField
|
23
|
+
message = "NodeField is deprecated, use `include GraphQL::Types::Relay::HasNodeField` instead."
|
24
|
+
message += "\n(referenced from #{caller(1, 1).first})"
|
25
|
+
GraphQL::Deprecation.warn(message)
|
26
|
+
|
27
|
+
DeprecatedNodeField
|
28
|
+
else
|
29
|
+
super
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
DeprecatedNodeField = GraphQL::Schema::Field.new(owner: nil, **HasNodeField.field_options, &HasNodeField.field_block)
|
23
34
|
end
|
24
35
|
end
|
25
36
|
end
|
@@ -2,8 +2,7 @@
|
|
2
2
|
module GraphQL
|
3
3
|
module Types
|
4
4
|
module Relay
|
5
|
-
#
|
6
|
-
# or use it for inspiration for your own field definition.
|
5
|
+
# Don't use this directly, instead, use one of these:
|
7
6
|
#
|
8
7
|
# @example Adding this field directly
|
9
8
|
# include GraphQL::Types::Relay::HasNodesField
|
@@ -21,7 +20,18 @@ module GraphQL
|
|
21
20
|
# end
|
22
21
|
# end
|
23
22
|
#
|
24
|
-
|
23
|
+
def self.const_missing(const_name)
|
24
|
+
if const_name == :NodesField
|
25
|
+
message = "NodesField is deprecated, use `include GraphQL::Types::Relay::HasNodesField` instead."
|
26
|
+
message += "\n(referenced from #{caller(1, 1).first})"
|
27
|
+
GraphQL::Deprecation.warn(message)
|
28
|
+
|
29
|
+
DeprecatedNodesField
|
30
|
+
else
|
31
|
+
super
|
32
|
+
end
|
33
|
+
end
|
34
|
+
DeprecatedNodesField = GraphQL::Schema::Field.new(owner: nil, **HasNodesField.field_options, &HasNodesField.field_block)
|
25
35
|
end
|
26
36
|
end
|
27
37
|
end
|
data/lib/graphql/version.rb
CHANGED