Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-07-28 21:09:03 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-07-28 21:09:03 +0300
commitb420660ef1369fec4d09b7bf5e961d81980974e5 (patch)
treef096fdd1bd3b4898e1b2ca80957ce68c200c09f0 /lib/gitlab/graphql
parentb8026fd558e7ec154c626208a33c1485aec8f4ea (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/graphql')
-rw-r--r--lib/gitlab/graphql/deprecations_base.rb48
-rw-r--r--lib/gitlab/graphql/type_name_deprecations.rb23
2 files changed, 71 insertions, 0 deletions
diff --git a/lib/gitlab/graphql/deprecations_base.rb b/lib/gitlab/graphql/deprecations_base.rb
new file mode 100644
index 00000000000..2ee14620907
--- /dev/null
+++ b/lib/gitlab/graphql/deprecations_base.rb
@@ -0,0 +1,48 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Graphql
+ # include DeprecationsBase at the end of the target module
+ module DeprecationsBase
+ NameDeprecation = Struct.new(:old_name, :new_name, :milestone, keyword_init: true)
+
+ def self.included(klass)
+ klass.extend(ClassMethods)
+
+ klass.const_set('OLD_GRAPHQL_NAME_MAP', klass::DEPRECATIONS.index_by do |d|
+ klass.map_graphql_name(d.old_name)
+ end.freeze)
+ klass.const_set('OLD_NAME_MAP', klass::DEPRECATIONS.index_by(&:old_name).freeze)
+ klass.const_set('NEW_NAME_MAP', klass::DEPRECATIONS.index_by(&:new_name).freeze)
+ end
+
+ module ClassMethods
+ def deprecated?(old_name)
+ self::OLD_NAME_MAP.key?(old_name)
+ end
+
+ def deprecation_for(old_name)
+ self::OLD_NAME_MAP[old_name]
+ end
+
+ def deprecation_by(new_name)
+ self::NEW_NAME_MAP[new_name]
+ end
+
+ # Returns the new `graphql_name` (Type#graphql_name) of a deprecated GID,
+ # or the `graphql_name` argument given if no deprecation applies.
+ def apply_to_graphql_name(graphql_name)
+ return graphql_name unless deprecation = self::OLD_GRAPHQL_NAME_MAP[graphql_name]
+
+ self.map_graphql_name(deprecation.new_name)
+ end
+
+ private
+
+ def map_graphql_name(name)
+ raise NotImplementedError, "Implement `#{__method__}` in #{self.name}"
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/graphql/type_name_deprecations.rb b/lib/gitlab/graphql/type_name_deprecations.rb
new file mode 100644
index 00000000000..4c75a0e7bd3
--- /dev/null
+++ b/lib/gitlab/graphql/type_name_deprecations.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Graphql
+ module TypeNameDeprecations
+ # Contains the deprecations in place.
+ # Example:
+ #
+ # DEPRECATIONS = [
+ # Gitlab::Graphql::DeprecationsBase::NameDeprecation.new(
+ # old_name: 'CiRunnerUpgradeStatusType', new_name: 'CiRunnerUpgradeStatus', milestone: '15.3'
+ # )
+ # ].freeze
+ DEPRECATIONS = [].freeze
+
+ def self.map_graphql_name(name)
+ name
+ end
+
+ include Gitlab::Graphql::DeprecationsBase
+ end
+ end
+end