class GraphQL::Schema::EnumValue

A possible value for an {Enum}.

You can extend this class to customize enum values in your schema.

@example custom enum value class

# define a custom class:
class CustomEnumValue < GraphQL::Schema::EnumValue
  def initialize(*args)
    # arguments to `value(...)` in Enum classes are passed here
    super
  end

  def to_graphql
    enum_value = super
    # customize the derived GraphQL::EnumValue here
    enum_value
  end
end

class BaseEnum < GraphQL::Schema::Enum
  # use it for these enums:
  enum_value_class CustomEnumValue
end

Attributes

deprecation_reason[RW]

@return [String] Explains why this value was deprecated (if present, this will be marked deprecated in introspection)

graphql_name[R]
owner[R]

@return [Class] The enum type that owns this value

Public Class Methods

new(graphql_name, desc = nil, owner:, description: nil, value: nil, deprecation_reason: nil, &block) click to toggle source
# File lib/graphql/schema/enum_value.rb, line 40
def initialize(graphql_name, desc = nil, owner:, description: nil, value: nil, deprecation_reason: nil, &block)
  @graphql_name = graphql_name.to_s
  @description = desc || description
  @value = value || @graphql_name
  @deprecation_reason = deprecation_reason
  @owner = owner

  if block_given?
    instance_eval(&block)
  end
end

Public Instance Methods

accessible?(_ctx) click to toggle source
# File lib/graphql/schema/enum_value.rb, line 78
def accessible?(_ctx); true; end
authorized?(_ctx) click to toggle source
# File lib/graphql/schema/enum_value.rb, line 79
def authorized?(_ctx); true; end
description(new_desc = nil) click to toggle source
# File lib/graphql/schema/enum_value.rb, line 52
def description(new_desc = nil)
  if new_desc
    @description = new_desc
  end
  @description
end
to_graphql() click to toggle source

@return [GraphQL::EnumType::EnumValue] A runtime-ready object derived from this object

# File lib/graphql/schema/enum_value.rb, line 67
def to_graphql
  enum_value = GraphQL::EnumType::EnumValue.new
  enum_value.name = @graphql_name
  enum_value.description = @description
  enum_value.value = @value
  enum_value.deprecation_reason = @deprecation_reason
  enum_value.metadata[:type_class] = self
  enum_value
end
value(new_val = nil) click to toggle source
# File lib/graphql/schema/enum_value.rb, line 59
def value(new_val = nil)
  if new_val
    @value = new_val
  end
  @value
end
visible?(_ctx) click to toggle source
# File lib/graphql/schema/enum_value.rb, line 77
def visible?(_ctx); true; end