Long — GraphQL Custom Scalar

Author – ChilliCream

Date – 2025-12-29

1Overview

The Long scalar type represents a signed 64-bit integer. It is intended for scenarios where values exceed the range of the built-in Int scalar, such as representing large identifiers, timestamps in milliseconds, file sizes in bytes, or any integer values requiring more than 32 bits.

Unlike the built-in Int scalar which represents signed 32-bit integers with a range of -2,147,483,648 to 2,147,483,647, Long supports values in the range -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.

Note: JavaScript’s JSON.parse() does not safely support 64-bit integers. Values outside the safe integer range (-(2^53 - 1) to 2^53 - 1) may lose precision when parsed as JavaScript numbers. Client applications using JavaScript should handle Long values with care, potentially using libraries like json-bigint or representing them as strings.

3Result spec

A Long scalar must serialize to an integer value in the range -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 (inclusive).

3.1Examples

These are valid result values:

Value Explanation
0 Zero.
-9223372036854775808 Minimum long value.
9223372036854775807 Maximum long value.
1609459200000 Unix timestamp in milliseconds (2021-01-01 00:00:00 UTC).

These are invalid result values:

Value Why is it invalid
-9223372036854775809 Below minimum long value.
9223372036854775808 Exceeds maximum long value.
3.14 Fractional values are not allowed.
"1000" Must be a number, not a string.

4Input spec

A Long scalar accepts integer values in the range -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 (inclusive), both as GraphQL literals and as JSON input values.

Implementations should validate:

4.1Examples

Valid input values:

GraphQL Literal:

query {
  fileInfo(sizeInBytes: 5368709120) {
    name
  }
}

JSON input:

{
  "sizeInBytes": 5368709120
}
{
  "timestamp": 1609459200000
}

Invalid input values:

Value Why is it invalid
-9223372036854775809 Below minimum long value.
9223372036854775808 Exceeds maximum long value.
3.14 Fractional values are not allowed.
"1000" Must be a number, not a string.

5References

  1. 1Overview
  2. 2Recommended name
  3. 3Result spec
    1. 3.1Examples
  4. 4Input spec
    1. 4.1Examples
  5. 5References