Sha256: 47c5d2b32fa9c8134306b00429d2d434fb11ea483c072df1a6baa0359f36d216

Contents?: true

Size: 834 Bytes

Versions: 6

Compression:

Stored size: 834 Bytes

Contents

# frozen_string_literal: true

module Rails
  module GraphQL
    class Type
      # Bigint basically removes the limit of the value, but it serializes as
      # a string so it won't go against the spec
      class Scalar::BigintScalar < Scalar
        desc <<~DESC
          The Bigint scalar type represents a signed numeric non-fractional value.
          It can go beyond the Int 32-bit limit, but it's exchanged as a string.
        DESC

        class << self
          def valid_input?(value)
            super && value.match?(/\A[+-]?\d+\z/)
          end

          def valid_output?(value)
            value.respond_to?(:to_i)
          end

          def as_json(value)
            value.to_i.to_s
          end

          def deserialize(value)
            value.to_i
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rails-graphql-1.0.2 lib/rails/graphql/type/scalar/bigint_scalar.rb
rails-graphql-1.0.1 lib/rails/graphql/type/scalar/bigint_scalar.rb
rails-graphql-1.0.0 lib/rails/graphql/type/scalar/bigint_scalar.rb
rails-graphql-1.0.0.rc2 lib/rails/graphql/type/scalar/bigint_scalar.rb
rails-graphql-1.0.0.rc1 lib/rails/graphql/type/scalar/bigint_scalar.rb
rails-graphql-1.0.0.beta lib/rails/graphql/type/scalar/bigint_scalar.rb