diff options
Diffstat (limited to 'app/graphql/types/concerns/gitlab_style_deprecations.rb')
-rw-r--r-- | app/graphql/types/concerns/gitlab_style_deprecations.rb | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/app/graphql/types/concerns/gitlab_style_deprecations.rb b/app/graphql/types/concerns/gitlab_style_deprecations.rb index e404f1fcad9..859a27cac4c 100644 --- a/app/graphql/types/concerns/gitlab_style_deprecations.rb +++ b/app/graphql/types/concerns/gitlab_style_deprecations.rb @@ -1,14 +1,22 @@ # frozen_string_literal: true -# Concern for handling deprecation arguments. +# Concern for handling GraphQL deprecations. # https://docs.gitlab.com/ee/development/api_graphql_styleguide.html#deprecating-schema-items module GitlabStyleDeprecations extend ActiveSupport::Concern + included do + attr_accessor :deprecation + end + + def visible?(ctx) + super && ctx[:remove_deprecated] == true ? deprecation.nil? : true + end + private - # Mutate the arguments, returns the deprecation - def gitlab_deprecation(kwargs) + # Set deprecation, mutate the arguments + def init_gitlab_deprecation(kwargs) if kwargs[:deprecation_reason].present? raise ArgumentError, 'Use `deprecated` property instead of `deprecation_reason`. ' \ 'See https://docs.gitlab.com/ee/development/api_graphql_styleguide.html#deprecating-schema-items' @@ -17,14 +25,12 @@ module GitlabStyleDeprecations # GitLab allows items to be marked as "alpha", which leverages GraphQL deprecations. deprecation_args = kwargs.extract!(:alpha, :deprecated) - deprecation = ::Gitlab::Graphql::Deprecation.parse(**deprecation_args) + self.deprecation = ::Gitlab::Graphql::Deprecation.parse(**deprecation_args) return unless deprecation raise ArgumentError, "Bad deprecation. #{deprecation.errors.full_messages.to_sentence}" unless deprecation.valid? kwargs[:deprecation_reason] = deprecation.deprecation_reason kwargs[:description] = deprecation.edit_description(kwargs[:description]) - - deprecation end end |