Sha256: e0163c840739349f85f6b446f3f98de232cacd0d0777f88992287440c3affaa9

Contents?: true

Size: 1018 Bytes

Versions: 1

Compression:

Stored size: 1018 Bytes

Contents

module GraphQL
  # The parent type for scalars, eg {GraphQL::STRING_TYPE}, {GraphQL::INT_TYPE}
  #
  # @example defining a type for Time
  #   TimeType = GraphQL::ObjectType.define do
  #     name "Time"
  #     description "Time since epoch in seconds"
  #
  #     coerce_input ->(value) { Time.at(Float(value)) }
  #     coerce_result ->(value) { value.to_f }
  #   end
  #
  class ScalarType < GraphQL::BaseType
    defined_by_config :name, :coerce, :coerce_input, :coerce_result, :description
    attr_accessor :name, :description

    def coerce=(proc)
      self.coerce_input = proc
      self.coerce_result = proc
    end

    def coerce_input(value)
      @coerce_input_proc.call(value)
    end

    def coerce_input=(proc)
      @coerce_input_proc = proc unless proc.nil?
    end

    def coerce_result(value)
      @coerce_result_proc.call(value)
    end

    def coerce_result=(proc)
      @coerce_result_proc = proc unless proc.nil?
    end

    def kind
      GraphQL::TypeKinds::SCALAR
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
graphql-0.10.0 lib/graphql/scalar_type.rb