class GraphQL::BaseType

The parent for all type classes.

Attributes

ast_node[RW]
default_relay[W]

@api private

default_scalar[W]

@api private

description[RW]

@return [String, nil] a description for this type

graphql_name[R]

@return [String] the name of this type, must be unique within a Schema

introspection[W]

@api private

name[R]

@return [String] the name of this type, must be unique within a Schema

Public Class Methods

new() click to toggle source
# File lib/graphql/base_type.rb, line 24
def initialize
  @introspection = false
  @default_scalar = false
  @default_relay = false
end

Public Instance Methods

==(other) click to toggle source

@param other [GraphQL::BaseType] compare to this object @return [Boolean] are these types equivalent? (incl. non-null, list) @see {ModifiesAnotherType#==} for override on List & NonNull types

# File lib/graphql/base_type.rb, line 81
def ==(other)
  other.is_a?(GraphQL::BaseType) && self.name == other.name
end
coerce_input(value, ctx = nil) click to toggle source
# File lib/graphql/base_type.rb, line 163
def coerce_input(value, ctx = nil)
  if value.nil?
    nil
  else
    if ctx.nil?
      warn_deprecated_coerce("coerce_isolated_input")
      ctx = GraphQL::Query::NullContext
    end
    coerce_non_null_input(value, ctx)
  end
end
coerce_isolated_input(value) click to toggle source
# File lib/graphql/base_type.rb, line 133
def coerce_isolated_input(value)
  coerce_input(value, GraphQL::Query::NullContext)
end
coerce_isolated_result(value) click to toggle source
# File lib/graphql/base_type.rb, line 137
def coerce_isolated_result(value)
  coerce_result(value, GraphQL::Query::NullContext)
end
coerce_result(value, ctx) click to toggle source
# File lib/graphql/base_type.rb, line 175
def coerce_result(value, ctx)
  raise GraphQL::RequiredImplementationMissingError
end
default_relay?() click to toggle source

@return [Boolean] Is this type a built-in Relay type? (`Node`, `PageInfo`)

# File lib/graphql/base_type.rb, line 71
def default_relay?
  @default_relay
end
default_scalar?() click to toggle source

@return [Boolean] Is this type a built-in scalar type? (eg, `String`, `Int`)

# File lib/graphql/base_type.rb, line 66
def default_scalar?
  @default_scalar
end
get_field(name) click to toggle source

Types with fields may override this @param name [String] field name to lookup for this type @return [GraphQL::Field, nil]

# File lib/graphql/base_type.rb, line 182
def get_field(name)
  nil
end
graphql_definition(silence_deprecation_warning: false) click to toggle source

Future-compatible alias @see {GraphQL::SchemaMember}

# File lib/graphql/base_type.rb, line 44
def graphql_definition(silence_deprecation_warning: false)
  itself
end
initialize_copy(other) click to toggle source
# File lib/graphql/base_type.rb, line 30
def initialize_copy(other)
  super
  # Reset these derived defaults
  @connection_type = nil
  @edge_type = nil
end
inspect()
Alias for: to_s
introspection?() click to toggle source

@return [Boolean] Is this type a predefined introspection type?

# File lib/graphql/base_type.rb, line 61
def introspection?
  @introspection
end
list?() click to toggle source

Returns true if this is a list type. A non-nullable list is considered a list.

# File lib/graphql/base_type.rb, line 222
def list?
  false
end
name=(name) click to toggle source
# File lib/graphql/base_type.rb, line 52
def name=(name)
  GraphQL::NameValidator.validate!(name)
  @name = name
end
non_null?() click to toggle source

Returns true if this is a non-nullable type. A nullable list of non-nullables is considered nullable.

# File lib/graphql/base_type.rb, line 217
def non_null?
  false
end
resolve_type(value, ctx) click to toggle source

Find out which possible type to use for `value`. Returns self if there are no possible types (ie, not Union or Interface)

# File lib/graphql/base_type.rb, line 113
def resolve_type(value, ctx)
  self
end
to_definition(schema, printer: nil, **args) click to toggle source

Return a GraphQL string for the type definition @param schema [GraphQL::Schema] @param printer [GraphQL::Schema::Printer] @see {GraphQL::Schema::Printer#initialize for additional options} @return [String] type definition

# File lib/graphql/base_type.rb, line 211
def to_definition(schema, printer: nil, **args)
  printer ||= GraphQL::Schema::Printer.new(schema, **args)
  printer.print_type(self)
end
to_list_type() click to toggle source

@return [GraphQL::ListType] a list version of this type

# File lib/graphql/base_type.rb, line 97
def to_list_type
  GraphQL::ListType.new(of_type: self)
end
to_non_null_type() click to toggle source

@return [GraphQL::NonNullType] a non-null version of this type

# File lib/graphql/base_type.rb, line 92
def to_non_null_type
  GraphQL::NonNullType.new(of_type: self)
end
to_s() click to toggle source

Print the human-readable name of this type using the query-string naming pattern

# File lib/graphql/base_type.rb, line 118
def to_s
  name
end
Also aliased as: inspect, to_type_signature
to_type_signature()
Alias for: to_s
type_class() click to toggle source
# File lib/graphql/base_type.rb, line 48
def type_class
  metadata[:type_class]
end
unwrap() click to toggle source

If this type is modifying an underlying type, return the underlying type. (Otherwise, return `self`.)

# File lib/graphql/base_type.rb, line 87
def unwrap
  self
end
valid_input?(value, ctx = nil) click to toggle source
# File lib/graphql/base_type.rb, line 141
def valid_input?(value, ctx = nil)
  if ctx.nil?
    warn_deprecated_coerce("valid_isolated_input?")
    ctx = GraphQL::Query::NullContext
  end

  validate_input(value, ctx).valid?
end
valid_isolated_input?(value) click to toggle source
# File lib/graphql/base_type.rb, line 125
def valid_isolated_input?(value)
  valid_input?(value, GraphQL::Query::NullContext)
end
validate_input(value, ctx = nil) click to toggle source
# File lib/graphql/base_type.rb, line 150
def validate_input(value, ctx = nil)
  if ctx.nil?
    warn_deprecated_coerce("validate_isolated_input")
    ctx = GraphQL::Query::NullContext
  end

  if value.nil?
    GraphQL::Query::InputValidationResult.new
  else
    validate_non_null_input(value, ctx)
  end
end
validate_isolated_input(value) click to toggle source
# File lib/graphql/base_type.rb, line 129
def validate_isolated_input(value)
  validate_input(value, GraphQL::Query::NullContext)
end

Private Instance Methods

warn_deprecated_coerce(alt_method_name) click to toggle source
# File lib/graphql/base_type.rb, line 228
def warn_deprecated_coerce(alt_method_name)
  GraphQL::Deprecation.warn("Coercing without a context is deprecated; use `#{alt_method_name}` if you don't want context-awareness")
end