Skip to content

Commit 718cd23

Browse files
authored
Merge pull request rmosolgo#4867 from rmosolgo/deprecate-execution-strategy
Deprecate execution strategy methods
2 parents f41bad4 + 7731022 commit 718cd23

File tree

3 files changed

+19
-26
lines changed

3 files changed

+19
-26
lines changed

lib/graphql/execution/interpreter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def run_all(schema, query_options, context: {}, max_complexity: schema.max_compl
4747
begin
4848
# Since this is basically the batching context,
4949
# share it for a whole multiplex
50-
multiplex.context[:interpreter_instance] ||= multiplex.schema.query_execution_strategy.new
50+
multiplex.context[:interpreter_instance] ||= multiplex.schema.query_execution_strategy(deprecation_warning: false).new
5151
# Do as much eager evaluation of the query as possible
5252
results = []
5353
queries.each_with_index do |query, idx|

lib/graphql/schema.rb

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,6 @@ module GraphQL
6363
# Schemas can restrict large incoming queries with `max_depth` and `max_complexity` configurations.
6464
# (These configurations can be overridden by specific calls to {Schema#execute})
6565
#
66-
# Schemas can specify how queries should be executed against them.
67-
# `query_execution_strategy`, `mutation_execution_strategy` and `subscription_execution_strategy`
68-
# each apply to corresponding root types.
69-
#
7066
# @example defining a schema
7167
# class MySchema < GraphQL::Schema
7268
# query QueryType
@@ -651,27 +647,39 @@ def default_page_size(new_default_page_size = nil)
651647
end
652648
end
653649

654-
def query_execution_strategy(new_query_execution_strategy = nil)
650+
def query_execution_strategy(new_query_execution_strategy = nil, deprecation_warning: true)
651+
if deprecation_warning
652+
warn "GraphQL::Schema.query_execution_strategy is deprecated without replacement. Use `GraphQL::Query.new` directly to create and execute a custom query instead."
653+
warn " #{caller(1, 1).first}"
654+
end
655655
if new_query_execution_strategy
656656
@query_execution_strategy = new_query_execution_strategy
657657
else
658-
@query_execution_strategy || find_inherited_value(:query_execution_strategy, self.default_execution_strategy)
658+
@query_execution_strategy || (superclass.respond_to?(:query_execution_strategy) ? superclass.query_execution_strategy(deprecation_warning: false) : self.default_execution_strategy)
659659
end
660660
end
661661

662-
def mutation_execution_strategy(new_mutation_execution_strategy = nil)
662+
def mutation_execution_strategy(new_mutation_execution_strategy = nil, deprecation_warning: true)
663+
if deprecation_warning
664+
warn "GraphQL::Schema.mutation_execution_strategy is deprecated without replacement. Use `GraphQL::Query.new` directly to create and execute a custom query instead."
665+
warn " #{caller(1, 1).first}"
666+
end
663667
if new_mutation_execution_strategy
664668
@mutation_execution_strategy = new_mutation_execution_strategy
665669
else
666-
@mutation_execution_strategy || find_inherited_value(:mutation_execution_strategy, self.default_execution_strategy)
670+
@mutation_execution_strategy || (superclass.respond_to?(:mutation_execution_strategy) ? superclass.mutation_execution_strategy(deprecation_warning: false) : self.default_execution_strategy)
667671
end
668672
end
669673

670-
def subscription_execution_strategy(new_subscription_execution_strategy = nil)
674+
def subscription_execution_strategy(new_subscription_execution_strategy = nil, deprecation_warning: true)
675+
if deprecation_warning
676+
warn "GraphQL::Schema.subscription_execution_strategy is deprecated without replacement. Use `GraphQL::Query.new` directly to create and execute a custom query instead."
677+
warn " #{caller(1, 1).first}"
678+
end
671679
if new_subscription_execution_strategy
672680
@subscription_execution_strategy = new_subscription_execution_strategy
673681
else
674-
@subscription_execution_strategy || find_inherited_value(:subscription_execution_strategy, self.default_execution_strategy)
682+
@subscription_execution_strategy || (superclass.respond_to?(:subscription_execution_strategy) ? superclass.subscription_execution_strategy(deprecation_warning: false) : self.default_execution_strategy)
675683
end
676684
end
677685

spec/graphql/schema_spec.rb

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ class CustomSubscriptions < GraphQL::Subscriptions::ActionCableSubscriptions
4242
orphan_types Jazz::Ensemble
4343
introspection Module.new
4444
cursor_encoder Object.new
45-
query_execution_strategy Object.new
46-
mutation_execution_strategy Object.new
47-
subscription_execution_strategy Object.new
4845
context_class Class.new
4946
directives [DummyFeature1]
5047
tracer GraphQL::Tracing::DataDogTracing
@@ -64,9 +61,6 @@ class CustomSubscriptions < GraphQL::Subscriptions::ActionCableSubscriptions
6461
assert_equal base_schema.subscription, schema.subscription
6562
assert_equal base_schema.introspection, schema.introspection
6663
assert_equal base_schema.cursor_encoder, schema.cursor_encoder
67-
assert_equal base_schema.query_execution_strategy, schema.query_execution_strategy
68-
assert_equal base_schema.mutation_execution_strategy, schema.mutation_execution_strategy
69-
assert_equal base_schema.subscription_execution_strategy, schema.subscription_execution_strategy
7064
assert_equal base_schema.validate_timeout, schema.validate_timeout
7165
assert_equal base_schema.max_complexity, schema.max_complexity
7266
assert_equal base_schema.max_depth, schema.max_depth
@@ -114,15 +108,6 @@ class CustomSubscriptions < GraphQL::Subscriptions::ActionCableSubscriptions
114108
schema.introspection(introspection)
115109
cursor_encoder = Object.new
116110
schema.cursor_encoder(cursor_encoder)
117-
query_execution_strategy = Object.new
118-
schema.query_execution_strategy(query_execution_strategy)
119-
mutation_execution_strategy = Object.new
120-
schema.mutation_execution_strategy(mutation_execution_strategy)
121-
subscription_execution_strategy = Object.new
122-
schema.subscription_execution_strategy(subscription_execution_strategy)
123-
assert_equal query_execution_strategy, schema.query_execution_strategy
124-
assert_equal mutation_execution_strategy, schema.mutation_execution_strategy
125-
assert_equal subscription_execution_strategy, schema.subscription_execution_strategy
126111

127112
context_class = Class.new
128113
schema.context_class(context_class)

0 commit comments

Comments
 (0)