Skip to content

Commit 682e94f

Browse files
committed
Fix unsetting deprecation_reason
1 parent 7848d85 commit 682e94f

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

lib/graphql/schema/member/has_deprecation_reason.rb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,16 @@ class Schema
55
class Member
66
module HasDeprecationReason
77
# @return [String, nil] Explains why this member was deprecated (if present, this will be marked deprecated in introspection)
8-
def deprecation_reason
9-
@deprecation_reason
10-
end
8+
attr_reader :deprecation_reason
119

1210
# Set the deprecation reason for this member, or remove it by assigning `nil`
1311
# @param text [String, nil]
1412
def deprecation_reason=(text)
13+
@deprecation_reason = text
1514
if text.nil?
1615
remove_directive(GraphQL::Schema::Directive::Deprecated)
1716
else
18-
if defined?(@deprecation_reason) && @deprecation_reason
19-
remove_directive(GraphQL::Schema::Directive::Deprecated)
20-
end
21-
@deprecation_reason = text
17+
# This removes a previously-attached directive, if there is one:
2218
directive(GraphQL::Schema::Directive::Deprecated, reason: text)
2319
end
2420
end

spec/graphql/schema/argument_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,13 @@ def self.object_from_id(id, ctx)
349349
it "has an assignment method" do
350350
arg.deprecation_reason = "another new deprecation reason"
351351
assert_equal "another new deprecation reason", arg.deprecation_reason
352+
assert_equal 1, arg.directives.size
353+
arg.deprecation_reason = "something else"
354+
assert_equal "something else", arg.deprecation_reason
355+
assert_equal 1, arg.directives.size
356+
arg.deprecation_reason = nil
357+
assert_nil arg.deprecation_reason
358+
assert_equal 0, arg.directives.size
352359
end
353360

354361
it "disallows deprecating required arguments in the constructor" do

0 commit comments

Comments
 (0)