Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

Commit

Permalink
chore: document U16 entity
Browse files Browse the repository at this point in the history
  • Loading branch information
ra0x3 committed Nov 28, 2023
1 parent fbe5355 commit c815907
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 13 deletions.
1 change: 1 addition & 0 deletions docs/src/designing-a-schema/scalars.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
2 changes: 2 additions & 0 deletions packages/fuel-indexer-lib/src/graphql/base.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ scalar Json
scalar U128
scalar U32
scalar U64
scalar I16
scalar U16
scalar U8
scalar UID
scalar String
Expand Down
20 changes: 19 additions & 1 deletion packages/fuel-indexer-schema/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,20 @@ pub enum FtColumn {
ContractId(Option<ContractId>),
Enum(Option<String>),
I128(Option<I128>),
I16(Option<I16>),
I32(Option<I32>),
I64(Option<I64>),
I8(Option<I8>),
ID(Option<UID>),
Identity(Option<Identity>),
Json(Option<Json>),
String(Option<String>),
U128(Option<U128>),
U16(Option<U16>),
U32(Option<U32>),
U64(Option<U64>),
U8(Option<U8>),
UID(Option<UID>),
String(Option<String>),
}

impl FtColumn {
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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());
Expand All @@ -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]
Expand Down Expand Up @@ -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());
Expand All @@ -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]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: packages/fuel-indexer-schema/src/lib.rs
expression: tai64_timestamp.query_fragment()
expression: uint2.query_fragment()
---
"'0000000000000000'"
"30840"

Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ type Book @entity {
type Sponsor @entity {
id: ID!
name: String! @unique
amount: U64!
amount: U16!
representative: Person!
}

Expand Down
24 changes: 15 additions & 9 deletions packages/fuel-indexer-types/src/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>;

Expand Down

0 comments on commit c815907

Please sign in to comment.