Class: GraphQL::BaseType
- Inherits:
- 
      Object
      
        - Object
- GraphQL::BaseType
 
- Defined in:
- lib/graphql/base_type.rb
Overview
The parent for all type classes.
Direct Known Subclasses
EnumType, InputObjectType, InterfaceType, ListType, NonNullType, ObjectType, ScalarType, UnionType
Defined Under Namespace
Modules: ModifiesAnotherType
Instance Attribute Summary collapse
- 
  
    
      #ast_node  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute ast_node. 
- 
  
    
      #default_relay  ⇒ Object 
    
    
  
  
  
  
    
    
      writeonly
    
  
  
  
  
  private
  
    
- 
  
    
      #default_scalar  ⇒ Object 
    
    
  
  
  
  
    
    
      writeonly
    
  
  
  
  
  private
  
    
- 
  
    
      #description  ⇒ String? 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    A description for this type. 
- 
  
    
      #introspection  ⇒ Object 
    
    
  
  
  
  
    
    
      writeonly
    
  
  
  
  
  private
  
    
- 
  
    
      #name  ⇒ String 
    
    
      (also: #graphql_name)
    
  
  
  
  
    
    
  
  
  
  
  
  
    The name of this type, must be unique within a Schema. 
Class Method Summary collapse
- 
  
    
      .resolve_related_type(type_arg)  ⇒ GraphQL::BaseType 
    
    
  
  
  
  
  
  
  
  
  
    During schema definition, types can be defined inside procs or as strings. 
Instance Method Summary collapse
- 
  
    
      #==(other)  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    Are these types equivalent? (incl. non-null, list). 
- 
  
    
      #coerce_input(value, ctx = nil)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
- 
  
    
      #coerce_isolated_input(value)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
- 
  
    
      #coerce_isolated_result(value)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
- 
  
    
      #coerce_result(value, ctx)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
- 
  
    
      #default_relay?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    Is this type a built-in Relay type? ( Node,PageInfo).
- 
  
    
      #default_scalar?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    Is this type a built-in scalar type? (eg, String,Int).
- 
  
    
      #get_field(name)  ⇒ GraphQL::Field? 
    
    
  
  
  
  
  
  
  
  
  
    Types with fields may override this. 
- 
  
    
      #graphql_definition(silence_deprecation_warning: false)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Future-compatible alias. 
- 
  
    
      #initialize  ⇒ BaseType 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of BaseType. 
- 
  
    
      #initialize_copy(other)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
- 
  
    
      #introspection?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    Is this type a predefined introspection type?. 
- 
  
    
      #list?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    Returns true if this is a list type. 
- 
  
    
      #non_null?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    Returns true if this is a non-nullable type. 
- 
  
    
      #resolve_type(value, ctx)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Find out which possible type to use for value.
- 
  
    
      #to_definition(schema, printer: nil, **args)  ⇒ String 
    
    
  
  
  
  
  
  
  
  
  
    Return a GraphQL string for the type definition. 
- 
  
    
      #to_list_type  ⇒ GraphQL::ListType 
    
    
  
  
  
  
  
  
  
  
  
    A list version of this type. 
- 
  
    
      #to_non_null_type  ⇒ GraphQL::NonNullType 
    
    
  
  
  
  
  
  
  
  
  
    A non-null version of this type. 
- 
  
    
      #to_s  ⇒ Object 
    
    
      (also: #inspect, #to_type_signature)
    
  
  
  
  
  
  
  
  
  
    Print the human-readable name of this type using the query-string naming pattern. 
- 
  
    
      #type_class  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
- 
  
    
      #unwrap  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    If this type is modifying an underlying type, return the underlying type. 
- 
  
    
      #valid_input?(value, ctx = nil)  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
- 
  
    
      #valid_isolated_input?(value)  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
- 
  
    
      #validate_input(value, ctx = nil)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
- 
  
    
      #validate_isolated_input(value)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Methods included from Relay::TypeExtensions
#connection_type, #define_connection, #define_edge, #edge_type
Methods included from Define::InstanceDefinable
#define, #deprecated_define, #metadata, #redefine
Methods included from Define::NonNullWithBang
Constructor Details
#initialize ⇒ BaseType
Returns a new instance of BaseType.
| 24 25 26 27 28 | # File 'lib/graphql/base_type.rb', line 24 def initialize @introspection = false @default_scalar = false @default_relay = false end | 
Instance Attribute Details
#ast_node ⇒ Object
Returns the value of attribute ast_node.
| 22 23 24 | # File 'lib/graphql/base_type.rb', line 22 def ast_node @ast_node end | 
#default_relay=(value) ⇒ Object (writeonly)
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.
| 76 77 78 | # File 'lib/graphql/base_type.rb', line 76 def default_relay=(value) @default_relay = value end | 
#default_scalar=(value) ⇒ Object (writeonly)
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.
| 76 77 78 | # File 'lib/graphql/base_type.rb', line 76 def default_scalar=(value) @default_scalar = value end | 
#description ⇒ String?
Returns a description for this type.
| 58 59 60 | # File 'lib/graphql/base_type.rb', line 58 def description @description end | 
#introspection=(value) ⇒ Object (writeonly)
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.
| 76 77 78 | # File 'lib/graphql/base_type.rb', line 76 def introspection=(value) @introspection = value end | 
#name ⇒ String Also known as: graphql_name
Returns the name of this type, must be unique within a Schema.
| 38 39 40 | # File 'lib/graphql/base_type.rb', line 38 def name @name end | 
Class Method Details
.resolve_related_type(type_arg) ⇒ GraphQL::BaseType
During schema definition, types can be defined inside procs or as strings. This function converts it to a type instance
| 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | # File 'lib/graphql/base_type.rb', line 189 def self.(type_arg) case type_arg when Proc # lazy-eval it, then try again (type_arg.call) when String # Get a constant by this name (Object.const_get(type_arg)) else if type_arg.respond_to?(:graphql_definition) type_arg.graphql_definition(silence_deprecation_warning: true) else type_arg end end end | 
Instance Method Details
#==(other) ⇒ Boolean
Returns are these types equivalent? (incl. non-null, list).
| 81 82 83 | # 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) ⇒ Object
| 163 164 165 166 167 168 169 170 171 172 173 | # 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) ⇒ Object
| 133 134 135 | # File 'lib/graphql/base_type.rb', line 133 def coerce_isolated_input(value) coerce_input(value, GraphQL::Query::NullContext) end | 
#coerce_isolated_result(value) ⇒ Object
| 137 138 139 | # File 'lib/graphql/base_type.rb', line 137 def coerce_isolated_result(value) coerce_result(value, GraphQL::Query::NullContext) end | 
#coerce_result(value, ctx) ⇒ Object
| 175 176 177 | # File 'lib/graphql/base_type.rb', line 175 def coerce_result(value, ctx) raise GraphQL::RequiredImplementationMissingError end | 
#default_relay? ⇒ Boolean
Returns Is this type a built-in Relay type? (Node, PageInfo).
| 71 72 73 | # File 'lib/graphql/base_type.rb', line 71 def default_relay? @default_relay end | 
#default_scalar? ⇒ Boolean
Returns Is this type a built-in scalar type? (eg, String, Int).
| 66 67 68 | # File 'lib/graphql/base_type.rb', line 66 def default_scalar? @default_scalar end | 
#get_field(name) ⇒ GraphQL::Field?
Types with fields may override this
| 182 183 184 | # File 'lib/graphql/base_type.rb', line 182 def get_field(name) nil end | 
#graphql_definition(silence_deprecation_warning: false) ⇒ Object
Future-compatible alias
| 44 45 46 | # File 'lib/graphql/base_type.rb', line 44 def graphql_definition(silence_deprecation_warning: false) itself end | 
#initialize_copy(other) ⇒ Object
| 30 31 32 33 34 35 | # File 'lib/graphql/base_type.rb', line 30 def initialize_copy(other) super # Reset these derived defaults @connection_type = nil @edge_type = nil end | 
#introspection? ⇒ Boolean
Returns Is this type a predefined introspection type?.
| 61 62 63 | # File 'lib/graphql/base_type.rb', line 61 def introspection? @introspection end | 
#list? ⇒ Boolean
Returns true if this is a list type. A non-nullable list is considered a list.
| 222 223 224 | # File 'lib/graphql/base_type.rb', line 222 def list? false end | 
#non_null? ⇒ Boolean
Returns true if this is a non-nullable type. A nullable list of non-nullables is considered nullable.
| 217 218 219 | # File 'lib/graphql/base_type.rb', line 217 def non_null? false end | 
#resolve_type(value, ctx) ⇒ Object
Find out which possible type to use for value.
Returns self if there are no possible types (ie, not Union or Interface)
| 113 114 115 | # File 'lib/graphql/base_type.rb', line 113 def resolve_type(value, ctx) self end | 
#to_definition(schema, printer: nil, **args) ⇒ String
Return a GraphQL string for the type definition
| 211 212 213 214 | # 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 ⇒ GraphQL::ListType
Returns a list version of this type.
| 97 98 99 | # File 'lib/graphql/base_type.rb', line 97 def to_list_type GraphQL::ListType.new(of_type: self) end | 
#to_non_null_type ⇒ GraphQL::NonNullType
Returns a non-null version of this type.
| 92 93 94 | # File 'lib/graphql/base_type.rb', line 92 def to_non_null_type GraphQL::NonNullType.new(of_type: self) end | 
#to_s ⇒ Object Also known as: inspect, to_type_signature
Print the human-readable name of this type using the query-string naming pattern
| 118 119 120 | # File 'lib/graphql/base_type.rb', line 118 def to_s name end | 
#type_class ⇒ Object
| 48 49 50 | # File 'lib/graphql/base_type.rb', line 48 def type_class [:type_class] end | 
#unwrap ⇒ Object
If this type is modifying an underlying type,
return the underlying type. (Otherwise, return self.)
| 87 88 89 | # File 'lib/graphql/base_type.rb', line 87 def unwrap self end | 
#valid_input?(value, ctx = nil) ⇒ Boolean
| 141 142 143 144 145 146 147 148 | # 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) ⇒ Boolean
| 125 126 127 | # 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) ⇒ Object
| 150 151 152 153 154 155 156 157 158 159 160 161 | # 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) ⇒ Object
| 129 130 131 | # File 'lib/graphql/base_type.rb', line 129 def validate_isolated_input(value) validate_input(value, GraphQL::Query::NullContext) end |