Method: GraphQL::Schema::Enum.coerce_input
- Defined in:
- lib/graphql/schema/enum.rb
.coerce_input(value_name, ctx) ⇒ Object
Called by the runtime with incoming string representations from a query. It will match the string to a configured by name or by Ruby value.
216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/graphql/schema/enum.rb', line 216 def coerce_input(value_name, ctx) all_values = ctx.types ? ctx.types.enum_values(self) : values.each_value # This tries matching by incoming GraphQL string, then checks Ruby-defined values if v = (all_values.find { |val| val.graphql_name == value_name } || all_values.find { |val| val.value == value_name }) if v.(ctx) v.value else raise GraphQL::.new(type: self, enum_value: v, context: ctx) end else nil end end |