Overview
Enum types, like scalar types, represent leaf values in a GraphQL type system. However, enums describe a specific set of possible values. Inherits from:Rails::GraphQL::Type
Specification: GraphQL Enum Type Definition
Class Attributes
Collection of enum value names (uppercase)
Descriptions for each enum value
Directives applied to each enum value
Class Methods
add(value, desc: nil, description: nil, directives: nil, deprecated: false)
Add a value to the enum type.
The enum value name (will be converted to uppercase)
Description of the enum value
Alias for
descList of directives to apply to this value
Mark value as deprecated. Use
true for default message, or provide a string for custom reasonindexed!
Mark the enum as indexed, allowing values to be set by numeric index.
indexed?
Check if the enum is marked as indexed.
Returns
true if enum supports numeric indexingvalid_input?(value)
Check if a value is valid enum input (before deserialization).
The value to validate
Returns
true if the value is a valid enum inputvalid_output?(value)
Check if a value is valid enum output (before serialization).
The value to validate
Returns
true if the value can be serialized as this enumdeserialize(value)
Turn user input into an enum instance.
The input value to deserialize
Returns an enum instance, or
nil if invalidas_json(value)
Transform a value to its JSON representation.
The value to serialize
The enum value as a string (uppercase)
to_json(value)
Transform a value to its JSON string representation.
The value to serialize
The enum value as a quoted string
decorate(value)
Wrap a value in an enum instance.
The value to decorate
An enum instance wrapping the value
value_using?(value, directive)
Check if a specific enum value uses a directive.
The enum value to check
The directive class to check for
Returns
true if the value has the directiveall_deprecated_values
Get a hash of deprecated values and their reasons.
Hash mapping deprecated values to their deprecation reasons
Instance Methods
initialize(value)
Create a new enum instance.
The enum value
to_s
Return the enum value as a string.
to_sym
Return the enum value as a lowercase symbol.
to_i
Return the indexed position of the value.
valid?
Check if the current value is valid.
Returns
true if the value is valid for this enumdescription
Get the description for the current value.
The value’s description
directives
Get directives applied to the current value.
List of directives for this value
deprecated?
Check if the current value is deprecated.
Returns
true if the value has a @deprecated directivedeprecated_reason
Get the deprecation reason for the current value.
The deprecation reason, if any