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:
Diffstat (limited to 'app/graphql/types/color_type.rb')
-rw-r--r--app/graphql/types/color_type.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/app/graphql/types/color_type.rb b/app/graphql/types/color_type.rb
new file mode 100644
index 00000000000..ee5c0c8737b
--- /dev/null
+++ b/app/graphql/types/color_type.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+module Types
+ class ColorType < BaseScalar
+ graphql_name 'Color'
+ description <<~DESC
+ Color represented as a hex code or named color.
+
+ For example: "#fefefe".
+ DESC
+
+ def self.coerce_input(value, ctx)
+ color = Gitlab::Color.of(value)
+ raise GraphQL::CoercionError, 'Not a color' unless color.valid?
+
+ color
+ rescue ArgumentError => e
+ raise GraphQL::CoercionError, e.message
+ end
+
+ def self.coerce_result(value, ctx)
+ value.to_s
+ end
+ end
+end