|
| 1 | +# UnsignedInt — 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 `UnsignedInt` scalar type represents an unsigned 32-bit integer. It is |
| 15 | +intended for scenarios where values are constrained to the range 0 to |
| 16 | +4,294,967,295, such as representing counts, sizes, indices, or other |
| 17 | +non-negative integer values. |
| 18 | + |
| 19 | +Unlike the built-in `Int` scalar which represents signed 32-bit integers with a |
| 20 | +range of -2,147,483,648 to 2,147,483,647, `UnsignedInt` provides stronger type |
| 21 | +safety for values that must be non-negative and can represent larger positive |
| 22 | +values. |
| 23 | + |
| 24 | +# Recommended name |
| 25 | + |
| 26 | +The recommended name for this scalar is `UnsignedInt`. |
| 27 | + |
| 28 | +# Result spec |
| 29 | + |
| 30 | +An `UnsignedInt` scalar must serialize to an integer value in the range 0 to |
| 31 | +4,294,967,295 (inclusive). |
| 32 | + |
| 33 | +## Examples |
| 34 | + |
| 35 | +These are valid result values: |
| 36 | + |
| 37 | +| Value | Explanation | |
| 38 | +| ------------ | ------------------------------------- | |
| 39 | +| `0` | Minimum unsigned int value. | |
| 40 | +| `4294967295` | Maximum unsigned int value. | |
| 41 | +| `2147483648` | A value exceeding signed int maximum. | |
| 42 | + |
| 43 | +These are invalid result values: |
| 44 | + |
| 45 | +| Value | Why is it invalid | |
| 46 | +| ------------ | ----------------------------------- | |
| 47 | +| `-1` | Negative values are not allowed. | |
| 48 | +| `4294967296` | Exceeds maximum unsigned int value. | |
| 49 | +| `3.14` | Fractional values are not allowed. | |
| 50 | +| `"1000"` | Must be a number, not a string. | |
| 51 | + |
| 52 | +# Input spec |
| 53 | + |
| 54 | +An `UnsignedInt` scalar accepts integer values in the range 0 to 4,294,967,295 |
| 55 | +(inclusive), both as GraphQL literals and as JSON input values. |
| 56 | + |
| 57 | +Implementations should validate: |
| 58 | + |
| 59 | +- Value is an integer (no fractional component) |
| 60 | +- Value is between 0 and 4,294,967,295 (inclusive) |
| 61 | +- Value is not negative |
| 62 | + |
| 63 | +## Examples |
| 64 | + |
| 65 | +Valid input values: |
| 66 | + |
| 67 | +GraphQL Literal: |
| 68 | + |
| 69 | +```graphql |
| 70 | +query { |
| 71 | + items(limit: 100, offset: 50) { |
| 72 | + id |
| 73 | + } |
| 74 | +} |
| 75 | +``` |
| 76 | + |
| 77 | +JSON input: |
| 78 | + |
| 79 | +```json |
| 80 | +{ |
| 81 | + "limit": 100, |
| 82 | + "offset": 50 |
| 83 | +} |
| 84 | +``` |
| 85 | + |
| 86 | +```json |
| 87 | +{ |
| 88 | + "count": 4294967295 |
| 89 | +} |
| 90 | +``` |
| 91 | + |
| 92 | +Invalid input values: |
| 93 | + |
| 94 | +| Value | Why is it invalid | |
| 95 | +| ------------ | ----------------------------------- | |
| 96 | +| `-1` | Negative values are not allowed. | |
| 97 | +| `4294967296` | Exceeds maximum unsigned int value. | |
| 98 | +| `3.14` | Fractional values are not allowed. | |
| 99 | +| `"1000"` | Must be a number, not a string. | |
| 100 | + |
| 101 | +# References |
| 102 | + |
| 103 | +- [GraphQL Specification - Int](https://spec.graphql.org/September2025/#sec-Int) |
| 104 | + — Built-in integer scalar type |
0 commit comments