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 81 def ==(other) other.is_a?(GraphQL::BaseType) && self.name == other.name end
# 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
# File lib/graphql/base_type.rb, line 133 def coerce_isolated_input(value) coerce_input(value, GraphQL::Query::NullContext) end
# File lib/graphql/base_type.rb, line 137 def coerce_isolated_result(value) coerce_result(value, GraphQL::Query::NullContext) end
# File lib/graphql/base_type.rb, line 175 def coerce_result(value, ctx) raise GraphQL::RequiredImplementationMissingError end
@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
@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
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
Future-compatible alias @see {GraphQL::SchemaMember}
# File lib/graphql/base_type.rb, line 44 def graphql_definition(silence_deprecation_warning: false) itself 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 61 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 222 def list? false end
# File lib/graphql/base_type.rb, line 52 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 217 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 113 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 211 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 97 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 92 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 118 def to_s name end
# File lib/graphql/base_type.rb, line 48 def type_class metadata[:type_class] end
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
# 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
# File lib/graphql/base_type.rb, line 125 def valid_isolated_input?(value) valid_input?(value, GraphQL::Query::NullContext) end
# 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
# File lib/graphql/base_type.rb, line 129 def validate_isolated_input(value) validate_input(value, GraphQL::Query::NullContext) end
Private Instance Methods
# 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