graphql 1.13.24 → 2.0.0
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/graphql/analysis/ast/query_complexity.rb +1 -1
- data/lib/graphql/analysis/ast/query_depth.rb +0 -1
- data/lib/graphql/analysis/ast/visitor.rb +1 -1
- data/lib/graphql/analysis/ast.rb +0 -10
- data/lib/graphql/analysis.rb +0 -7
- data/lib/graphql/backtrace/table.rb +0 -18
- data/lib/graphql/backtrace/tracer.rb +1 -2
- data/lib/graphql/backtrace.rb +2 -8
- data/lib/graphql/dig.rb +1 -1
- data/lib/graphql/execution/errors.rb +1 -9
- data/lib/graphql/execution/interpreter/runtime.rb +6 -13
- data/lib/graphql/execution/interpreter.rb +0 -22
- data/lib/graphql/execution/lazy.rb +1 -1
- data/lib/graphql/execution/lookahead.rb +6 -13
- data/lib/graphql/execution/multiplex.rb +50 -107
- data/lib/graphql/execution.rb +11 -3
- data/lib/graphql/introspection/directive_type.rb +2 -2
- data/lib/graphql/introspection/dynamic_fields.rb +3 -8
- data/lib/graphql/introspection/entry_points.rb +2 -15
- data/lib/graphql/introspection/field_type.rb +1 -1
- data/lib/graphql/introspection/schema_type.rb +2 -2
- data/lib/graphql/introspection/type_type.rb +5 -5
- data/lib/graphql/language/document_from_schema_definition.rb +0 -17
- data/lib/graphql/language/nodes.rb +0 -3
- data/lib/graphql/pagination/connections.rb +2 -28
- data/lib/graphql/query/context.rb +1 -185
- data/lib/graphql/query/input_validation_result.rb +0 -9
- data/lib/graphql/query/literal_input.rb +8 -13
- data/lib/graphql/query/validation_pipeline.rb +6 -34
- data/lib/graphql/query/variable_validation_error.rb +2 -2
- data/lib/graphql/query/variables.rb +8 -31
- data/lib/graphql/query.rb +5 -34
- data/lib/graphql/railtie.rb +0 -104
- data/lib/graphql/relay/range_add.rb +0 -4
- data/lib/graphql/relay.rb +0 -15
- data/lib/graphql/schema/addition.rb +1 -8
- data/lib/graphql/schema/argument.rb +6 -28
- data/lib/graphql/schema/build_from_definition.rb +7 -9
- data/lib/graphql/schema/directive.rb +1 -22
- data/lib/graphql/schema/enum.rb +3 -19
- data/lib/graphql/schema/enum_value.rb +1 -23
- data/lib/graphql/schema/field.rb +22 -221
- data/lib/graphql/schema/input_object.rb +17 -65
- data/lib/graphql/schema/interface.rb +1 -30
- data/lib/graphql/schema/introspection_system.rb +3 -8
- data/lib/graphql/schema/late_bound_type.rb +2 -2
- data/lib/graphql/schema/list.rb +3 -24
- data/lib/graphql/schema/loader.rb +0 -1
- data/lib/graphql/schema/member/base_dsl_methods.rb +1 -6
- data/lib/graphql/schema/member/build_type.rb +4 -6
- data/lib/graphql/schema/member/has_arguments.rb +16 -20
- data/lib/graphql/schema/member/has_fields.rb +3 -3
- data/lib/graphql/schema/member/has_interfaces.rb +1 -13
- data/lib/graphql/schema/member/validates_input.rb +2 -2
- data/lib/graphql/schema/member.rb +0 -6
- data/lib/graphql/schema/mutation.rb +0 -9
- data/lib/graphql/schema/non_null.rb +3 -9
- data/lib/graphql/schema/object.rb +0 -40
- data/lib/graphql/schema/relay_classic_mutation.rb +17 -28
- data/lib/graphql/schema/scalar.rb +1 -16
- data/lib/graphql/schema/union.rb +0 -16
- data/lib/graphql/schema/warden.rb +3 -12
- data/lib/graphql/schema/wrapper.rb +0 -5
- data/lib/graphql/schema.rb +106 -945
- data/lib/graphql/static_validation/base_visitor.rb +4 -21
- data/lib/graphql/static_validation/rules/directives_are_in_valid_locations.rb +12 -12
- data/lib/graphql/static_validation/validator.rb +2 -24
- data/lib/graphql/static_validation.rb +0 -2
- data/lib/graphql/subscriptions/default_subscription_resolve_extension.rb +38 -1
- data/lib/graphql/subscriptions/event.rb +1 -1
- data/lib/graphql/subscriptions/instrumentation.rb +0 -51
- data/lib/graphql/subscriptions.rb +4 -13
- data/lib/graphql/tracing/data_dog_tracing.rb +16 -20
- data/lib/graphql/tracing/platform_tracing.rb +4 -32
- data/lib/graphql/tracing.rb +0 -1
- data/lib/graphql/types/relay/connection_behaviors.rb +2 -6
- data/lib/graphql/types/relay/default_relay.rb +0 -10
- data/lib/graphql/types/relay/node_behaviors.rb +5 -1
- data/lib/graphql/types/relay.rb +0 -2
- data/lib/graphql/types/string.rb +1 -1
- data/lib/graphql/version.rb +1 -1
- data/lib/graphql.rb +1 -66
- metadata +28 -164
- data/lib/graphql/analysis/analyze_query.rb +0 -98
- data/lib/graphql/analysis/field_usage.rb +0 -45
- data/lib/graphql/analysis/max_query_complexity.rb +0 -26
- data/lib/graphql/analysis/max_query_depth.rb +0 -26
- data/lib/graphql/analysis/query_complexity.rb +0 -88
- data/lib/graphql/analysis/query_depth.rb +0 -43
- data/lib/graphql/analysis/reducer_state.rb +0 -48
- data/lib/graphql/argument.rb +0 -131
- data/lib/graphql/authorization.rb +0 -82
- data/lib/graphql/backtrace/legacy_tracer.rb +0 -56
- data/lib/graphql/backwards_compatibility.rb +0 -61
- data/lib/graphql/base_type.rb +0 -232
- data/lib/graphql/boolean_type.rb +0 -2
- data/lib/graphql/compatibility/execution_specification/counter_schema.rb +0 -53
- data/lib/graphql/compatibility/execution_specification/specification_schema.rb +0 -200
- data/lib/graphql/compatibility/execution_specification.rb +0 -436
- data/lib/graphql/compatibility/lazy_execution_specification/lazy_schema.rb +0 -111
- data/lib/graphql/compatibility/lazy_execution_specification.rb +0 -215
- data/lib/graphql/compatibility/query_parser_specification/parse_error_specification.rb +0 -87
- data/lib/graphql/compatibility/query_parser_specification/query_assertions.rb +0 -79
- data/lib/graphql/compatibility/query_parser_specification.rb +0 -266
- data/lib/graphql/compatibility/schema_parser_specification.rb +0 -682
- data/lib/graphql/compatibility.rb +0 -5
- data/lib/graphql/define/assign_argument.rb +0 -12
- data/lib/graphql/define/assign_connection.rb +0 -13
- data/lib/graphql/define/assign_enum_value.rb +0 -18
- data/lib/graphql/define/assign_global_id_field.rb +0 -11
- data/lib/graphql/define/assign_mutation_function.rb +0 -34
- data/lib/graphql/define/assign_object_field.rb +0 -42
- data/lib/graphql/define/defined_object_proxy.rb +0 -53
- data/lib/graphql/define/instance_definable.rb +0 -255
- data/lib/graphql/define/no_definition_error.rb +0 -7
- data/lib/graphql/define/non_null_with_bang.rb +0 -16
- data/lib/graphql/define/type_definer.rb +0 -31
- data/lib/graphql/define.rb +0 -31
- data/lib/graphql/deprecated_dsl.rb +0 -55
- data/lib/graphql/directive/deprecated_directive.rb +0 -2
- data/lib/graphql/directive/include_directive.rb +0 -2
- data/lib/graphql/directive/skip_directive.rb +0 -2
- data/lib/graphql/directive.rb +0 -107
- data/lib/graphql/enum_type.rb +0 -133
- data/lib/graphql/execution/execute.rb +0 -333
- data/lib/graphql/execution/flatten.rb +0 -40
- data/lib/graphql/execution/typecast.rb +0 -50
- data/lib/graphql/field/resolve.rb +0 -59
- data/lib/graphql/field.rb +0 -226
- data/lib/graphql/float_type.rb +0 -2
- data/lib/graphql/function.rb +0 -128
- data/lib/graphql/id_type.rb +0 -2
- data/lib/graphql/input_object_type.rb +0 -138
- data/lib/graphql/int_type.rb +0 -2
- data/lib/graphql/interface_type.rb +0 -72
- data/lib/graphql/internal_representation/document.rb +0 -27
- data/lib/graphql/internal_representation/node.rb +0 -206
- data/lib/graphql/internal_representation/print.rb +0 -51
- data/lib/graphql/internal_representation/rewrite.rb +0 -184
- data/lib/graphql/internal_representation/scope.rb +0 -88
- data/lib/graphql/internal_representation/visit.rb +0 -36
- data/lib/graphql/internal_representation.rb +0 -7
- data/lib/graphql/list_type.rb +0 -80
- data/lib/graphql/non_null_type.rb +0 -71
- data/lib/graphql/object_type.rb +0 -130
- data/lib/graphql/query/arguments.rb +0 -189
- data/lib/graphql/query/arguments_cache.rb +0 -24
- data/lib/graphql/query/executor.rb +0 -52
- data/lib/graphql/query/serial_execution/field_resolution.rb +0 -92
- data/lib/graphql/query/serial_execution/operation_resolution.rb +0 -19
- data/lib/graphql/query/serial_execution/selection_resolution.rb +0 -23
- data/lib/graphql/query/serial_execution/value_resolution.rb +0 -87
- data/lib/graphql/query/serial_execution.rb +0 -40
- data/lib/graphql/relay/array_connection.rb +0 -83
- data/lib/graphql/relay/base_connection.rb +0 -189
- data/lib/graphql/relay/connection_instrumentation.rb +0 -54
- data/lib/graphql/relay/connection_resolve.rb +0 -43
- data/lib/graphql/relay/connection_type.rb +0 -54
- data/lib/graphql/relay/edge.rb +0 -27
- data/lib/graphql/relay/edge_type.rb +0 -19
- data/lib/graphql/relay/edges_instrumentation.rb +0 -39
- data/lib/graphql/relay/global_id_resolve.rb +0 -17
- data/lib/graphql/relay/mongo_relation_connection.rb +0 -50
- data/lib/graphql/relay/mutation/instrumentation.rb +0 -23
- data/lib/graphql/relay/mutation/resolve.rb +0 -56
- data/lib/graphql/relay/mutation/result.rb +0 -38
- data/lib/graphql/relay/mutation.rb +0 -106
- data/lib/graphql/relay/node.rb +0 -39
- data/lib/graphql/relay/page_info.rb +0 -7
- data/lib/graphql/relay/relation_connection.rb +0 -188
- data/lib/graphql/relay/type_extensions.rb +0 -32
- data/lib/graphql/scalar_type.rb +0 -91
- data/lib/graphql/schema/catchall_middleware.rb +0 -35
- data/lib/graphql/schema/default_parse_error.rb +0 -10
- data/lib/graphql/schema/default_type_error.rb +0 -17
- data/lib/graphql/schema/member/accepts_definition.rb +0 -164
- data/lib/graphql/schema/member/cached_graphql_definition.rb +0 -58
- data/lib/graphql/schema/member/instrumentation.rb +0 -131
- data/lib/graphql/schema/middleware_chain.rb +0 -82
- data/lib/graphql/schema/possible_types.rb +0 -44
- data/lib/graphql/schema/rescue_middleware.rb +0 -60
- data/lib/graphql/schema/timeout_middleware.rb +0 -88
- data/lib/graphql/schema/traversal.rb +0 -228
- data/lib/graphql/schema/validation.rb +0 -313
- data/lib/graphql/static_validation/default_visitor.rb +0 -15
- data/lib/graphql/static_validation/no_validate_visitor.rb +0 -10
- data/lib/graphql/string_type.rb +0 -2
- data/lib/graphql/subscriptions/subscription_root.rb +0 -76
- data/lib/graphql/tracing/skylight_tracing.rb +0 -70
- data/lib/graphql/types/relay/node_field.rb +0 -24
- data/lib/graphql/types/relay/nodes_field.rb +0 -43
- data/lib/graphql/union_type.rb +0 -115
- data/lib/graphql/upgrader/member.rb +0 -937
- data/lib/graphql/upgrader/schema.rb +0 -38
@@ -14,11 +14,6 @@ module GraphQL
|
|
14
14
|
super(document)
|
15
15
|
end
|
16
16
|
|
17
|
-
# This will be overwritten by {InternalRepresentation::Rewrite} if it's included
|
18
|
-
def rewrite_document
|
19
|
-
nil
|
20
|
-
end
|
21
|
-
|
22
17
|
attr_reader :context
|
23
18
|
|
24
19
|
# @return [Array<GraphQL::ObjectType>] Types whose scope we've entered
|
@@ -32,22 +27,13 @@ module GraphQL
|
|
32
27
|
# Build a class to visit the AST and perform validation,
|
33
28
|
# or use a pre-built class if rules is `ALL_RULES` or empty.
|
34
29
|
# @param rules [Array<Module, Class>]
|
35
|
-
# @param rewrite [Boolean] if `false`, don't include rewrite
|
36
30
|
# @return [Class] A class for validating `rules` during visitation
|
37
|
-
def self.including_rules(rules
|
31
|
+
def self.including_rules(rules)
|
38
32
|
if rules.empty?
|
39
|
-
|
40
|
-
|
41
|
-
else
|
42
|
-
# It's not doing _anything?!?_
|
43
|
-
BaseVisitor
|
44
|
-
end
|
33
|
+
# It's not doing _anything?!?_
|
34
|
+
BaseVisitor
|
45
35
|
elsif rules == ALL_RULES
|
46
|
-
|
47
|
-
DefaultVisitor
|
48
|
-
else
|
49
|
-
InterpreterVisitor
|
50
|
-
end
|
36
|
+
InterpreterVisitor
|
51
37
|
else
|
52
38
|
visitor_class = Class.new(self) do
|
53
39
|
include(GraphQL::StaticValidation::DefinitionDependencies)
|
@@ -60,9 +46,6 @@ module GraphQL
|
|
60
46
|
end
|
61
47
|
end
|
62
48
|
|
63
|
-
if rewrite
|
64
|
-
visitor_class.include(GraphQL::InternalRepresentation::Rewrite)
|
65
|
-
end
|
66
49
|
visitor_class.include(ContextMethods)
|
67
50
|
visitor_class
|
68
51
|
end
|
@@ -12,20 +12,20 @@ module GraphQL
|
|
12
12
|
private
|
13
13
|
|
14
14
|
LOCATION_MESSAGE_NAMES = {
|
15
|
-
GraphQL::Directive::QUERY => "queries",
|
16
|
-
GraphQL::Directive::MUTATION => "mutations",
|
17
|
-
GraphQL::Directive::SUBSCRIPTION => "subscriptions",
|
18
|
-
GraphQL::Directive::FIELD => "fields",
|
19
|
-
GraphQL::Directive::FRAGMENT_DEFINITION => "fragment definitions",
|
20
|
-
GraphQL::Directive::FRAGMENT_SPREAD => "fragment spreads",
|
21
|
-
GraphQL::Directive::INLINE_FRAGMENT => "inline fragments",
|
15
|
+
GraphQL::Schema::Directive::QUERY => "queries",
|
16
|
+
GraphQL::Schema::Directive::MUTATION => "mutations",
|
17
|
+
GraphQL::Schema::Directive::SUBSCRIPTION => "subscriptions",
|
18
|
+
GraphQL::Schema::Directive::FIELD => "fields",
|
19
|
+
GraphQL::Schema::Directive::FRAGMENT_DEFINITION => "fragment definitions",
|
20
|
+
GraphQL::Schema::Directive::FRAGMENT_SPREAD => "fragment spreads",
|
21
|
+
GraphQL::Schema::Directive::INLINE_FRAGMENT => "inline fragments",
|
22
22
|
}
|
23
23
|
|
24
24
|
SIMPLE_LOCATIONS = {
|
25
|
-
Nodes::Field => GraphQL::Directive::FIELD,
|
26
|
-
Nodes::InlineFragment => GraphQL::Directive::INLINE_FRAGMENT,
|
27
|
-
Nodes::FragmentSpread => GraphQL::Directive::FRAGMENT_SPREAD,
|
28
|
-
Nodes::FragmentDefinition => GraphQL::Directive::FRAGMENT_DEFINITION,
|
25
|
+
Nodes::Field => GraphQL::Schema::Directive::FIELD,
|
26
|
+
Nodes::InlineFragment => GraphQL::Schema::Directive::INLINE_FRAGMENT,
|
27
|
+
Nodes::FragmentSpread => GraphQL::Schema::Directive::FRAGMENT_SPREAD,
|
28
|
+
Nodes::FragmentDefinition => GraphQL::Schema::Directive::FRAGMENT_DEFINITION,
|
29
29
|
}
|
30
30
|
|
31
31
|
SIMPLE_LOCATION_NODES = SIMPLE_LOCATIONS.keys
|
@@ -34,7 +34,7 @@ module GraphQL
|
|
34
34
|
directive_defn = directives[ast_directive.name]
|
35
35
|
case ast_parent
|
36
36
|
when Nodes::OperationDefinition
|
37
|
-
required_location = GraphQL::Directive.const_get(ast_parent.operation_type.upcase)
|
37
|
+
required_location = GraphQL::Schema::Directive.const_get(ast_parent.operation_type.upcase)
|
38
38
|
assert_includes_location(directive_defn, ast_directive, required_location)
|
39
39
|
when *SIMPLE_LOCATION_NODES
|
40
40
|
required_location = SIMPLE_LOCATIONS[ast_parent.class]
|
@@ -28,12 +28,11 @@ module GraphQL
|
|
28
28
|
# @return [Array<Hash>]
|
29
29
|
def validate(query, validate: true, timeout: nil, max_errors: nil)
|
30
30
|
query.trace("validate", { validate: validate, query: query }) do
|
31
|
-
|
32
|
-
errors = if validate == false && can_skip_rewrite
|
31
|
+
errors = if validate == false
|
33
32
|
[]
|
34
33
|
else
|
35
34
|
rules_to_use = validate ? @rules : []
|
36
|
-
visitor_class = BaseVisitor.including_rules(rules_to_use
|
35
|
+
visitor_class = BaseVisitor.including_rules(rules_to_use)
|
37
36
|
|
38
37
|
context = GraphQL::StaticValidation::ValidationContext.new(query, visitor_class, max_errors)
|
39
38
|
|
@@ -42,18 +41,6 @@ module GraphQL
|
|
42
41
|
# A timeout value of 0 or nil will execute the block without any timeout.
|
43
42
|
Timeout::timeout(timeout) do
|
44
43
|
catch(:too_many_validation_errors) do
|
45
|
-
# Attach legacy-style rules.
|
46
|
-
# Only loop through rules if it has legacy-style rules
|
47
|
-
unless (legacy_rules = rules_to_use - GraphQL::StaticValidation::ALL_RULES).empty?
|
48
|
-
legacy_rules.each do |rule_class_or_module|
|
49
|
-
if rule_class_or_module.method_defined?(:validate)
|
50
|
-
GraphQL::Deprecation.warn "Legacy validator rules will be removed from GraphQL-Ruby 2.0, use a module instead (see the built-in rules: https://github.com/rmosolgo/graphql-ruby/tree/master/lib/graphql/static_validation/rules)"
|
51
|
-
GraphQL::Deprecation.warn " -> Legacy validator: #{rule_class_or_module}"
|
52
|
-
rule_class_or_module.new.validate(context)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
44
|
context.visitor.visit
|
58
45
|
end
|
59
46
|
end
|
@@ -64,22 +51,13 @@ module GraphQL
|
|
64
51
|
context.errors
|
65
52
|
end
|
66
53
|
|
67
|
-
irep = if errors.empty? && context
|
68
|
-
# Only return this if there are no errors and validation was actually run
|
69
|
-
context.visitor.rewrite_document
|
70
|
-
else
|
71
|
-
nil
|
72
|
-
end
|
73
|
-
|
74
54
|
{
|
75
55
|
errors: errors,
|
76
|
-
irep: irep,
|
77
56
|
}
|
78
57
|
end
|
79
58
|
rescue GraphQL::ExecutionError => e
|
80
59
|
{
|
81
60
|
errors: [e],
|
82
|
-
irep: nil,
|
83
61
|
}
|
84
62
|
end
|
85
63
|
|
@@ -7,7 +7,6 @@ require "graphql/static_validation/validation_context"
|
|
7
7
|
require "graphql/static_validation/validation_timeout_error"
|
8
8
|
require "graphql/static_validation/literal_validator"
|
9
9
|
require "graphql/static_validation/base_visitor"
|
10
|
-
require "graphql/static_validation/no_validate_visitor"
|
11
10
|
|
12
11
|
rules_glob = File.expand_path("../static_validation/rules/*.rb", __FILE__)
|
13
12
|
Dir.glob(rules_glob).each do |file|
|
@@ -15,5 +14,4 @@ Dir.glob(rules_glob).each do |file|
|
|
15
14
|
end
|
16
15
|
|
17
16
|
require "graphql/static_validation/all_rules"
|
18
|
-
require "graphql/static_validation/default_visitor"
|
19
17
|
require "graphql/static_validation/interpreter_visitor"
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
module GraphQL
|
3
3
|
class Subscriptions
|
4
|
-
class DefaultSubscriptionResolveExtension < GraphQL::
|
4
|
+
class DefaultSubscriptionResolveExtension < GraphQL::Schema::FieldExtension
|
5
5
|
def resolve(context:, object:, arguments:)
|
6
6
|
has_override_implementation = @field.resolver ||
|
7
7
|
object.respond_to?(@field.resolver_method)
|
@@ -16,6 +16,43 @@ module GraphQL
|
|
16
16
|
yield(object, arguments)
|
17
17
|
end
|
18
18
|
end
|
19
|
+
|
20
|
+
def after_resolve(value:, context:, object:, arguments:, **rest)
|
21
|
+
if value.is_a?(GraphQL::ExecutionError)
|
22
|
+
value
|
23
|
+
elsif (events = context.namespace(:subscriptions)[:events])
|
24
|
+
# This is the first execution, so gather an Event
|
25
|
+
# for the backend to register:
|
26
|
+
event = Subscriptions::Event.new(
|
27
|
+
name: field.name,
|
28
|
+
arguments: arguments_without_field_extras(arguments: arguments),
|
29
|
+
context: context,
|
30
|
+
field: field,
|
31
|
+
)
|
32
|
+
events << event
|
33
|
+
value
|
34
|
+
elsif context.query.subscription_topic == Subscriptions::Event.serialize(
|
35
|
+
field.name,
|
36
|
+
arguments_without_field_extras(arguments: arguments),
|
37
|
+
field,
|
38
|
+
scope: (field.subscription_scope ? context[field.subscription_scope] : nil),
|
39
|
+
)
|
40
|
+
# This is a subscription update. The resolver returned `skip` if it should be skipped,
|
41
|
+
# or else it returned an object to resolve the update.
|
42
|
+
value
|
43
|
+
else
|
44
|
+
# This is a subscription update, but this event wasn't triggered.
|
45
|
+
context.skip
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def arguments_without_field_extras(arguments:)
|
52
|
+
arguments.dup.tap do |event_args|
|
53
|
+
field.extras.each { |k| event_args.delete(k) }
|
54
|
+
end
|
55
|
+
end
|
19
56
|
end
|
20
57
|
end
|
21
58
|
end
|
@@ -9,7 +9,7 @@ module GraphQL
|
|
9
9
|
# @return [String] Corresponds to the Subscription root field name
|
10
10
|
attr_reader :name
|
11
11
|
|
12
|
-
# @return [GraphQL::
|
12
|
+
# @return [GraphQL::Execution::Interpreter::Arguments]
|
13
13
|
attr_reader :arguments
|
14
14
|
|
15
15
|
# @return [GraphQL::Query::Context]
|
@@ -9,16 +9,6 @@ module GraphQL
|
|
9
9
|
@schema = schema
|
10
10
|
end
|
11
11
|
|
12
|
-
def instrument(type, field)
|
13
|
-
if type == @schema.subscription.graphql_definition
|
14
|
-
# This is a root field of `subscription`
|
15
|
-
subscribing_resolve_proc = SubscriptionRegistrationResolve.new(field.resolve_proc)
|
16
|
-
field.redefine(resolve: subscribing_resolve_proc)
|
17
|
-
else
|
18
|
-
field
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
12
|
# If needed, prepare to gather events which this query subscribes to
|
23
13
|
def before_query(query)
|
24
14
|
if query.subscription? && !query.subscription_update?
|
@@ -33,47 +23,6 @@ module GraphQL
|
|
33
23
|
@schema.subscriptions.write_subscription(query, events)
|
34
24
|
end
|
35
25
|
end
|
36
|
-
|
37
|
-
private
|
38
|
-
|
39
|
-
class SubscriptionRegistrationResolve
|
40
|
-
def initialize(inner_proc)
|
41
|
-
@inner_proc = inner_proc
|
42
|
-
end
|
43
|
-
|
44
|
-
# Wrap the proc with subscription registration logic
|
45
|
-
def call(obj, args, ctx)
|
46
|
-
result = nil
|
47
|
-
if @inner_proc && !@inner_proc.is_a?(GraphQL::Field::Resolve::BuiltInResolve)
|
48
|
-
result = @inner_proc.call(obj, args, ctx)
|
49
|
-
end
|
50
|
-
|
51
|
-
events = ctx.namespace(:subscriptions)[:events]
|
52
|
-
|
53
|
-
if events
|
54
|
-
# This is the first execution, so gather an Event
|
55
|
-
# for the backend to register:
|
56
|
-
events << Subscriptions::Event.new(
|
57
|
-
name: ctx.field.name,
|
58
|
-
arguments: args,
|
59
|
-
context: ctx,
|
60
|
-
)
|
61
|
-
result
|
62
|
-
elsif ctx.irep_node.subscription_topic == ctx.query.subscription_topic
|
63
|
-
if !result.nil?
|
64
|
-
result
|
65
|
-
elsif obj.is_a?(GraphQL::Schema::Object)
|
66
|
-
# The root object is _already_ the subscription update:
|
67
|
-
obj.object
|
68
|
-
else
|
69
|
-
obj
|
70
|
-
end
|
71
|
-
else
|
72
|
-
# This is a subscription update, but this event wasn't triggered.
|
73
|
-
ctx.skip
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
26
|
end
|
78
27
|
end
|
79
28
|
end
|
@@ -5,7 +5,6 @@ require "graphql/subscriptions/event"
|
|
5
5
|
require "graphql/subscriptions/instrumentation"
|
6
6
|
require "graphql/subscriptions/serialize"
|
7
7
|
require "graphql/subscriptions/action_cable_subscriptions"
|
8
|
-
require "graphql/subscriptions/subscription_root"
|
9
8
|
require "graphql/subscriptions/default_subscription_resolve_extension"
|
10
9
|
|
11
10
|
module GraphQL
|
@@ -33,9 +32,6 @@ module GraphQL
|
|
33
32
|
|
34
33
|
instrumentation = Subscriptions::Instrumentation.new(schema: schema)
|
35
34
|
defn.instrument(:query, instrumentation)
|
36
|
-
if !schema.is_a?(Class)
|
37
|
-
defn.instrument(:field, instrumentation)
|
38
|
-
end
|
39
35
|
options[:schema] = schema
|
40
36
|
schema.subscriptions = self.new(**options)
|
41
37
|
schema.add_subscription_extension_if_necessary
|
@@ -45,9 +41,6 @@ module GraphQL
|
|
45
41
|
# @param schema [Class] the GraphQL schema this manager belongs to
|
46
42
|
def initialize(schema:, broadcast: false, default_broadcastable: false, **rest)
|
47
43
|
if broadcast
|
48
|
-
if !schema.using_ast_analysis?
|
49
|
-
raise ArgumentError, "`broadcast: true` requires AST analysis, add `using GraphQL::Analysis::AST` to your schema or see https://graphql-ruby.org/queries/ast_analysis.html."
|
50
|
-
end
|
51
44
|
schema.query_analyzer(Subscriptions::BroadcastAnalyzer)
|
52
45
|
end
|
53
46
|
@default_broadcastable = default_broadcastable
|
@@ -233,7 +226,7 @@ module GraphQL
|
|
233
226
|
# @return [Any] normalized arguments value
|
234
227
|
def normalize_arguments(event_name, arg_owner, args, context)
|
235
228
|
case arg_owner
|
236
|
-
when GraphQL::
|
229
|
+
when GraphQL::Schema::Field, Class
|
237
230
|
if arg_owner.is_a?(Class) && !arg_owner.kind.input_object?
|
238
231
|
# it's a type, but not an input object
|
239
232
|
return args
|
@@ -274,9 +267,7 @@ module GraphQL
|
|
274
267
|
end
|
275
268
|
|
276
269
|
if missing_arg_names.any?
|
277
|
-
arg_owner_name = if arg_owner.is_a?(GraphQL::Field)
|
278
|
-
"Subscription.#{arg_owner.name}"
|
279
|
-
elsif arg_owner.is_a?(GraphQL::Schema::Field)
|
270
|
+
arg_owner_name = if arg_owner.is_a?(GraphQL::Schema::Field)
|
280
271
|
arg_owner.path
|
281
272
|
elsif arg_owner.is_a?(Class)
|
282
273
|
arg_owner.graphql_name
|
@@ -287,9 +278,9 @@ module GraphQL
|
|
287
278
|
end
|
288
279
|
|
289
280
|
normalized_args
|
290
|
-
when GraphQL::
|
281
|
+
when GraphQL::Schema::List
|
291
282
|
args.map { |a| normalize_arguments(event_name, arg_owner.of_type, a, context) }
|
292
|
-
when GraphQL::
|
283
|
+
when GraphQL::Schema::NonNull
|
293
284
|
normalize_arguments(event_name, arg_owner.of_type, args, context)
|
294
285
|
else
|
295
286
|
args
|
@@ -15,23 +15,22 @@ module GraphQL
|
|
15
15
|
}
|
16
16
|
|
17
17
|
def platform_trace(platform_key, key, data)
|
18
|
-
tracer.trace(platform_key, service:
|
19
|
-
span.
|
20
|
-
span.set_tag('operation', key)
|
18
|
+
tracer.trace(platform_key, service: service_name) do |span|
|
19
|
+
span.span_type = 'custom'
|
21
20
|
|
22
21
|
if key == 'execute_multiplex'
|
23
22
|
operations = data[:multiplex].queries.map(&:selected_operation_name).join(', ')
|
24
|
-
|
25
|
-
resource = if operations.empty?
|
23
|
+
span.resource = if operations.empty?
|
26
24
|
first_query = data[:multiplex].queries.first
|
27
25
|
fallback_transaction_name(first_query && first_query.context)
|
28
26
|
else
|
29
27
|
operations
|
30
28
|
end
|
31
|
-
span.resource = resource if resource
|
32
29
|
|
33
|
-
#
|
34
|
-
|
30
|
+
# For top span of query, set the analytics sample rate tag, if available.
|
31
|
+
if analytics_enabled?
|
32
|
+
Datadog::Contrib::Analytics.set_sample_rate(span, analytics_sample_rate)
|
33
|
+
end
|
35
34
|
end
|
36
35
|
|
37
36
|
if key == 'execute_query'
|
@@ -40,29 +39,26 @@ module GraphQL
|
|
40
39
|
span.set_tag(:query_string, data[:query].query_string)
|
41
40
|
end
|
42
41
|
|
43
|
-
prepare_span(key, data, span)
|
44
|
-
|
45
42
|
yield
|
46
43
|
end
|
47
44
|
end
|
48
45
|
|
49
|
-
|
50
|
-
|
51
|
-
# @param data [Hash] The runtime data for this event (@see GraphQL::Tracing for keys for each event)
|
52
|
-
# @param span [Datadog::Tracing::SpanOperation] The datadog span for this event
|
53
|
-
def prepare_span(key, data, span)
|
46
|
+
def service_name
|
47
|
+
options.fetch(:service, 'ruby-graphql')
|
54
48
|
end
|
55
49
|
|
56
50
|
def tracer
|
57
|
-
|
51
|
+
options.fetch(:tracer, Datadog.tracer)
|
52
|
+
end
|
58
53
|
|
59
|
-
|
60
|
-
|
54
|
+
def analytics_available?
|
55
|
+
defined?(Datadog::Contrib::Analytics) \
|
56
|
+
&& Datadog::Contrib::Analytics.respond_to?(:enabled?) \
|
57
|
+
&& Datadog::Contrib::Analytics.respond_to?(:set_sample_rate)
|
61
58
|
end
|
62
59
|
|
63
60
|
def analytics_enabled?
|
64
|
-
|
65
|
-
options.fetch(:analytics_enabled, false)
|
61
|
+
analytics_available? && Datadog::Contrib::Analytics.enabled?(options.fetch(:analytics_enabled, false))
|
66
62
|
end
|
67
63
|
|
68
64
|
def analytics_sample_rate
|
@@ -10,10 +10,6 @@ module GraphQL
|
|
10
10
|
class PlatformTracing
|
11
11
|
class << self
|
12
12
|
attr_accessor :platform_keys
|
13
|
-
|
14
|
-
def inherited(child_class)
|
15
|
-
child_class.platform_keys = self.platform_keys
|
16
|
-
end
|
17
13
|
end
|
18
14
|
|
19
15
|
def initialize(options = {})
|
@@ -36,7 +32,6 @@ module GraphQL
|
|
36
32
|
trace_field = true # implemented with instrumenter
|
37
33
|
else
|
38
34
|
field = data[:field]
|
39
|
-
# HERE
|
40
35
|
return_type = field.type.unwrap
|
41
36
|
trace_field = if return_type.kind.scalar? || return_type.kind.enum?
|
42
37
|
(field.trace.nil? && @trace_scalars) || field.trace
|
@@ -46,7 +41,7 @@ module GraphQL
|
|
46
41
|
|
47
42
|
platform_key = if trace_field
|
48
43
|
context = data.fetch(:query).context
|
49
|
-
cached_platform_key(context, field
|
44
|
+
cached_platform_key(context, field) { platform_field_key(data[:owner], field) }
|
50
45
|
else
|
51
46
|
nil
|
52
47
|
end
|
@@ -62,14 +57,14 @@ module GraphQL
|
|
62
57
|
when "authorized", "authorized_lazy"
|
63
58
|
type = data.fetch(:type)
|
64
59
|
context = data.fetch(:context)
|
65
|
-
platform_key = cached_platform_key(context, type
|
60
|
+
platform_key = cached_platform_key(context, type) { platform_authorized_key(type) }
|
66
61
|
platform_trace(platform_key, key, data) do
|
67
62
|
yield
|
68
63
|
end
|
69
64
|
when "resolve_type", "resolve_type_lazy"
|
70
65
|
type = data.fetch(:type)
|
71
66
|
context = data.fetch(:context)
|
72
|
-
platform_key = cached_platform_key(context, type
|
67
|
+
platform_key = cached_platform_key(context, type) { platform_resolve_type_key(type) }
|
73
68
|
platform_trace(platform_key, key, data) do
|
74
69
|
yield
|
75
70
|
end
|
@@ -79,31 +74,8 @@ module GraphQL
|
|
79
74
|
end
|
80
75
|
end
|
81
76
|
|
82
|
-
def instrument(type, field)
|
83
|
-
return_type = field.type.unwrap
|
84
|
-
case return_type
|
85
|
-
when GraphQL::ScalarType, GraphQL::EnumType
|
86
|
-
if field.trace || (field.trace.nil? && @trace_scalars)
|
87
|
-
trace_field(type, field)
|
88
|
-
else
|
89
|
-
field
|
90
|
-
end
|
91
|
-
else
|
92
|
-
trace_field(type, field)
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
def trace_field(type, field)
|
97
|
-
new_f = field.redefine
|
98
|
-
new_f.metadata[:platform_key] = platform_field_key(type, field)
|
99
|
-
new_f
|
100
|
-
end
|
101
|
-
|
102
77
|
def self.use(schema_defn, options = {})
|
103
78
|
tracer = self.new(**options)
|
104
|
-
if !schema_defn.is_a?(Class)
|
105
|
-
schema_defn.instrument(:field, tracer)
|
106
|
-
end
|
107
79
|
schema_defn.tracer(tracer)
|
108
80
|
end
|
109
81
|
|
@@ -140,7 +112,7 @@ module GraphQL
|
|
140
112
|
# If the key isn't present, the given block is called and the result is cached for `key`.
|
141
113
|
#
|
142
114
|
# @return [String]
|
143
|
-
def cached_platform_key(ctx, key
|
115
|
+
def cached_platform_key(ctx, key)
|
144
116
|
cache = ctx.namespace(self.class)[:platform_key_cache] ||= {}
|
145
117
|
cache.fetch(key) { cache[key] = yield }
|
146
118
|
end
|
data/lib/graphql/tracing.rb
CHANGED
@@ -6,7 +6,6 @@ require "graphql/tracing/appsignal_tracing"
|
|
6
6
|
require "graphql/tracing/data_dog_tracing"
|
7
7
|
require "graphql/tracing/new_relic_tracing"
|
8
8
|
require "graphql/tracing/scout_tracing"
|
9
|
-
require "graphql/tracing/skylight_tracing"
|
10
9
|
require "graphql/tracing/statsd_tracing"
|
11
10
|
require "graphql/tracing/prometheus_tracing"
|
12
11
|
|
@@ -36,7 +36,7 @@ module GraphQL
|
|
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::
|
39
|
+
def edge_type(edge_type_class, edge_class: GraphQL::Pagination::Connection::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)
|
40
40
|
# Set this connection's graphql name
|
41
41
|
node_type_name = node_type.graphql_name
|
42
42
|
|
@@ -49,7 +49,6 @@ module GraphQL
|
|
49
49
|
type: [edge_type_class, null: edge_nullable],
|
50
50
|
null: edges_nullable,
|
51
51
|
description: "A list of edges.",
|
52
|
-
legacy_edge_class: edge_class, # This is used by the old runtime only, for EdgesInstrumentation
|
53
52
|
connection: false,
|
54
53
|
}
|
55
54
|
|
@@ -159,13 +158,10 @@ module GraphQL
|
|
159
158
|
def edges
|
160
159
|
if @object.is_a?(GraphQL::Pagination::Connection)
|
161
160
|
@object.edges
|
162
|
-
|
161
|
+
else
|
163
162
|
context.schema.after_lazy(object.edge_nodes) do |nodes|
|
164
163
|
nodes.map { |n| self.class.edge_class.new(n, object) }
|
165
164
|
end
|
166
|
-
else
|
167
|
-
# This is done by edges_instrumentation
|
168
|
-
@object.edge_nodes
|
169
165
|
end
|
170
166
|
end
|
171
167
|
end
|
@@ -15,16 +15,6 @@ module GraphQL
|
|
15
15
|
def default_relay?
|
16
16
|
!!@default_relay
|
17
17
|
end
|
18
|
-
|
19
|
-
def to_graphql
|
20
|
-
type_defn = if method(:to_graphql).super_method.arity
|
21
|
-
super(silence_deprecation_warning: true)
|
22
|
-
else
|
23
|
-
super
|
24
|
-
end
|
25
|
-
type_defn.default_relay = default_relay?
|
26
|
-
type_defn
|
27
|
-
end
|
28
18
|
end
|
29
19
|
end
|
30
20
|
end
|
@@ -7,7 +7,11 @@ module GraphQL
|
|
7
7
|
def self.included(child_module)
|
8
8
|
child_module.extend(DefaultRelay)
|
9
9
|
child_module.description("An object with an ID.")
|
10
|
-
child_module.field(:id, ID, null: false, description: "ID of the object.")
|
10
|
+
child_module.field(:id, ID, null: false, description: "ID of the object.", resolver_method: :default_global_id)
|
11
|
+
end
|
12
|
+
|
13
|
+
def default_global_id
|
14
|
+
context.schema.id_from_object(object, self, context)
|
11
15
|
end
|
12
16
|
end
|
13
17
|
end
|
data/lib/graphql/types/relay.rb
CHANGED
@@ -14,8 +14,6 @@ require "graphql/types/relay/page_info"
|
|
14
14
|
require "graphql/types/relay/base_connection"
|
15
15
|
require "graphql/types/relay/base_edge"
|
16
16
|
require "graphql/types/relay/node"
|
17
|
-
require "graphql/types/relay/node_field"
|
18
|
-
require "graphql/types/relay/nodes_field"
|
19
17
|
|
20
18
|
module GraphQL
|
21
19
|
module Types
|
data/lib/graphql/types/string.rb
CHANGED
data/lib/graphql/version.rb
CHANGED