class GraphQL::BaseType
The parent for all type classes.
Attributes
@api private
@api private
@return [String, nil] a description for this type
@return [String] the name of this type, must be unique within a Schema
@api private
@return [String] the name of this type, must be unique within a Schema
Public Class Methods
# File lib/graphql/base_type.rb, line 24 def initialize @introspection = false @default_scalar = false @default_relay = false end
Public Instance Methods
@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 75 def ==(other) other.is_a?(GraphQL::BaseType) && self.name == other.name end
# File lib/graphql/base_type.rb, line 157 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
# File lib/graphql/base_type.rb, line 127 def coerce_isolated_input(value) coerce_input(value, GraphQL::Query::NullContext) end
# File lib/graphql/base_type.rb, line 131 def coerce_isolated_result(value) coerce_result(value, GraphQL::Query::NullContext) end
# File lib/graphql/base_type.rb, line 169 def coerce_result(value, ctx) raise NotImplementedError end
@return [Boolean] Is this type a built-in Relay
type? (`Node`, `PageInfo`)
# File lib/graphql/base_type.rb, line 65 def default_relay? @default_relay end
@return [Boolean] Is this type a built-in scalar type? (eg, `String`, `Int`)
# File lib/graphql/base_type.rb, line 60 def default_scalar? @default_scalar end
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 176 def get_field(name) nil end
GraphQL::Define::InstanceDefinable#initialize_copy
# File lib/graphql/base_type.rb, line 30 def initialize_copy(other) super # Reset these derived defaults @connection_type = nil @edge_type = nil end
@return [Boolean] Is this type a predefined introspection type?
# File lib/graphql/base_type.rb, line 55 def introspection? @introspection end
Returns true if this is a list type. A non-nullable list is considered a list.
# File lib/graphql/base_type.rb, line 216 def list? false end
# File lib/graphql/base_type.rb, line 46 def name=(name) GraphQL::NameValidator.validate!(name) @name = name end
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 211 def non_null? false end
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 107 def resolve_type(value, ctx) self end
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 205 def to_definition(schema, printer: nil, **args) printer ||= GraphQL::Schema::Printer.new(schema, **args) printer.print_type(self) end
@return [GraphQL::ListType] a list version of this type
# File lib/graphql/base_type.rb, line 91 def to_list_type GraphQL::ListType.new(of_type: self) end
@return [GraphQL::NonNullType] a non-null version of this type
# File lib/graphql/base_type.rb, line 86 def to_non_null_type GraphQL::NonNullType.new(of_type: self) end
Print the human-readable name of this type using the query-string naming pattern
# File lib/graphql/base_type.rb, line 112 def to_s name end
If this type is modifying an underlying type, return the underlying type. (Otherwise, return `self`.)
# File lib/graphql/base_type.rb, line 81 def unwrap self end
# File lib/graphql/base_type.rb, line 135 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
# File lib/graphql/base_type.rb, line 119 def valid_isolated_input?(value) valid_input?(value, GraphQL::Query::NullContext) end
# File lib/graphql/base_type.rb, line 144 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
# File lib/graphql/base_type.rb, line 123 def validate_isolated_input(value) validate_input(value, GraphQL::Query::NullContext) end
Private Instance Methods
# File lib/graphql/base_type.rb, line 222 def warn_deprecated_coerce(alt_method_name) warn("Coercing without a context is deprecated; use `#{alt_method_name}` if you don't want context-awareness") end