18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/elastic_graph/graphql/scalar_coercion_adapters/time_zone.rb', line 18
def self.coerce_input(value, ctx)
return value if value.nil? || VALID_TIME_ZONES.include?(value)
suggestions = SUGGESTER.correct(value).map(&:inspect)
suggestion_sentence =
if suggestions.size >= 3
*initial, final = suggestions
" Possible alternatives: #{initial.join(", ")}, or #{final}."
elsif suggestions.size == 1
" Possible alternative: #{suggestions.first}."
elsif suggestions.size > 0
" Possible alternatives: #{suggestions.join(" or ")}."
end
raise ::GraphQL::CoercionError,
"Could not coerce value #{value.inspect} to TimeZone: must be a valid IANA time zone identifier " \
"(such as `America/Los_Angeles` or `UTC`).#{suggestion_sentence}"
end
|