Sha256: a24f0ef4d7770b6f931762d11e703c14702969f57a77b3d87a79be698e8443d4

Contents?: true

Size: 615 Bytes

Versions: 1

Compression:

Stored size: 615 Bytes

Contents

# frozen_string_literal: true

module GraphTypes
  MoneyType = ::GraphQL::ObjectType.define do
    name 'Money'

    field :cents, types.Int do
      resolve ->(object, _args, _context) do
        (object.to_f * 100).to_i
      end
    end

    field :formatted, types.String do
      argument :delimiter, types.String, default_value: '.'
      argument :separator, types.String, default_value: ','
      argument :unit,      types.String, default_value: 'R$ '

      resolve ->(object, args, _context) do
        ActionController::Base.helpers.number_to_currency object.to_f, args.to_h
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
graph_types-0.2.0 lib/graph_types/types/money_type.rb