Class: GraphQL::Schema::EnumValue
- Defined in:
- lib/graphql/schema/enum_value.rb
Overview
A possible value for an Enum.
You can extend this class to customize enum values in your schema.
Examples
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
end
class BaseEnum < GraphQL::Schema::Enum
# use it for these enums:
enum_value_class CustomEnumValue
end
Constant Summary
Constants included from Member::GraphQLTypeNames
Member::GraphQLTypeNames::Boolean, Member::GraphQLTypeNames::ID, Member::GraphQLTypeNames::Int
Instance Attribute Summary collapse
-
#graphql_name ⇒ Object
readonly
Returns the value of attribute graphql_name.
-
#owner ⇒ Object
readonly
Returns.
Attributes included from Member::HasDeprecationReason
Attributes included from Member::HasAstNode
Attributes included from Member::BaseDSLMethods
Attributes included from Member::RelayShortcuts
#connection_type, #connection_type_class, #edge_type, #edge_type_class
Instance Method Summary collapse
- #authorized?(_ctx) ⇒ Boolean
- #comment(new_comment = nil) ⇒ Object
- #description(new_desc = nil) ⇒ Object
-
#initialize(graphql_name, desc = nil, owner:, ast_node: nil, directives: nil, description: nil, comment: nil, value: NOT_CONFIGURED, deprecation_reason: nil, &block) ⇒ EnumValue
constructor
A new instance of EnumValue.
- #inspect ⇒ Object
- #value(new_val = nil) ⇒ Object
- #visible?(_ctx) ⇒ Boolean
Methods included from Member::HasDeprecationReason
Methods included from Member::HasDirectives
add_directive, #directive, #directives, extended, get_directives, #inherited, #remove_directive, remove_directive
Methods included from Member::HasAstNode
Methods included from Member::HasPath
Methods inherited from Member
Methods included from Member::BaseDSLMethods
#default_relay?, #introspection, #introspection?, #mutation
Methods included from FindInheritedValue
Methods included from Member::BaseDSLMethods::ConfigurationExtension
Methods included from Member::TypeSystemHelpers
#kind, #list?, #non_null?, #to_list_type, #to_non_null_type, #to_type_signature
Methods included from Member::Scoped
#inherited, #reauthorize_scoped_objects, #scope_items
Constructor Details
#initialize(graphql_name, desc = nil, owner:, ast_node: nil, directives: nil, description: nil, comment: nil, value: NOT_CONFIGURED, deprecation_reason: nil, &block) ⇒ EnumValue
Returns a new instance of EnumValue.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/graphql/schema/enum_value.rb', line 42 def initialize(graphql_name, desc = nil, owner:, ast_node: nil, directives: nil, description: nil, comment: nil, value: NOT_CONFIGURED, deprecation_reason: nil, &block) @graphql_name = graphql_name.to_s GraphQL::NameValidator.validate!(@graphql_name) @description = desc || description @comment = comment @value = value == NOT_CONFIGURED ? @graphql_name : value if deprecation_reason self.deprecation_reason = deprecation_reason end @owner = owner @ast_node = ast_node if directives directives.each do |dir_class, | directive(dir_class, **) end end if block_given? instance_exec(self, &block) end end |
Instance Attribute Details
#graphql_name ⇒ Object (readonly)
Returns the value of attribute graphql_name.
35 36 37 |
# File 'lib/graphql/schema/enum_value.rb', line 35 def graphql_name @graphql_name end |
#owner ⇒ Object (readonly)
Returns
Class— The enum type that owns this value
40 41 42 |
# File 'lib/graphql/schema/enum_value.rb', line 40 def owner @owner end |
Instance Method Details
#authorized?(_ctx) ⇒ Boolean
90 |
# File 'lib/graphql/schema/enum_value.rb', line 90 def (_ctx); true; end |
#comment(new_comment = nil) ⇒ Object
71 72 73 74 75 76 |
# File 'lib/graphql/schema/enum_value.rb', line 71 def comment(new_comment = nil) if new_comment @comment = new_comment end @comment end |
#description(new_desc = nil) ⇒ Object
64 65 66 67 68 69 |
# File 'lib/graphql/schema/enum_value.rb', line 64 def description(new_desc = nil) if new_desc @description = new_desc end @description end |
#inspect ⇒ Object
85 86 87 |
# File 'lib/graphql/schema/enum_value.rb', line 85 def inspect "#<#{self.class} #{path} @value=#{@value.inspect}#{description ? " @description=#{description.inspect}" : ""}#{deprecation_reason ? " @deprecation_reason=#{deprecation_reason.inspect}" : ""}>" end |
#value(new_val = nil) ⇒ Object
78 79 80 81 82 83 |
# File 'lib/graphql/schema/enum_value.rb', line 78 def value(new_val = nil) unless new_val.nil? @value = new_val end @value end |
#visible?(_ctx) ⇒ Boolean
89 |
# File 'lib/graphql/schema/enum_value.rb', line 89 def visible?(_ctx); true; end |