Sha256: b1492f00a100db609ac91572b9e1fb12ba620c8a11a936f290c6f9ef6ed63632

Contents?: true

Size: 747 Bytes

Versions: 26

Compression:

Stored size: 747 Bytes

Contents

# frozen_string_literal: true

module GraphQL
  module Types
    # @see {Types::BigInt} for handling integers outside 32-bit range.
    class Int < GraphQL::Schema::Scalar
      description "Represents non-fractional signed whole numeric values. Int can represent values between -(2^31) and 2^31 - 1."

      MIN = -(2**31)
      MAX = (2**31) - 1

      def self.coerce_input(value, _ctx)
        value.is_a?(Integer) ? value : nil
      end

      def self.coerce_result(value, ctx)
        value = value.to_i
        if value >= MIN && value <= MAX
          value
        else
          err = GraphQL::IntegerEncodingError.new(value)
          ctx.schema.type_error(err, ctx)
        end
      end

      default_scalar true
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
graphql-1.11.6 lib/graphql/types/int.rb
graphql-1.11.5 lib/graphql/types/int.rb
graphql-1.11.4 lib/graphql/types/int.rb
graphql-1.11.3 lib/graphql/types/int.rb
graphql-1.11.2 lib/graphql/types/int.rb
graphql-1.10.14 lib/graphql/types/int.rb
graphql-1.11.1 lib/graphql/types/int.rb
graphql-1.10.13 lib/graphql/types/int.rb
graphql-1.11.0 lib/graphql/types/int.rb
graphql-1.10.12 lib/graphql/types/int.rb
graphql-1.10.11 lib/graphql/types/int.rb
graphql-1.10.10 lib/graphql/types/int.rb
graphql-1.10.9 lib/graphql/types/int.rb
graphql-1.10.8 lib/graphql/types/int.rb
graphql-1.10.7 lib/graphql/types/int.rb
graphql-1.10.6 lib/graphql/types/int.rb
graphql-1.10.5 lib/graphql/types/int.rb
graphql-1.10.4 lib/graphql/types/int.rb
graphql-1.10.3 lib/graphql/types/int.rb
graphql-1.10.2 lib/graphql/types/int.rb