Skip to content

Commit 3d1c24a

Browse files
author
Robert Mosolgo
committed
Update code to silence warnings in tests
1 parent 1a25eb8 commit 3d1c24a

19 files changed

Lines changed: 78 additions & 65 deletions

lib/graphql/base_type.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ def initialize_copy(other)
4141
alias :graphql_name :name
4242
# Future-compatible alias
4343
# @see {GraphQL::SchemaMember}
44-
alias :graphql_definition :itself
44+
def graphql_definition(silence_deprecation_warning: false)
45+
itself
46+
end
4547

4648
def type_class
4749
metadata[:type_class]
@@ -194,7 +196,7 @@ def self.resolve_related_type(type_arg)
194196
resolve_related_type(Object.const_get(type_arg))
195197
else
196198
if type_arg.respond_to?(:graphql_definition)
197-
type_arg.graphql_definition
199+
type_arg.graphql_definition(silence_deprecation_warning: true)
198200
else
199201
type_arg
200202
end
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# frozen_string_literal: true
2-
GraphQL::Directive::DeprecatedDirective = GraphQL::Schema::Directive::Deprecated.graphql_definition
2+
GraphQL::Directive::DeprecatedDirective = GraphQL::Schema::Directive::Deprecated.graphql_definition(silence_deprecation_warning: true)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# frozen_string_literal: true
2-
GraphQL::Directive::IncludeDirective = GraphQL::Schema::Directive::Include.graphql_definition
2+
GraphQL::Directive::IncludeDirective = GraphQL::Schema::Directive::Include.graphql_definition(silence_deprecation_warning: true)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# frozen_string_literal: true
2-
GraphQL::Directive::SkipDirective = GraphQL::Schema::Directive::Skip.graphql_definition
2+
GraphQL::Directive::SkipDirective = GraphQL::Schema::Directive::Skip.graphql_definition(silence_deprecation_warning: true)

lib/graphql/relay/global_id_resolve.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def call(obj, args, ctx)
1010
if obj.is_a?(GraphQL::Schema::Object)
1111
obj = obj.object
1212
end
13-
type = @type.respond_to?(:graphql_definition) ? @type.graphql_definition : @type
13+
type = @type.respond_to?(:graphql_definition) ? @type.graphql_definition(silence_deprecation_warning: true) : @type
1414
ctx.query.schema.id_from_object(obj, type, ctx)
1515
end
1616
end

lib/graphql/schema.rb

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ class << self
845845
# - Cause the Schema instance to be created, if it hasn't been created yet
846846
# - Delegate to that instance
847847
# Eventually, the methods will be moved into this class, removing the need for the singleton.
848-
def_delegators :graphql_definition,
848+
def_delegators :deprecated_graphql_definition,
849849
# Execution
850850
:execution_strategy_for_operation,
851851
# Configuration
@@ -854,6 +854,10 @@ class << self
854854
:id_from_object=, :object_from_id=,
855855
:remove_handler
856856

857+
def deprecated_graphql_definition
858+
graphql_definition(silence_deprecation_warning: true)
859+
end
860+
857861
# @return [GraphQL::Subscriptions]
858862
attr_accessor :subscriptions
859863

@@ -896,8 +900,15 @@ def find(path)
896900
@find_cache[path] ||= @finder.find(path)
897901
end
898902

899-
def graphql_definition
900-
@graphql_definition ||= to_graphql
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
911+
end
901912
end
902913

903914
def default_filter
@@ -932,16 +943,16 @@ def plugins
932943
def to_graphql
933944
schema_defn = self.new
934945
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
946+
schema_defn.query = query && query.graphql_definition(silence_deprecation_warning: true)
947+
schema_defn.mutation = mutation && mutation.graphql_definition(silence_deprecation_warning: true)
948+
schema_defn.subscription = subscription && subscription.graphql_definition(silence_deprecation_warning: true)
938949
schema_defn.validate_timeout = validate_timeout
939950
schema_defn.validate_max_errors = validate_max_errors
940951
schema_defn.max_complexity = max_complexity
941952
schema_defn.error_bubbling = error_bubbling
942953
schema_defn.max_depth = max_depth
943954
schema_defn.default_max_page_size = default_max_page_size
944-
schema_defn.orphan_types = orphan_types.map(&:graphql_definition)
955+
schema_defn.orphan_types = orphan_types.map { |t| t.graphql_definition(silence_deprecation_warning: true) }
945956
schema_defn.disable_introspection_entry_points = disable_introspection_entry_points?
946957
schema_defn.disable_schema_introspection_entry_point = disable_schema_introspection_entry_point?
947958
schema_defn.disable_type_introspection_entry_point = disable_type_introspection_entry_point?

lib/graphql/schema/input_object.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def to_graphql
140140
type_defn.mutation = mutation
141141
type_defn.ast_node = ast_node
142142
all_argument_definitions.each do |arg|
143-
type_defn.arguments[arg.graphql_definition.name] = arg.graphql_definition # rubocop:disable Development/ContextIsPassedCop -- legacy-related
143+
type_defn.arguments[arg.graphql_definition(silence_deprecation_warning: true).name] = arg.graphql_definition(silence_deprecation_warning: true) # rubocop:disable Development/ContextIsPassedCop -- legacy-related
144144
end
145145
# Make a reference to a classic-style Arguments class
146146
self.arguments_class = GraphQL::Query::Arguments.construct_arguments_class(type_defn)

lib/graphql/schema/interface.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def to_graphql
108108
type_defn.type_membership_class = self.type_membership_class
109109
type_defn.ast_node = ast_node
110110
fields.each do |field_name, field_inst| # rubocop:disable Development/ContextIsPassedCop -- legacy-related
111-
field_defn = field_inst.graphql_definition
111+
field_defn = field_inst.graphql_definition(silence_deprecation_warning: true)
112112
type_defn.fields[field_defn.name] = field_defn # rubocop:disable Development/ContextIsPassedCop -- legacy-related
113113
end
114114
type_defn.metadata[:type_class] = self

lib/graphql/schema/list.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class List < GraphQL::Schema::Wrapper
99
include Schema::Member::ValidatesInput
1010

1111
def to_graphql
12-
@of_type.graphql_definition.to_list_type
12+
@of_type.graphql_definition(silence_deprecation_warning: true).to_list_type
1313
end
1414

1515
# @return [GraphQL::TypeKinds::LIST]

lib/graphql/schema/non_null.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class NonNull < GraphQL::Schema::Wrapper
99
include Schema::Member::ValidatesInput
1010

1111
def to_graphql
12-
@of_type.graphql_definition.to_non_null_type
12+
@of_type.graphql_definition(silence_deprecation_warning: true).to_non_null_type
1313
end
1414

1515
# @return [GraphQL::TypeKinds::NON_NULL]

0 commit comments

Comments
 (0)