Class: GraphQL::Schema::EnumValue Private

Inherits:
Member
  • Object
show all
Includes:
Member::AcceptsDefinition
Defined in:
lib/graphql/schema/enum_value.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

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::CachedGraphQLDefinition

#graphql_definition, #initialize_copy

Methods included from Relay::TypeExtensions

#connection_type, #define_connection, #define_edge, #edge_type

Methods included from Member::BaseDSLMethods

#introspection, #mutation, #name, #overridden_graphql_name

Methods included from Member::TypeSystemHelpers

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

Constructor Details

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

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of EnumValue.



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

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

Instance Attribute Details

#graphql_nameObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



31
32
33
# File 'lib/graphql/schema/enum_value.rb', line 31

def graphql_name
  @graphql_name
end

#ownerClass (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns The enum type that owns this value.



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

def owner
  @owner
end

Instance Method Details

#accessible?(_ctx) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



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

def accessible?(_ctx); true; end

#authorized?(_ctx) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



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

def authorized?(_ctx); true; end

#description(new_desc = nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



48
49
50
51
52
53
# File 'lib/graphql/schema/enum_value.rb', line 48

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

#to_graphqlGraphQL::EnumType::EnumValue

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns A runtime-ready object derived from this object.



63
64
65
66
67
68
69
70
71
# File 'lib/graphql/schema/enum_value.rb', line 63

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
end

#value(new_val = nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



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

def value(new_val = nil)
  if new_val
    @value = new_val
  end
  @value
end

#visible?(_ctx) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



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

def visible?(_ctx); true; end