Exception: GraphQL::Schema::Enum::UnresolvedValueError

Inherits:
Error
  • Object
show all
Defined in:
lib/graphql/schema/enum.rb

Overview

This is raised when either:

  • A resolver returns a value which doesn’t match any of the enum’s configured values;
  • Or, the resolver returns a value which matches a value, but that value’s authorized? check returns false.

In either case, the field should be modified so that the invalid value isn’t returned.

GraphQL::Schema::Enum subclasses get their own subclass of this error, so that bug trackers can better show where they came from.

Instance Method Summary collapse

Constructor Details

#initialize(value:, enum:, context:, authorized:) ⇒ UnresolvedValueError

Returns a new instance of UnresolvedValueError.



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/graphql/schema/enum.rb', line 34

def initialize(value:, enum:, context:, authorized:)
  fix_message = if authorized == false
    ", but this value was unauthorized. Update the field or resolver to return a different value in this case (or return `nil`)."
  else
    ", but this isn't a valid value for `#{enum.graphql_name}`. Update the field or resolver to return one of `#{enum.graphql_name}`'s values instead."
  end
  message = if (cp = context[:current_path]) && (cf = context[:current_field])
    "`#{cf.path}` returned `#{value.inspect}` at `#{cp.join(".")}`#{fix_message}"
  else
    "`#{value.inspect}` was returned for `#{enum.graphql_name}`#{fix_message}"
  end
  super(message)
end