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