Sha256: 792570c3be71570ce99149d5ee4300abd67a84fa4d7829c9e1a6c8e7ec6cf263

Contents?: true

Size: 868 Bytes

Versions: 6

Compression:

Stored size: 868 Bytes

Contents

# frozen_string_literal: true

module Rails # :nodoc:
  module GraphQL # :nodoc:
    class Type # :nodoc:
      # 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-0.2.1 lib/rails/graphql/type/scalar/bigint_scalar.rb
rails-graphql-0.2.0 lib/rails/graphql/type/scalar/bigint_scalar.rb
rails-graphql-0.1.3 lib/rails/graphql/type/scalar/bigint_scalar.rb
rails-graphql-0.1.2 lib/rails/graphql/type/scalar/bigint_scalar.rb
rails-graphql-0.1.1 lib/rails/graphql/type/scalar/bigint_scalar.rb
rails-graphql-0.1.0 lib/rails/graphql/type/scalar/bigint_scalar.rb