Method: GraphQL::Schema::Field#type

Defined in:
lib/graphql/schema/field.rb

#type(new_type = NOT_CONFIGURED) ⇒ Module, ...

Get or set the return type of this field.

It may return nil if no type was configured or if the given definition block wasn't called yet.

Parameters:

Returns:



594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
# File 'lib/graphql/schema/field.rb', line 594

def type(new_type = NOT_CONFIGURED)
  if NOT_CONFIGURED.equal?(new_type)
    if @resolver_class
      return_type = @return_type_expr || @resolver_class.type_expr
      if return_type.nil?
        raise MissingReturnTypeError, "Can't determine the return type for #{self.path} (it has `resolver: #{@resolver_class}`, perhaps that class is missing a `type ...` declaration, or perhaps its type causes a cyclical loading issue)"
      end
      nullable = @return_type_null.nil? ? @resolver_class.null : @return_type_null
      Member::BuildType.parse_type(return_type, null: nullable)
    elsif !@return_type_expr.nil?
      @type ||= Member::BuildType.parse_type(@return_type_expr, null: @return_type_null)
    end
  else
    @return_type_expr = new_type
    # If `type` is set in the definition block, then the `connection_extension: ...` given as a keyword won't be used, hmm...
    # Also, arguments added by `connection_extension` will clobber anything previously defined,
    # so `type(...)` should go first.
    set_pagination_extensions(connection_extension: self.class.connection_extension)
  end
rescue GraphQL::Schema::InvalidDocumentError, MissingReturnTypeError => err
  # Let this propagate up
  raise err
rescue StandardError => err
  raise MissingReturnTypeError, "Failed to build return type for #{@owner.graphql_name}.#{name} from #{@return_type_expr.inspect}: (#{err.class}) #{err.message}", err.backtrace
end