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 23 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 74 def ==(other) other.is_a?(GraphQL::BaseType) && self.name == other.name end
# File lib/graphql/base_type.rb, line 156 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 126 def coerce_isolated_input(value) coerce_input(value, GraphQL::Query::NullContext) end
# File lib/graphql/base_type.rb, line 130 def coerce_isolated_result(value) coerce_result(value, GraphQL::Query::NullContext) end
# File lib/graphql/base_type.rb, line 168 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 64 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 59 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 175 def get_field(name) nil end
# File lib/graphql/base_type.rb, line 29 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 54 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 215 def list? false end
# File lib/graphql/base_type.rb, line 45 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 210 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 106 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 204 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 90 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 85 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 111 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 80 def unwrap self end
# File lib/graphql/base_type.rb, line 134 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 118 def valid_isolated_input?(value) valid_input?(value, GraphQL::Query::NullContext) end
# File lib/graphql/base_type.rb, line 143 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 122 def validate_isolated_input(value) validate_input(value, GraphQL::Query::NullContext) end
Private Instance Methods
# File lib/graphql/base_type.rb, line 221 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