blob: ee5c0c8737b0184b0567e96b3654a94ec0200f6f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
|