|
| 1 | +# UnsignedLong — GraphQL Custom Scalar |
| 2 | + |
| 3 | +Author – ChilliCream |
| 4 | + |
| 5 | +Date – 2026-01-09 |
| 6 | + |
| 7 | +**License and Copyright** |
| 8 | + |
| 9 | +Copyright © GraphQL contributors. This specification is licensed under |
| 10 | +[OWFa 1.0](https://www.openwebfoundation.org/the-agreements/the-owf-1-0-agreements-granted-claims/owfa-1-0). |
| 11 | + |
| 12 | +# Overview |
| 13 | + |
| 14 | +The `UnsignedLong` scalar type represents an unsigned 64-bit integer. It is |
| 15 | +intended for scenarios where values exceed the range of unsigned 32-bit |
| 16 | +integers, such as representing very large counts, file sizes, memory addresses, |
| 17 | +or any non-negative integer values requiring more than 32 bits. |
| 18 | + |
| 19 | +Unlike the `Long` scalar which represents signed 64-bit integers with a range of |
| 20 | +-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807, `UnsignedLong` supports |
| 21 | +non-negative values in the range 0 to 18,446,744,073,709,551,615. |
| 22 | + |
| 23 | +**Note:** JavaScript's `JSON.parse()` does not safely support 64-bit integers. |
| 24 | +Values outside the safe integer range (0 to 2^53 - 1) may lose precision when |
| 25 | +parsed as JavaScript numbers. Client applications using JavaScript should handle |
| 26 | +`UnsignedLong` values with care, potentially using libraries like `json-bigint` |
| 27 | +or representing them as strings. |
| 28 | + |
| 29 | +# Recommended name |
| 30 | + |
| 31 | +The recommended name for this scalar is `UnsignedLong`. |
| 32 | + |
| 33 | +# Result spec |
| 34 | + |
| 35 | +An `UnsignedLong` scalar must serialize to an integer value in the range 0 to |
| 36 | +18,446,744,073,709,551,615 (inclusive). |
| 37 | + |
| 38 | +## Examples |
| 39 | + |
| 40 | +These are valid result values: |
| 41 | + |
| 42 | +| Value | Explanation | |
| 43 | +| ---------------------- | -------------------------------------- | |
| 44 | +| `0` | Minimum unsigned long value. | |
| 45 | +| `18446744073709551615` | Maximum unsigned long value. | |
| 46 | +| `9223372036854775808` | A value exceeding signed long maximum. | |
| 47 | + |
| 48 | +These are invalid result values: |
| 49 | + |
| 50 | +| Value | Why is it invalid | |
| 51 | +| ---------------------- | ------------------------------------ | |
| 52 | +| `-1` | Negative values are not allowed. | |
| 53 | +| `18446744073709551616` | Exceeds maximum unsigned long value. | |
| 54 | +| `3.14` | Fractional values are not allowed. | |
| 55 | +| `"1000"` | Must be a number, not a string. | |
| 56 | + |
| 57 | +# Input spec |
| 58 | + |
| 59 | +An `UnsignedLong` scalar accepts integer values in the range 0 to |
| 60 | +18,446,744,073,709,551,615 (inclusive), both as GraphQL literals and as JSON |
| 61 | +input values. |
| 62 | + |
| 63 | +Implementations should validate: |
| 64 | + |
| 65 | +- Value is an integer (no fractional component) |
| 66 | +- Value is between 0 and 18,446,744,073,709,551,615 (inclusive) |
| 67 | +- Value is not negative |
| 68 | + |
| 69 | +## Examples |
| 70 | + |
| 71 | +Valid input values: |
| 72 | + |
| 73 | +GraphQL Literal: |
| 74 | + |
| 75 | +```graphql |
| 76 | +query { |
| 77 | + fileInfo(sizeInBytes: 10000000000000000000) { |
| 78 | + name |
| 79 | + } |
| 80 | +} |
| 81 | +``` |
| 82 | + |
| 83 | +JSON input: |
| 84 | + |
| 85 | +```json |
| 86 | +{ |
| 87 | + "sizeInBytes": 10000000000000000000 |
| 88 | +} |
| 89 | +``` |
| 90 | + |
| 91 | +```json |
| 92 | +{ |
| 93 | + "maxValue": 18446744073709551615 |
| 94 | +} |
| 95 | +``` |
| 96 | + |
| 97 | +Invalid input values: |
| 98 | + |
| 99 | +| Value | Why is it invalid | |
| 100 | +| ---------------------- | ------------------------------------ | |
| 101 | +| `-1` | Negative values are not allowed. | |
| 102 | +| `18446744073709551616` | Exceeds maximum unsigned long value. | |
| 103 | +| `3.14` | Fractional values are not allowed. | |
| 104 | +| `"1000"` | Must be a number, not a string. | |
| 105 | + |
| 106 | +# References |
| 107 | + |
| 108 | +- [GraphQL Specification - Int](https://spec.graphql.org/September2025/#sec-Int) |
| 109 | + — Built-in integer scalar type |
0 commit comments