Class: GraphQL::Schema::EnumValue

Inherits:
Member
  • Object
show all
Includes:
Member::AcceptsDefinition, Member::CachedGraphQLDefinition, Member::HasAstNode, Member::HasPath
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:

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

Constant Summary

Constants included from Member::GraphQLTypeNames

Member::GraphQLTypeNames::Boolean, Member::GraphQLTypeNames::ID, Member::GraphQLTypeNames::Int

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Member::HasAstNode

#ast_node

Methods included from Member::HasPath

#path

Methods included from Member::CachedGraphQLDefinition

#graphql_definition, #initialize_copy, #type_class

Methods included from Member::RelayShortcuts

#connection_type, #connection_type_class, #edge_type, #edge_type_class

Methods included from Member::Scoped

#scope_items

Methods included from Member::TypeSystemHelpers

#kind, #list?, #non_null?, #to_list_type, #to_non_null_type, #to_type_signature

Methods included from Member::BaseDSLMethods::ConfigurationExtension

#inherited

Methods included from Member::BaseDSLMethods

#default_graphql_name, #introspection, #introspection?, #mutation, #name, #overridden_graphql_name

Methods included from Relay::TypeExtensions

#connection_type, #define_connection, #define_edge, #edge_type

Constructor Details

#initialize(graphql_name, desc = nil, owner:, ast_node: nil, description: nil, value: nil, deprecation_reason: nil, &block) ⇒ EnumValue


42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/graphql/schema/enum_value.rb', line 42

def initialize(graphql_name, desc = nil, owner:, ast_node: nil, description: nil, value: nil, deprecation_reason: nil, &block)
  @graphql_name = graphql_name.to_s
  @description = desc || description
  @value = value.nil? ? @graphql_name : value
  @deprecation_reason = deprecation_reason
  @owner = owner
  @ast_node = ast_node

  if block_given?
    instance_eval(&block)
  end
end

Instance Attribute Details

#deprecation_reasonString


40
41
42
# File 'lib/graphql/schema/enum_value.rb', line 40

def deprecation_reason
  @deprecation_reason
end

#graphql_nameObject (readonly)

Returns the value of attribute graphql_name


34
35
36
# File 'lib/graphql/schema/enum_value.rb', line 34

def graphql_name
  @graphql_name
end

#ownerClass (readonly)


37
38
39
# File 'lib/graphql/schema/enum_value.rb', line 37

def owner
  @owner
end

Instance Method Details

#accessible?(_ctx) ⇒ Boolean


82
# File 'lib/graphql/schema/enum_value.rb', line 82

def accessible?(_ctx); true; end

#authorized?(_ctx) ⇒ Boolean


83
# File 'lib/graphql/schema/enum_value.rb', line 83

def authorized?(_ctx); true; end

#description(new_desc = nil) ⇒ Object


55
56
57
58
59
60
# File 'lib/graphql/schema/enum_value.rb', line 55

def description(new_desc = nil)
  if new_desc
    @description = new_desc
  end
  @description
end

#to_graphqlGraphQL::EnumType::EnumValue


70
71
72
73
74
75
76
77
78
79
# File 'lib/graphql/schema/enum_value.rb', line 70

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.[:type_class] = self
  enum_value.ast_node = ast_node
  enum_value
end

#value(new_val = nil) ⇒ Object


62
63
64
65
66
67
# File 'lib/graphql/schema/enum_value.rb', line 62

def value(new_val = nil)
  unless new_val.nil?
    @value = new_val
  end
  @value
end

#visible?(_ctx) ⇒ Boolean


81
# File 'lib/graphql/schema/enum_value.rb', line 81

def visible?(_ctx); true; end