Method: GraphQL::Schema::Enum.coerce_result
- Defined in:
- lib/graphql/schema/enum.rb
.coerce_result(value, ctx) ⇒ String
Called by the runtime when a field returns a value to give back to the client. This method checks that the incoming value matches one of the enum's defined values.
199 200 201 202 203 204 205 206 207 208 |
# File 'lib/graphql/schema/enum.rb', line 199 def coerce_result(value, ctx) types = ctx.types all_values = types ? types.enum_values(self) : values.each_value enum_value = all_values.find { |val| val.value == value } if enum_value && (was_authed = enum_value.(ctx)) enum_value.graphql_name else raise self::UnresolvedValueError.new(enum: self, value: value, context: ctx, authorized: was_authed) end end |