graphql 1.9.17 → 1.11.7
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/core.rb +18 -2
- data/lib/generators/graphql/install_generator.rb +27 -0
- data/lib/generators/graphql/object_generator.rb +52 -8
- data/lib/generators/graphql/templates/base_argument.erb +2 -0
- data/lib/generators/graphql/templates/base_enum.erb +2 -0
- data/lib/generators/graphql/templates/base_field.erb +2 -0
- data/lib/generators/graphql/templates/base_input_object.erb +2 -0
- data/lib/generators/graphql/templates/base_interface.erb +2 -0
- data/lib/generators/graphql/templates/base_mutation.erb +2 -0
- data/lib/generators/graphql/templates/base_object.erb +2 -0
- data/lib/generators/graphql/templates/base_scalar.erb +2 -0
- data/lib/generators/graphql/templates/base_union.erb +2 -0
- data/lib/generators/graphql/templates/enum.erb +2 -0
- data/lib/generators/graphql/templates/graphql_controller.erb +14 -10
- data/lib/generators/graphql/templates/interface.erb +2 -0
- data/lib/generators/graphql/templates/loader.erb +2 -0
- data/lib/generators/graphql/templates/mutation.erb +2 -0
- data/lib/generators/graphql/templates/mutation_type.erb +2 -0
- data/lib/generators/graphql/templates/object.erb +2 -0
- data/lib/generators/graphql/templates/query_type.erb +2 -0
- data/lib/generators/graphql/templates/scalar.erb +2 -0
- data/lib/generators/graphql/templates/schema.erb +10 -0
- data/lib/generators/graphql/templates/union.erb +3 -1
- data/lib/graphql/analysis/ast/field_usage.rb +1 -1
- data/lib/graphql/analysis/ast/query_complexity.rb +178 -67
- data/lib/graphql/analysis/ast/visitor.rb +3 -3
- data/lib/graphql/analysis/ast.rb +12 -11
- data/lib/graphql/argument.rb +10 -38
- data/lib/graphql/backtrace/table.rb +10 -2
- data/lib/graphql/backtrace/tracer.rb +2 -1
- data/lib/graphql/base_type.rb +4 -0
- data/lib/graphql/compatibility/execution_specification/specification_schema.rb +2 -2
- data/lib/graphql/compatibility/query_parser_specification/parse_error_specification.rb +5 -9
- data/lib/graphql/define/assign_enum_value.rb +1 -1
- data/lib/graphql/define/assign_global_id_field.rb +2 -2
- data/lib/graphql/define/assign_object_field.rb +3 -3
- data/lib/graphql/define/defined_object_proxy.rb +3 -0
- data/lib/graphql/define/instance_definable.rb +18 -108
- data/lib/graphql/directive/deprecated_directive.rb +1 -12
- data/lib/graphql/directive.rb +8 -1
- data/lib/graphql/enum_type.rb +5 -71
- data/lib/graphql/execution/directive_checks.rb +2 -2
- data/lib/graphql/execution/errors.rb +2 -3
- data/lib/graphql/execution/execute.rb +1 -1
- data/lib/graphql/execution/instrumentation.rb +1 -1
- data/lib/graphql/execution/interpreter/argument_value.rb +28 -0
- data/lib/graphql/execution/interpreter/arguments.rb +51 -0
- data/lib/graphql/execution/interpreter/arguments_cache.rb +79 -0
- data/lib/graphql/execution/interpreter/handles_raw_value.rb +25 -0
- data/lib/graphql/execution/interpreter/runtime.rb +227 -254
- data/lib/graphql/execution/interpreter.rb +34 -11
- data/lib/graphql/execution/lazy/lazy_method_map.rb +4 -0
- data/lib/graphql/execution/lookahead.rb +39 -114
- data/lib/graphql/execution/multiplex.rb +14 -5
- data/lib/graphql/field.rb +14 -118
- data/lib/graphql/filter.rb +1 -1
- data/lib/graphql/function.rb +1 -30
- data/lib/graphql/input_object_type.rb +6 -24
- data/lib/graphql/integer_decoding_error.rb +17 -0
- data/lib/graphql/interface_type.rb +7 -23
- data/lib/graphql/internal_representation/scope.rb +2 -2
- data/lib/graphql/internal_representation/visit.rb +2 -2
- data/lib/graphql/introspection/base_object.rb +2 -5
- data/lib/graphql/introspection/directive_type.rb +1 -1
- data/lib/graphql/introspection/entry_points.rb +7 -7
- data/lib/graphql/introspection/field_type.rb +7 -3
- data/lib/graphql/introspection/input_value_type.rb +33 -9
- data/lib/graphql/introspection/introspection_query.rb +6 -92
- data/lib/graphql/introspection/schema_type.rb +4 -9
- data/lib/graphql/introspection/type_type.rb +11 -7
- data/lib/graphql/introspection.rb +96 -0
- data/lib/graphql/invalid_null_error.rb +18 -0
- data/lib/graphql/language/block_string.rb +24 -5
- data/lib/graphql/language/definition_slice.rb +21 -10
- data/lib/graphql/language/document_from_schema_definition.rb +89 -64
- data/lib/graphql/language/lexer.rb +7 -3
- data/lib/graphql/language/lexer.rl +7 -3
- data/lib/graphql/language/nodes.rb +52 -91
- data/lib/graphql/language/parser.rb +719 -717
- data/lib/graphql/language/parser.y +104 -98
- data/lib/graphql/language/printer.rb +1 -1
- data/lib/graphql/language/sanitized_printer.rb +222 -0
- data/lib/graphql/language/visitor.rb +2 -2
- data/lib/graphql/language.rb +2 -1
- data/lib/graphql/name_validator.rb +6 -7
- data/lib/graphql/non_null_type.rb +0 -10
- data/lib/graphql/object_type.rb +45 -56
- data/lib/graphql/pagination/active_record_relation_connection.rb +41 -0
- data/lib/graphql/pagination/array_connection.rb +77 -0
- data/lib/graphql/pagination/connection.rb +208 -0
- data/lib/graphql/pagination/connections.rb +145 -0
- data/lib/graphql/pagination/mongoid_relation_connection.rb +25 -0
- data/lib/graphql/pagination/relation_connection.rb +185 -0
- data/lib/graphql/pagination/sequel_dataset_connection.rb +28 -0
- data/lib/graphql/pagination.rb +6 -0
- data/lib/graphql/query/arguments.rb +4 -2
- data/lib/graphql/query/context.rb +36 -9
- data/lib/graphql/query/fingerprint.rb +26 -0
- data/lib/graphql/query/input_validation_result.rb +23 -6
- data/lib/graphql/query/literal_input.rb +30 -10
- data/lib/graphql/query/null_context.rb +5 -1
- data/lib/graphql/query/validation_pipeline.rb +4 -1
- data/lib/graphql/query/variable_validation_error.rb +1 -1
- data/lib/graphql/query/variables.rb +16 -7
- data/lib/graphql/query.rb +64 -15
- data/lib/graphql/rake_task/validate.rb +3 -0
- data/lib/graphql/rake_task.rb +9 -9
- data/lib/graphql/relay/array_connection.rb +10 -12
- data/lib/graphql/relay/base_connection.rb +23 -13
- data/lib/graphql/relay/connection_type.rb +2 -1
- data/lib/graphql/relay/edge_type.rb +1 -0
- data/lib/graphql/relay/edges_instrumentation.rb +1 -1
- data/lib/graphql/relay/mutation.rb +1 -86
- data/lib/graphql/relay/node.rb +2 -2
- data/lib/graphql/relay/range_add.rb +14 -5
- data/lib/graphql/relay/relation_connection.rb +8 -10
- data/lib/graphql/scalar_type.rb +15 -59
- data/lib/graphql/schema/argument.rb +113 -11
- data/lib/graphql/schema/base_64_encoder.rb +2 -0
- data/lib/graphql/schema/build_from_definition/resolve_map/default_resolve.rb +1 -1
- data/lib/graphql/schema/build_from_definition/resolve_map.rb +13 -5
- data/lib/graphql/schema/build_from_definition.rb +212 -190
- data/lib/graphql/schema/built_in_types.rb +5 -5
- data/lib/graphql/schema/default_type_error.rb +2 -0
- data/lib/graphql/schema/directive/deprecated.rb +18 -0
- data/lib/graphql/schema/directive/include.rb +1 -1
- data/lib/graphql/schema/directive/skip.rb +1 -1
- data/lib/graphql/schema/directive.rb +34 -3
- data/lib/graphql/schema/enum.rb +52 -4
- data/lib/graphql/schema/enum_value.rb +6 -1
- data/lib/graphql/schema/field/connection_extension.rb +44 -20
- data/lib/graphql/schema/field/scope_extension.rb +1 -1
- data/lib/graphql/schema/field.rb +200 -129
- data/lib/graphql/schema/find_inherited_value.rb +13 -0
- data/lib/graphql/schema/finder.rb +13 -11
- data/lib/graphql/schema/input_object.rb +131 -22
- data/lib/graphql/schema/interface.rb +26 -8
- data/lib/graphql/schema/introspection_system.rb +108 -37
- data/lib/graphql/schema/late_bound_type.rb +3 -2
- data/lib/graphql/schema/list.rb +47 -0
- data/lib/graphql/schema/loader.rb +134 -96
- data/lib/graphql/schema/member/base_dsl_methods.rb +29 -12
- data/lib/graphql/schema/member/build_type.rb +19 -5
- data/lib/graphql/schema/member/cached_graphql_definition.rb +5 -0
- data/lib/graphql/schema/member/has_arguments.rb +105 -5
- data/lib/graphql/schema/member/has_ast_node.rb +20 -0
- data/lib/graphql/schema/member/has_fields.rb +20 -10
- data/lib/graphql/schema/member/has_unresolved_type_error.rb +15 -0
- data/lib/graphql/schema/member/type_system_helpers.rb +2 -2
- data/lib/graphql/schema/member/validates_input.rb +33 -0
- data/lib/graphql/schema/member.rb +6 -0
- data/lib/graphql/schema/mutation.rb +5 -1
- data/lib/graphql/schema/non_null.rb +30 -0
- data/lib/graphql/schema/object.rb +65 -12
- data/lib/graphql/schema/possible_types.rb +9 -4
- data/lib/graphql/schema/printer.rb +0 -15
- data/lib/graphql/schema/relay_classic_mutation.rb +5 -3
- data/lib/graphql/schema/resolver/has_payload_type.rb +5 -2
- data/lib/graphql/schema/resolver.rb +26 -18
- data/lib/graphql/schema/scalar.rb +27 -3
- data/lib/graphql/schema/subscription.rb +8 -18
- data/lib/graphql/schema/timeout.rb +29 -15
- data/lib/graphql/schema/traversal.rb +1 -1
- data/lib/graphql/schema/type_expression.rb +21 -13
- data/lib/graphql/schema/type_membership.rb +2 -2
- data/lib/graphql/schema/union.rb +37 -3
- data/lib/graphql/schema/unique_within_type.rb +1 -2
- data/lib/graphql/schema/validation.rb +10 -2
- data/lib/graphql/schema/warden.rb +115 -29
- data/lib/graphql/schema.rb +903 -195
- data/lib/graphql/static_validation/all_rules.rb +1 -0
- data/lib/graphql/static_validation/base_visitor.rb +10 -6
- data/lib/graphql/static_validation/literal_validator.rb +52 -27
- data/lib/graphql/static_validation/rules/argument_literals_are_compatible.rb +43 -83
- data/lib/graphql/static_validation/rules/argument_literals_are_compatible_error.rb +17 -5
- data/lib/graphql/static_validation/rules/arguments_are_defined.rb +33 -25
- data/lib/graphql/static_validation/rules/directives_are_in_valid_locations.rb +1 -1
- data/lib/graphql/static_validation/rules/fields_are_defined_on_type.rb +4 -4
- data/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb +5 -5
- data/lib/graphql/static_validation/rules/fields_will_merge.rb +29 -21
- data/lib/graphql/static_validation/rules/fragment_spreads_are_possible.rb +3 -3
- 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/rules/required_arguments_are_present.rb +2 -2
- data/lib/graphql/static_validation/rules/required_input_object_attributes_are_present.rb +4 -5
- data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed.rb +12 -13
- data/lib/graphql/static_validation/rules/variable_usages_are_allowed.rb +5 -6
- data/lib/graphql/static_validation/rules/variables_are_input_types.rb +1 -1
- data/lib/graphql/static_validation/rules/variables_are_used_and_defined.rb +5 -3
- data/lib/graphql/static_validation/type_stack.rb +2 -2
- data/lib/graphql/static_validation/validation_context.rb +1 -1
- data/lib/graphql/static_validation/validation_timeout_error.rb +25 -0
- data/lib/graphql/static_validation/validator.rb +30 -8
- data/lib/graphql/static_validation.rb +1 -0
- data/lib/graphql/subscriptions/action_cable_subscriptions.rb +89 -19
- data/lib/graphql/subscriptions/broadcast_analyzer.rb +84 -0
- data/lib/graphql/subscriptions/default_subscription_resolve_extension.rb +21 -0
- data/lib/graphql/subscriptions/event.rb +23 -5
- data/lib/graphql/subscriptions/instrumentation.rb +10 -5
- data/lib/graphql/subscriptions/serialize.rb +22 -4
- data/lib/graphql/subscriptions/subscription_root.rb +15 -5
- data/lib/graphql/subscriptions.rb +108 -35
- data/lib/graphql/tracing/active_support_notifications_tracing.rb +14 -10
- data/lib/graphql/tracing/appoptics_tracing.rb +171 -0
- data/lib/graphql/tracing/appsignal_tracing.rb +8 -0
- data/lib/graphql/tracing/data_dog_tracing.rb +8 -0
- data/lib/graphql/tracing/new_relic_tracing.rb +9 -12
- data/lib/graphql/tracing/platform_tracing.rb +53 -9
- data/lib/graphql/tracing/prometheus_tracing/graphql_collector.rb +4 -1
- data/lib/graphql/tracing/prometheus_tracing.rb +8 -0
- data/lib/graphql/tracing/scout_tracing.rb +19 -0
- data/lib/graphql/tracing/skylight_tracing.rb +8 -0
- data/lib/graphql/tracing/statsd_tracing.rb +42 -0
- data/lib/graphql/tracing.rb +14 -34
- data/lib/graphql/types/big_int.rb +1 -1
- data/lib/graphql/types/int.rb +9 -2
- data/lib/graphql/types/iso_8601_date.rb +3 -3
- data/lib/graphql/types/iso_8601_date_time.rb +25 -10
- data/lib/graphql/types/relay/base_connection.rb +11 -7
- data/lib/graphql/types/relay/base_edge.rb +2 -1
- data/lib/graphql/types/string.rb +7 -1
- data/lib/graphql/unauthorized_error.rb +1 -1
- data/lib/graphql/union_type.rb +13 -28
- data/lib/graphql/unresolved_type_error.rb +2 -2
- data/lib/graphql/version.rb +1 -1
- data/lib/graphql.rb +31 -6
- data/readme.md +1 -1
- metadata +34 -9
- data/lib/graphql/literal_validation_error.rb +0 -6
@@ -26,18 +26,7 @@ module GraphQL
|
|
26
26
|
if key == "execute_query"
|
27
27
|
set_this_txn_name = data[:query].context[:set_new_relic_transaction_name]
|
28
28
|
if set_this_txn_name == true || (set_this_txn_name.nil? && @set_transaction_name)
|
29
|
-
|
30
|
-
# Set the transaction name based on the operation type and name
|
31
|
-
selected_op = query.selected_operation
|
32
|
-
if selected_op
|
33
|
-
op_type = selected_op.operation_type
|
34
|
-
op_name = selected_op.name || "anonymous"
|
35
|
-
else
|
36
|
-
op_type = "query"
|
37
|
-
op_name = "anonymous"
|
38
|
-
end
|
39
|
-
|
40
|
-
NewRelic::Agent.set_transaction_name("GraphQL/#{op_type}.#{op_name}")
|
29
|
+
NewRelic::Agent.set_transaction_name(transaction_name(data[:query]))
|
41
30
|
end
|
42
31
|
end
|
43
32
|
|
@@ -49,6 +38,14 @@ module GraphQL
|
|
49
38
|
def platform_field_key(type, field)
|
50
39
|
"GraphQL/#{type.graphql_name}/#{field.graphql_name}"
|
51
40
|
end
|
41
|
+
|
42
|
+
def platform_authorized_key(type)
|
43
|
+
"GraphQL/Authorize/#{type.graphql_name}"
|
44
|
+
end
|
45
|
+
|
46
|
+
def platform_resolve_type_key(type)
|
47
|
+
"GraphQL/ResolveType/#{type.graphql_name}"
|
48
|
+
end
|
52
49
|
end
|
53
50
|
end
|
54
51
|
end
|
@@ -21,7 +21,6 @@ module GraphQL
|
|
21
21
|
def trace(key, data)
|
22
22
|
case key
|
23
23
|
when "lex", "parse", "validate", "analyze_query", "analyze_multiplex", "execute_query", "execute_query_lazy", "execute_multiplex"
|
24
|
-
data.fetch(:query).context.namespace(self.class)[:platform_key_cache] = {} if key == "execute_query"
|
25
24
|
platform_key = @platform_keys.fetch(key)
|
26
25
|
platform_trace(platform_key, key, data) do
|
27
26
|
yield
|
@@ -33,18 +32,19 @@ module GraphQL
|
|
33
32
|
trace_field = true # implemented with instrumenter
|
34
33
|
else
|
35
34
|
field = data[:field]
|
36
|
-
platform_key_cache = data.fetch(:query).context.namespace(self.class).fetch(:platform_key_cache)
|
37
|
-
platform_key = platform_key_cache.fetch(field) do
|
38
|
-
platform_key_cache[field] = platform_field_key(data[:owner], field)
|
39
|
-
end
|
40
|
-
|
41
35
|
return_type = field.type.unwrap
|
42
|
-
|
43
|
-
trace_field = if return_type.respond_to?(:kind) && (return_type.kind.scalar? || return_type.kind.enum?)
|
36
|
+
trace_field = if return_type.kind.scalar? || return_type.kind.enum?
|
44
37
|
(field.trace.nil? && @trace_scalars) || field.trace
|
45
38
|
else
|
46
39
|
true
|
47
40
|
end
|
41
|
+
|
42
|
+
platform_key = if trace_field
|
43
|
+
context = data.fetch(:query).context
|
44
|
+
cached_platform_key(context, field) { platform_field_key(data[:owner], field) }
|
45
|
+
else
|
46
|
+
nil
|
47
|
+
end
|
48
48
|
end
|
49
49
|
|
50
50
|
if platform_key && trace_field
|
@@ -54,6 +54,20 @@ module GraphQL
|
|
54
54
|
else
|
55
55
|
yield
|
56
56
|
end
|
57
|
+
when "authorized", "authorized_lazy"
|
58
|
+
type = data.fetch(:type)
|
59
|
+
context = data.fetch(:context)
|
60
|
+
platform_key = cached_platform_key(context, type) { platform_authorized_key(type) }
|
61
|
+
platform_trace(platform_key, key, data) do
|
62
|
+
yield
|
63
|
+
end
|
64
|
+
when "resolve_type", "resolve_type_lazy"
|
65
|
+
type = data.fetch(:type)
|
66
|
+
context = data.fetch(:context)
|
67
|
+
platform_key = cached_platform_key(context, type) { platform_resolve_type_key(type) }
|
68
|
+
platform_trace(platform_key, key, data) do
|
69
|
+
yield
|
70
|
+
end
|
57
71
|
else
|
58
72
|
# it's a custom key
|
59
73
|
yield
|
@@ -81,13 +95,43 @@ module GraphQL
|
|
81
95
|
end
|
82
96
|
|
83
97
|
def self.use(schema_defn, options = {})
|
84
|
-
tracer = self.new(options)
|
98
|
+
tracer = self.new(**options)
|
85
99
|
schema_defn.instrument(:field, tracer)
|
86
100
|
schema_defn.tracer(tracer)
|
87
101
|
end
|
88
102
|
|
89
103
|
private
|
104
|
+
|
105
|
+
# Get the transaction name based on the operation type and name
|
106
|
+
def transaction_name(query)
|
107
|
+
selected_op = query.selected_operation
|
108
|
+
if selected_op
|
109
|
+
op_type = selected_op.operation_type
|
110
|
+
op_name = selected_op.name || "anonymous"
|
111
|
+
else
|
112
|
+
op_type = "query"
|
113
|
+
op_name = "anonymous"
|
114
|
+
end
|
115
|
+
"GraphQL/#{op_type}.#{op_name}"
|
116
|
+
end
|
117
|
+
|
90
118
|
attr_reader :options
|
119
|
+
|
120
|
+
# Different kind of schema objects have different kinds of keys:
|
121
|
+
#
|
122
|
+
# - Object types: `.authorized`
|
123
|
+
# - Union/Interface types: `.resolve_type`
|
124
|
+
# - Fields: execution
|
125
|
+
#
|
126
|
+
# So, they can all share one cache.
|
127
|
+
#
|
128
|
+
# If the key isn't present, the given block is called and the result is cached for `key`.
|
129
|
+
#
|
130
|
+
# @return [String]
|
131
|
+
def cached_platform_key(ctx, key)
|
132
|
+
cache = ctx.namespace(self.class)[:platform_key_cache] ||= {}
|
133
|
+
cache.fetch(key) { cache[key] = yield }
|
134
|
+
end
|
91
135
|
end
|
92
136
|
end
|
93
137
|
end
|
@@ -16,7 +16,10 @@ module GraphQL
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def collect(object)
|
19
|
-
|
19
|
+
default_labels = { key: object['key'], platform_key: object['platform_key'] }
|
20
|
+
custom = object['custom_labels']
|
21
|
+
labels = custom.nil? ? default_labels : default_labels.merge(custom)
|
22
|
+
|
20
23
|
@graphql_gauge.observe object['duration'], labels
|
21
24
|
end
|
22
25
|
|
@@ -36,6 +36,14 @@ module GraphQL
|
|
36
36
|
"#{type.graphql_name}.#{field.graphql_name}"
|
37
37
|
end
|
38
38
|
|
39
|
+
def platform_authorized_key(type)
|
40
|
+
"#{type.graphql_name}.authorized"
|
41
|
+
end
|
42
|
+
|
43
|
+
def platform_resolve_type_key(type)
|
44
|
+
"#{type.graphql_name}.resolve_type"
|
45
|
+
end
|
46
|
+
|
39
47
|
private
|
40
48
|
|
41
49
|
def instrument_execution(platform_key, key, data, &block)
|
@@ -16,12 +16,23 @@ module GraphQL
|
|
16
16
|
"execute_query_lazy" => "execute.graphql",
|
17
17
|
}
|
18
18
|
|
19
|
+
# @param set_transaction_name [Boolean] If true, the GraphQL operation name will be used as the transaction name.
|
20
|
+
# This is not advised if you run more than one query per HTTP request, for example, with `graphql-client` or multiplexing.
|
21
|
+
# It can also be specified per-query with `context[:set_scout_transaction_name]`.
|
19
22
|
def initialize(options = {})
|
20
23
|
self.class.include ScoutApm::Tracer
|
24
|
+
@set_transaction_name = options.fetch(:set_transaction_name, false)
|
21
25
|
super(options)
|
22
26
|
end
|
23
27
|
|
24
28
|
def platform_trace(platform_key, key, data)
|
29
|
+
if key == "execute_query"
|
30
|
+
set_this_txn_name = data[:query].context[:set_scout_transaction_name]
|
31
|
+
if set_this_txn_name == true || (set_this_txn_name.nil? && @set_transaction_name)
|
32
|
+
ScoutApm::Transaction.rename(transaction_name(data[:query]))
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
25
36
|
self.class.instrument("GraphQL", platform_key, INSTRUMENT_OPTS) do
|
26
37
|
yield
|
27
38
|
end
|
@@ -30,6 +41,14 @@ module GraphQL
|
|
30
41
|
def platform_field_key(type, field)
|
31
42
|
"#{type.graphql_name}.#{field.graphql_name}"
|
32
43
|
end
|
44
|
+
|
45
|
+
def platform_authorized_key(type)
|
46
|
+
"#{type.graphql_name}.authorized"
|
47
|
+
end
|
48
|
+
|
49
|
+
def platform_resolve_type_key(type)
|
50
|
+
"#{type.graphql_name}.resolve_type"
|
51
|
+
end
|
33
52
|
end
|
34
53
|
end
|
35
54
|
end
|
@@ -57,6 +57,14 @@ module GraphQL
|
|
57
57
|
def platform_field_key(type, field)
|
58
58
|
"graphql.#{type.graphql_name}.#{field.graphql_name}"
|
59
59
|
end
|
60
|
+
|
61
|
+
def platform_authorized_key(type)
|
62
|
+
"graphql.authorized.#{type.graphql_name}"
|
63
|
+
end
|
64
|
+
|
65
|
+
def platform_resolve_type_key(type)
|
66
|
+
"graphql.resolve_type.#{type.graphql_name}"
|
67
|
+
end
|
60
68
|
end
|
61
69
|
end
|
62
70
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GraphQL
|
4
|
+
module Tracing
|
5
|
+
class StatsdTracing < PlatformTracing
|
6
|
+
self.platform_keys = {
|
7
|
+
'lex' => "graphql.lex",
|
8
|
+
'parse' => "graphql.parse",
|
9
|
+
'validate' => "graphql.validate",
|
10
|
+
'analyze_query' => "graphql.analyze_query",
|
11
|
+
'analyze_multiplex' => "graphql.analyze_multiplex",
|
12
|
+
'execute_multiplex' => "graphql.execute_multiplex",
|
13
|
+
'execute_query' => "graphql.execute_query",
|
14
|
+
'execute_query_lazy' => "graphql.execute_query_lazy",
|
15
|
+
}
|
16
|
+
|
17
|
+
# @param statsd [Object] A statsd client
|
18
|
+
def initialize(statsd:, **rest)
|
19
|
+
@statsd = statsd
|
20
|
+
super(**rest)
|
21
|
+
end
|
22
|
+
|
23
|
+
def platform_trace(platform_key, key, data)
|
24
|
+
@statsd.time(platform_key) do
|
25
|
+
yield
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def platform_field_key(type, field)
|
30
|
+
"graphql.#{type.graphql_name}.#{field.graphql_name}"
|
31
|
+
end
|
32
|
+
|
33
|
+
def platform_authorized_key(type)
|
34
|
+
"graphql.authorized.#{type.graphql_name}"
|
35
|
+
end
|
36
|
+
|
37
|
+
def platform_resolve_type_key(type)
|
38
|
+
"graphql.resolve_type.#{type.graphql_name}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/graphql/tracing.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require "graphql/tracing/active_support_notifications_tracing"
|
3
3
|
require "graphql/tracing/platform_tracing"
|
4
|
+
require "graphql/tracing/appoptics_tracing"
|
4
5
|
require "graphql/tracing/appsignal_tracing"
|
5
6
|
require "graphql/tracing/data_dog_tracing"
|
6
7
|
require "graphql/tracing/new_relic_tracing"
|
7
8
|
require "graphql/tracing/scout_tracing"
|
8
9
|
require "graphql/tracing/skylight_tracing"
|
10
|
+
require "graphql/tracing/statsd_tracing"
|
9
11
|
require "graphql/tracing/prometheus_tracing"
|
10
12
|
|
11
13
|
if defined?(PrometheusExporter::Server)
|
@@ -15,15 +17,13 @@ end
|
|
15
17
|
module GraphQL
|
16
18
|
# Library entry point for performance metric reporting.
|
17
19
|
#
|
18
|
-
# __Warning:__ Installing/uninstalling tracers is not thread-safe. Do it during application boot only.
|
19
|
-
#
|
20
20
|
# @example Sending custom events
|
21
|
-
#
|
21
|
+
# query.trace("my_custom_event", { ... }) do
|
22
22
|
# # do stuff ...
|
23
23
|
# end
|
24
24
|
#
|
25
25
|
# @example Adding a tracer to a schema
|
26
|
-
# MySchema
|
26
|
+
# class MySchema < GraphQL::Schema
|
27
27
|
# tracer MyTracer # <= responds to .trace(key, data, &block)
|
28
28
|
# end
|
29
29
|
#
|
@@ -43,7 +43,11 @@ module GraphQL
|
|
43
43
|
# execute_query | `{ query: GraphQL::Query }`
|
44
44
|
# execute_query_lazy | `{ query: GraphQL::Query?, multiplex: GraphQL::Execution::Multiplex? }`
|
45
45
|
# execute_field | `{ context: GraphQL::Query::Context::FieldResolutionContext?, owner: Class?, field: GraphQL::Schema::Field?, query: GraphQL::Query?, path: Array<String, Integer>?}`
|
46
|
-
# execute_field_lazy | `{ context: GraphQL::Query::Context::FieldResolutionContext?, owner: Class?, field: GraphQL::Schema::Field?, query:
|
46
|
+
# execute_field_lazy | `{ context: GraphQL::Query::Context::FieldResolutionContext?, owner: Class?, field: GraphQL::Schema::Field?, query: GraphQL::Query?, path: Array<String, Integer>?}`
|
47
|
+
# authorized | `{ context: GraphQL::Query::Context, type: Class, object: Object, path: Array<String, Integer> }`
|
48
|
+
# authorized_lazy | `{ context: GraphQL::Query::Context, type: Class, object: Object, path: Array<String, Integer> }`
|
49
|
+
# resolve_type | `{ context: GraphQL::Query::Context, type: Class, object: Object, path: Array<String, Integer> }`
|
50
|
+
# resolve_type_lazy | `{ context: GraphQL::Query::Context, type: Class, object: Object, path: Array<String, Integer> }`
|
47
51
|
#
|
48
52
|
# Note that `execute_field` and `execute_field_lazy` receive different data in different settings:
|
49
53
|
#
|
@@ -58,8 +62,9 @@ module GraphQL
|
|
58
62
|
# @param key [String] The name of the event in GraphQL internals
|
59
63
|
# @param metadata [Hash] Event-related metadata (can be anything)
|
60
64
|
# @return [Object] Must return the value of the block
|
61
|
-
def trace(key, metadata)
|
62
|
-
|
65
|
+
def trace(key, metadata, &block)
|
66
|
+
return yield if @tracers.empty?
|
67
|
+
call_tracers(0, key, metadata, &block)
|
63
68
|
end
|
64
69
|
|
65
70
|
private
|
@@ -71,39 +76,14 @@ module GraphQL
|
|
71
76
|
# @param key [String] The current event name
|
72
77
|
# @param metadata [Object] The current event object
|
73
78
|
# @return Whatever the block returns
|
74
|
-
def call_tracers(idx, key, metadata)
|
79
|
+
def call_tracers(idx, key, metadata, &block)
|
75
80
|
if idx == @tracers.length
|
76
81
|
yield
|
77
82
|
else
|
78
|
-
@tracers[idx].trace(key, metadata) { call_tracers(idx + 1, key, metadata)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
class << self
|
84
|
-
# Install a tracer to receive events.
|
85
|
-
# @param tracer [<#trace(key, metadata)>]
|
86
|
-
# @return [void]
|
87
|
-
# @deprecated See {Schema#tracer} or use `context: { tracers: [...] }`
|
88
|
-
def install(tracer)
|
89
|
-
warn("GraphQL::Tracing.install is deprecated, add it to the schema with `tracer(my_tracer)` instead.")
|
90
|
-
if !tracers.include?(tracer)
|
91
|
-
@tracers << tracer
|
83
|
+
@tracers[idx].trace(key, metadata) { call_tracers(idx + 1, key, metadata, &block) }
|
92
84
|
end
|
93
85
|
end
|
94
|
-
|
95
|
-
# @deprecated See {Schema#tracer} or use `context: { tracers: [...] }`
|
96
|
-
def uninstall(tracer)
|
97
|
-
@tracers.delete(tracer)
|
98
|
-
end
|
99
|
-
|
100
|
-
# @deprecated See {Schema#tracer} or use `context: { tracers: [...] }`
|
101
|
-
def tracers
|
102
|
-
@tracers ||= []
|
103
|
-
end
|
104
86
|
end
|
105
|
-
# Initialize the array
|
106
|
-
tracers
|
107
87
|
|
108
88
|
module NullTracer
|
109
89
|
module_function
|
@@ -6,7 +6,7 @@ module GraphQL
|
|
6
6
|
description "Represents non-fractional signed whole numeric values. Since the value may exceed the size of a 32-bit integer, it's encoded as a string."
|
7
7
|
|
8
8
|
def self.coerce_input(value, _ctx)
|
9
|
-
Integer(value)
|
9
|
+
value && Integer(value)
|
10
10
|
rescue ArgumentError
|
11
11
|
nil
|
12
12
|
end
|
data/lib/graphql/types/int.rb
CHANGED
@@ -9,8 +9,15 @@ module GraphQL
|
|
9
9
|
MIN = -(2**31)
|
10
10
|
MAX = (2**31) - 1
|
11
11
|
|
12
|
-
def self.coerce_input(value,
|
13
|
-
value.is_a?(
|
12
|
+
def self.coerce_input(value, ctx)
|
13
|
+
return if !value.is_a?(Integer)
|
14
|
+
|
15
|
+
if value >= MIN && value <= MAX
|
16
|
+
value
|
17
|
+
else
|
18
|
+
err = GraphQL::IntegerDecodingError.new(value)
|
19
|
+
ctx.schema.type_error(err, ctx)
|
20
|
+
end
|
14
21
|
end
|
15
22
|
|
16
23
|
def self.coerce_result(value, ctx)
|
@@ -15,17 +15,17 @@ module GraphQL
|
|
15
15
|
class ISO8601Date < GraphQL::Schema::Scalar
|
16
16
|
description "An ISO 8601-encoded date"
|
17
17
|
|
18
|
-
# @param value [Date]
|
18
|
+
# @param value [Date,Time,DateTime,String]
|
19
19
|
# @return [String]
|
20
20
|
def self.coerce_result(value, _ctx)
|
21
|
-
value.iso8601
|
21
|
+
Date.parse(value.to_s).iso8601
|
22
22
|
end
|
23
23
|
|
24
24
|
# @param str_value [String]
|
25
25
|
# @return [Date]
|
26
26
|
def self.coerce_input(str_value, _ctx)
|
27
27
|
Date.iso8601(str_value)
|
28
|
-
rescue ArgumentError
|
28
|
+
rescue ArgumentError, TypeError
|
29
29
|
# Invalid input
|
30
30
|
nil
|
31
31
|
end
|
@@ -1,7 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'time'
|
4
|
+
|
2
5
|
module GraphQL
|
3
6
|
module Types
|
4
|
-
# This scalar takes `
|
7
|
+
# This scalar takes `Time`s and transmits them as strings,
|
5
8
|
# using ISO 8601 format.
|
6
9
|
#
|
7
10
|
# Use it for fields or arguments as follows:
|
@@ -29,21 +32,33 @@ module GraphQL
|
|
29
32
|
@time_precision = value
|
30
33
|
end
|
31
34
|
|
32
|
-
# @param value [DateTime]
|
35
|
+
# @param value [Time,Date,DateTime,String]
|
33
36
|
# @return [String]
|
34
37
|
def self.coerce_result(value, _ctx)
|
35
|
-
value
|
36
|
-
|
37
|
-
|
38
|
+
case value
|
39
|
+
when Date
|
40
|
+
return value.to_time.iso8601(time_precision)
|
41
|
+
when ::String
|
42
|
+
return Time.parse(value).iso8601(time_precision)
|
43
|
+
else
|
44
|
+
# Time, DateTime or compatible is given:
|
45
|
+
return value.iso8601(time_precision)
|
46
|
+
end
|
47
|
+
rescue StandardError => error
|
48
|
+
raise GraphQL::Error, "An incompatible object (#{value.class}) was given to #{self}. Make sure that only Times, Dates, DateTimes, and well-formatted Strings are used with this type. (#{error.message})"
|
38
49
|
end
|
39
50
|
|
40
51
|
# @param str_value [String]
|
41
|
-
# @return [
|
52
|
+
# @return [Time]
|
42
53
|
def self.coerce_input(str_value, _ctx)
|
43
|
-
|
44
|
-
rescue ArgumentError
|
45
|
-
|
46
|
-
|
54
|
+
Time.iso8601(str_value)
|
55
|
+
rescue ArgumentError, TypeError
|
56
|
+
begin
|
57
|
+
Date.iso8601(str_value).to_time
|
58
|
+
rescue ArgumentError, TypeError
|
59
|
+
# Invalid input
|
60
|
+
nil
|
61
|
+
end
|
47
62
|
end
|
48
63
|
end
|
49
64
|
end
|
@@ -48,7 +48,7 @@ module GraphQL
|
|
48
48
|
# It's called when you subclass this base connection, trying to use the
|
49
49
|
# class name to set defaults. You can call it again in the class definition
|
50
50
|
# to override the default (or provide a value, if the default lookup failed).
|
51
|
-
def edge_type(edge_type_class, edge_class: GraphQL::Relay::Edge, node_type: edge_type_class.node_type, nodes_field: true)
|
51
|
+
def edge_type(edge_type_class, edge_class: GraphQL::Relay::Edge, node_type: edge_type_class.node_type, nodes_field: true, node_nullable: true)
|
52
52
|
# Set this connection's graphql name
|
53
53
|
node_type_name = node_type.graphql_name
|
54
54
|
|
@@ -61,7 +61,7 @@ module GraphQL
|
|
61
61
|
description: "A list of edges.",
|
62
62
|
edge_class: edge_class
|
63
63
|
|
64
|
-
define_nodes_field if nodes_field
|
64
|
+
define_nodes_field(node_nullable) if nodes_field
|
65
65
|
|
66
66
|
description("The connection type for #{node_type_name}.")
|
67
67
|
end
|
@@ -90,10 +90,12 @@ module GraphQL
|
|
90
90
|
|
91
91
|
private
|
92
92
|
|
93
|
-
def define_nodes_field
|
94
|
-
|
95
|
-
|
96
|
-
|
93
|
+
def define_nodes_field(nullable = true)
|
94
|
+
type = nullable ? [@node_type, null: true] : [@node_type]
|
95
|
+
field :nodes, type,
|
96
|
+
null: nullable,
|
97
|
+
description: "A list of nodes.",
|
98
|
+
connection: false
|
97
99
|
end
|
98
100
|
end
|
99
101
|
|
@@ -106,7 +108,9 @@ module GraphQL
|
|
106
108
|
end
|
107
109
|
|
108
110
|
def edges
|
109
|
-
if
|
111
|
+
if @object.is_a?(GraphQL::Pagination::Connection)
|
112
|
+
@object.edges
|
113
|
+
elsif context.interpreter?
|
110
114
|
context.schema.after_lazy(object.edge_nodes) do |nodes|
|
111
115
|
nodes.map { |n| self.class.edge_class.new(n, object) }
|
112
116
|
end
|
@@ -33,7 +33,8 @@ module GraphQL
|
|
33
33
|
if node_type
|
34
34
|
@node_type = node_type
|
35
35
|
# Add a default `node` field
|
36
|
-
field :node, node_type, null: null, description: "The item at the end of the edge."
|
36
|
+
field :node, node_type, null: null, description: "The item at the end of the edge.",
|
37
|
+
connection: false
|
37
38
|
end
|
38
39
|
@node_type
|
39
40
|
end
|
data/lib/graphql/types/string.rb
CHANGED
@@ -7,7 +7,13 @@ module GraphQL
|
|
7
7
|
|
8
8
|
def self.coerce_result(value, ctx)
|
9
9
|
str = value.to_s
|
10
|
-
str.encoding == Encoding::UTF_8
|
10
|
+
if str.encoding == Encoding::UTF_8
|
11
|
+
str
|
12
|
+
elsif str.frozen?
|
13
|
+
str.encode(Encoding::UTF_8)
|
14
|
+
else
|
15
|
+
str.encode!(Encoding::UTF_8)
|
16
|
+
end
|
11
17
|
rescue EncodingError
|
12
18
|
err = GraphQL::StringEncodingError.new(str)
|
13
19
|
ctx.schema.type_error(err, ctx)
|
@@ -22,7 +22,7 @@ module GraphQL
|
|
22
22
|
@object = object
|
23
23
|
@type = type
|
24
24
|
@context = context
|
25
|
-
message ||= "An instance of #{object.class} failed #{type.
|
25
|
+
message ||= "An instance of #{object.class} failed #{type.graphql_name}'s authorization check"
|
26
26
|
super(message)
|
27
27
|
end
|
28
28
|
end
|
data/lib/graphql/union_type.rb
CHANGED
@@ -1,31 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
module GraphQL
|
3
|
-
#
|
4
|
-
#
|
5
|
-
# The members of a union are declared with `possible_types`.
|
6
|
-
#
|
7
|
-
# @example A union of object types
|
8
|
-
# MediaUnion = GraphQL::UnionType.define do
|
9
|
-
# name "Media"
|
10
|
-
# description "Media objects which you can enjoy"
|
11
|
-
# possible_types [AudioType, ImageType, VideoType]
|
12
|
-
# end
|
13
|
-
#
|
14
|
-
# A union itself has no fields; only its members have fields.
|
15
|
-
# So, when you query, you must use fragment spreads to access fields.
|
16
|
-
#
|
17
|
-
# @example Querying for fields on union members
|
18
|
-
# {
|
19
|
-
# searchMedia(name: "Jens Lekman") {
|
20
|
-
# ... on Audio { name, duration }
|
21
|
-
# ... on Image { name, height, width }
|
22
|
-
# ... on Video { name, length, quality }
|
23
|
-
# }
|
24
|
-
# }
|
25
|
-
#
|
3
|
+
# @api deprecated
|
26
4
|
class UnionType < GraphQL::BaseType
|
5
|
+
# Rubocop was unhappy about the syntax when this was a proc literal
|
6
|
+
class AcceptPossibleTypesDefinition
|
7
|
+
def self.call(target, possible_types, options = {})
|
8
|
+
target.add_possible_types(possible_types, **options)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
27
12
|
accepts_definitions :resolve_type, :type_membership_class,
|
28
|
-
possible_types:
|
13
|
+
possible_types: AcceptPossibleTypesDefinition
|
29
14
|
ensure_defined :possible_types, :resolve_type, :resolve_type_proc, :type_membership_class
|
30
15
|
|
31
16
|
attr_accessor :resolve_type_proc
|
@@ -72,13 +57,13 @@ module GraphQL
|
|
72
57
|
# This is a re-assignment, so clear the previous values
|
73
58
|
@type_memberships = []
|
74
59
|
@cached_possible_types = nil
|
75
|
-
add_possible_types(types, {})
|
60
|
+
add_possible_types(types, **{})
|
76
61
|
end
|
77
62
|
|
78
|
-
def add_possible_types(types, options)
|
63
|
+
def add_possible_types(types, **options)
|
79
64
|
@type_memberships ||= []
|
80
65
|
Array(types).each { |t|
|
81
|
-
@type_memberships << self.type_membership_class.new(self, t, options)
|
66
|
+
@type_memberships << self.type_membership_class.new(self, t, **options)
|
82
67
|
}
|
83
68
|
nil
|
84
69
|
end
|
@@ -89,7 +74,7 @@ module GraphQL
|
|
89
74
|
# @return [GraphQL::ObjectType, nil] The type named `type_name` if it exists and is a member of this {UnionType}, (else `nil`)
|
90
75
|
def get_possible_type(type_name, ctx)
|
91
76
|
type = ctx.query.get_type(type_name)
|
92
|
-
type if type && ctx.query.
|
77
|
+
type if type && ctx.query.warden.possible_types(self).include?(type)
|
93
78
|
end
|
94
79
|
|
95
80
|
# Check if a type is a possible type of this {UnionType}
|
@@ -24,8 +24,8 @@ module GraphQL
|
|
24
24
|
@parent_type = parent_type
|
25
25
|
@resolved_type = resolved_type
|
26
26
|
@possible_types = possible_types
|
27
|
-
message = "The value from \"#{field.
|
28
|
-
"(Received: `#{resolved_type.inspect}`, Expected: [#{possible_types.map(&:
|
27
|
+
message = "The value from \"#{field.graphql_name}\" on \"#{parent_type.graphql_name}\" could not be resolved to \"#{field.type.to_type_signature}\". " \
|
28
|
+
"(Received: `#{resolved_type.inspect}`, Expected: [#{possible_types.map(&:graphql_name).join(", ")}]) " \
|
29
29
|
"Make sure you have defined a `resolve_type` proc on your schema and that value `#{value.inspect}` " \
|
30
30
|
"gets resolved to a valid type. You may need to add your type to `orphan_types` if it implements an " \
|
31
31
|
"interface but isn't a return type of any other field."
|
data/lib/graphql/version.rb
CHANGED