diff --git a/docs/src/designing-a-schema/scalars.md b/docs/src/designing-a-schema/scalars.md index f66526526..727f97f14 100644 --- a/docs/src/designing-a-schema/scalars.md +++ b/docs/src/designing-a-schema/scalars.md @@ -17,6 +17,7 @@ The Fuel indexer has a collection of GraphQL scalars that cover virtually any va | I128 | `i128` | | I32 | `i32` | | I64 | `i64` | +| I16 | `i16` | | I8 | `i8` | | ID | `SizedAsciiString<64>` | Alias of `UID` | Json | `String` | JSON string of arbitary size | diff --git a/packages/fuel-indexer-lib/src/graphql/base.graphql b/packages/fuel-indexer-lib/src/graphql/base.graphql index a497706be..747658b21 100644 --- a/packages/fuel-indexer-lib/src/graphql/base.graphql +++ b/packages/fuel-indexer-lib/src/graphql/base.graphql @@ -18,6 +18,8 @@ scalar Json scalar U128 scalar U32 scalar U64 +scalar I16 +scalar U16 scalar U8 scalar UID scalar String diff --git a/packages/fuel-indexer-schema/src/lib.rs b/packages/fuel-indexer-schema/src/lib.rs index 6ccf24b93..b399618b4 100644 --- a/packages/fuel-indexer-schema/src/lib.rs +++ b/packages/fuel-indexer-schema/src/lib.rs @@ -62,18 +62,20 @@ pub enum FtColumn { ContractId(Option), Enum(Option), I128(Option), + I16(Option), I32(Option), I64(Option), I8(Option), ID(Option), Identity(Option), Json(Option), + String(Option), U128(Option), + U16(Option), U32(Option), U64(Option), U8(Option), UID(Option), - String(Option), } impl FtColumn { @@ -138,6 +140,14 @@ impl FtColumn { Some(val) => format!("{val}"), None => String::from(NULL_VALUE), }, + FtColumn::I16(value) => match value { + Some(val) => format!("{val}"), + None => String::from(NULL_VALUE), + }, + FtColumn::U16(value) => match value { + Some(val) => format!("{val}"), + None => String::from(NULL_VALUE), + }, FtColumn::I128(value) => match value { Some(val) => format!("{val}"), None => String::from(NULL_VALUE), @@ -278,6 +288,8 @@ mod tests { let uint4 = FtColumn::U32(Some(u32::from_le_bytes([0x78; 4]))); let uint8 = FtColumn::U64(Some(u64::from_le_bytes([0x78; 8]))); let xstring = FtColumn::String(Some(String::from("hello world"))); + let uint2 = FtColumn::U16(Some(u16::from_le_bytes([0x78; 2]))); + let int2 = FtColumn::I16(Some(i16::from_le_bytes([0x78; 2]))); insta::assert_yaml_snapshot!(addr.query_fragment()); insta::assert_yaml_snapshot!(array.query_fragment()); @@ -302,6 +314,8 @@ mod tests { insta::assert_yaml_snapshot!(uint4.query_fragment()); insta::assert_yaml_snapshot!(uint8.query_fragment()); insta::assert_yaml_snapshot!(xstring.query_fragment()); + insta::assert_yaml_snapshot!(uint2.query_fragment()); + insta::assert_yaml_snapshot!(int2.query_fragment()); } #[test] @@ -329,6 +343,8 @@ mod tests { let uint4_none = FtColumn::U32(None); let uint8_none = FtColumn::U64(None); let xstring_none = FtColumn::String(None); + let uint2_none = FtColumn::U16(None); + let int2_none = FtColumn::I16(None); insta::assert_yaml_snapshot!(addr_none.query_fragment()); insta::assert_yaml_snapshot!(array.query_fragment()); @@ -351,6 +367,8 @@ mod tests { insta::assert_yaml_snapshot!(uint4_none.query_fragment()); insta::assert_yaml_snapshot!(uint8_none.query_fragment()); insta::assert_yaml_snapshot!(xstring_none.query_fragment()); + insta::assert_yaml_snapshot!(uint2_none.query_fragment()); + insta::assert_yaml_snapshot!(int2_none.query_fragment()); } #[test] diff --git a/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-24.snap b/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-24.snap index 18408fe1f..418d28ccc 100644 --- a/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-24.snap +++ b/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-24.snap @@ -1,6 +1,6 @@ --- source: packages/fuel-indexer-schema/src/lib.rs -expression: tai64_timestamp.query_fragment() +expression: uint2.query_fragment() --- -"'0000000000000000'" +"30840" diff --git a/packages/fuel-indexer-tests/indexers/fuel-indexer-test/schema/fuel_indexer_test.graphql b/packages/fuel-indexer-tests/indexers/fuel-indexer-test/schema/fuel_indexer_test.graphql index 335145cc3..64ba59655 100644 --- a/packages/fuel-indexer-tests/indexers/fuel-indexer-test/schema/fuel_indexer_test.graphql +++ b/packages/fuel-indexer-tests/indexers/fuel-indexer-test/schema/fuel_indexer_test.graphql @@ -194,7 +194,7 @@ type Book @entity { type Sponsor @entity { id: ID! name: String! @unique - amount: U64! + amount: U16! representative: Person! } diff --git a/packages/fuel-indexer-types/src/scalar.rs b/packages/fuel-indexer-types/src/scalar.rs index 5e8bf7fc0..eb6c23d4b 100644 --- a/packages/fuel-indexer-types/src/scalar.rs +++ b/packages/fuel-indexer-types/src/scalar.rs @@ -8,39 +8,45 @@ use serde::{Deserialize, Serialize}; /// Scalar for 256-bit value. pub type B256 = [u8; 32]; -/// Scalar for 32-byte unique ID payloads. +/// Scalar for 512-bit unique ID payloads. pub type UID = SizedAsciiString<64>; /// Scalar for object IDs. pub type ID = UID; -/// Scalar for 4-byte signed integers. +/// Scalar for 32-bit signed integers. pub type I32 = i32; -/// Scalar for 8-byte signed integers. +/// Scalar for 64-bit signed integers. pub type I64 = i64; -/// Scalar for 16-byte signed integers. +/// Scalar for 128-bit signed integers. pub type I128 = i128; -/// Scalar for 4-byte unsigned integers. +/// Scalar for 32-bit unsigned integers. pub type U32 = u32; -/// Scalar for 8-byte unsigned integers. +/// Scalar for 64-bit unsigned integers. pub type U64 = u64; -/// Scalar for 16-byte unsigned integers. +/// Scalar for 128-bit unsigned integers. pub type U128 = u128; /// Scalar for boolean. pub type Boolean = bool; -/// Scalar for 1-byte signed integers. +/// Scalar for 8-bit signed integers. pub type I8 = i8; -/// Scalar for 1-byte unsigned integers. +/// Scalar for 8-bit unsigned integers. pub type U8 = u8; +/// Scalar for 16-bit signed integers. +pub type U16 = u16; + +/// Scalar for 16-bit unsigned integers. +pub type I16 = i16; + /// Scalar for arbitrarily-sized byte payloads. pub type Bytes = Vec;