Skip to content

Commit

Permalink
chore/breaking: simplify scalar types (#1388)
Browse files Browse the repository at this point in the history
* chore: simplify scalar types

* rename xstring to string

* update tests

* updates

* updates

* fix snapshot tests

---------

Co-authored-by: Rashad Alston <rashad@Rashads-Air.lan>
  • Loading branch information
ra0x3 and Rashad Alston authored Sep 29, 2023
1 parent 3afad10 commit f02438a
Show file tree
Hide file tree
Showing 58 changed files with 650 additions and 989 deletions.
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/src/designing-a-schema/directives.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ The `@join` directive is used to relate a field in one type to others by referen
```graphql
type Book @entity {
id: ID!
name: Charfield! @unique
name: String! @unique
}

type Library @entity {
Expand Down
4 changes: 2 additions & 2 deletions docs/src/designing-a-schema/relationships.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Let's learn how to use each foreign key type by looking at some GraphQL schema e
```graphql
type Library @entity {
id: ID!
name: Charfield!
name: String!
}

type Book @entity {
Expand All @@ -35,7 +35,7 @@ Given the above schema, two entities will be created: a `Book` entity, and a `Li
```graphql
type Library @entity {
id: ID!
name: Charfield! @unique
name: String! @unique
}

type Book @entity {
Expand Down
32 changes: 12 additions & 20 deletions docs/src/designing-a-schema/scalars.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,23 @@ The Fuel indexer has a collection of GraphQL scalars that cover virtually any va
--- | --- | ---
| Address | `u8[32]` |
| AssetId | `u8[32]` |
| Blob | `Vec<u8>` | Byte blob of arbitary size |
| BlockId | `u8[32]` | 32-byte block ID |
| Boolean | `bool` |
| Bytes4 | `u8[4]` |
| Bytes8 | `u8[8]` |
| Bytes | `Vec<u8>` | Byte blob of arbitary size |
| Bytes32 | `u8[32]` |
| Bytes4 | `u8[4]` |
| Bytes64 | `u8[64]` |
| Charfield | `String` | String of arbitrary size |
| Bytes8 | `u8[8]` |
| ContractId | `u8[32]` |
| HexString | `Vec<u8>` | Byte blob of arbitrary size |
| I128 | `i128` |
| I32 | `i32` |
| I64 | `i64` |
| I8 | `i8` |
| ID | `SizedAsciiString<64>` | Alias of `UID`
| Int1 | `i8` |
| Int4 | `i32` |
| Int8 | `i64` |
| Int16 | `i128` |
| Json | `String` | JSON string of arbitary size |
| MessageId | `u8[32]` |
| Nonce | `u8[32]` |
| Salt | `u8[32]` |
| Signature | `u8[64]` | 64-byte signature |
| Tai64Timestamp | `Tai64` | `Tai64` timestamp |
| Timestamp | `u64` |
| U128 | `u128` |
| U32 | `u32` |
| U64 | `u64` |
| U8 | `u8` |
| UID | `SizedAsciiString<64>` | 32-byte unique ID |
| UInt1 | `u8` |
| UInt4 | `u32` |
| UInt8 | `u64` |
| UInt16 | `u128` |
| Virtual | `String` | Used to store types tagged with `@virtual` directive |
| String | `String` | String of arbitrary size |
10 changes: 5 additions & 5 deletions docs/src/designing-a-schema/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Object types are the most commonly used type in indexer GraphQL schema. Each obj
type Account @entity {
id: ID!
address: Address!
balance: UInt8!
balance: U64!
}
```

Expand Down Expand Up @@ -69,14 +69,14 @@ enum TransactionLabel {

type CreateTransaction @entity {
id: ID!
bytecode_length: UInt8!
bytecode_length: U64!
contract_id: ContractId!
label: TransactionLabel!
}

type ScriptTransaction @entity {
id: ID!
maturity: UInt8!
maturity: U64!
label: TransactionLabel!
}

Expand All @@ -94,10 +94,10 @@ The `Transaction` union type above, will internally produce the following object
```graphql
type Transaction @entity {
id: ID!
bytecode_length: UInt8!
bytecode_length: U64!
contract_id: ContractId!
label: TransactionLabel!
maturity: UInt8!
maturity: U64!
metadata: Json
}
```
Expand Down
8 changes: 4 additions & 4 deletions docs/src/indexing-custom-types/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,14 @@ To index the contracts and store information about our Sway types in the databas
```graphql
type AddEntity @entity {
id: ID!
value: UInt8!
updated_total: UInt8!
value: U64!
updated_total: U64!
}

type SubtractEntity @entity {
id: ID!
value: UInt8!
updated_total: UInt8!
value: U64!
updated_total: U64!
}
```

Expand Down
8 changes: 4 additions & 4 deletions docs/src/project-components/schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ Below is a sample GraphQL schema for a Fuel indexer.

```graphql
type Metadata @entity(virtual: true) {
imageUrl: Charfield!
data: Blob
imageUrl: String!
data: Bytes
}

type Account @entity {
id: ID!
address: Address!
index: UInt8!
index: U64!
metadata: Metadata
}

type Wallet @entity {
id: ID!
name: Charfield!
name: String!
accounts: [Account!]!
}
```
Expand Down
8 changes: 4 additions & 4 deletions docs/src/querying/basic-queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,24 +90,24 @@ We'll start with the following example schema:
```graphql
type City @entity {
id: ID!
name: Charfield!
name: String!
}

type Library @entity {
id: ID!
name: Charfield!
name: String!
city: City!
}

type Book @entity {
id: ID!
title: Charfield!
title: String!
library: Library!
}

type Character @entity {
id: ID!
name: Charfield!
name: String!
book: Book!
}
```
Expand Down
35 changes: 13 additions & 22 deletions docs/src/storing-records/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,25 @@ Below is a mapping of GraphQL schema types to their Sway and database equivalent
--- | --- | ---
| Address | `b256` | varchar(64) |
| AssetId | `u8[32]` | varchar(64) |
| Blob | `str[]` | varchar(10485760) |
| BlockId | | varchar(64) |
| Boolean | `bool` | boolean |
| Bytes4 | `str[4]` | varchar(8) |
| Bytes8 | `str[8]` | varchar(16) |
| Bytes | `str[]` | varchar(10485760) |
| Bytes32 | `str[32]` | varchar(64) |
| Bytes4 | `str[4]` | varchar(8) |
| Bytes64 | `str[64]` | varchar(128) |
| Charfield | `str[]` | varchar(255) |
| Bytes8 | `str[8]` | varchar(16) |
| ContractId | `b256` | varchar(64) |
| HexString | `str[]` | varchar(10485760) |
| I128 | | numeric(39,0) |
| I32 | `u32` | integer |
| I64 | `u64` | bigint |
| I8 | `u8` | integer |
| ID | | varchar(64) primary key |
| Int1 | `u8` | integer |
| Int4 | `u32` | integer |
| Int8 | `u64` | bigint |
| Int16 | | numeric(39,0) |
| Json | `str[]` | json |
| MessageId | `str[32]` | varchar(64) |
| Nonce | `str[32]` | varchar(64) |
| Salt | `str[32]` | varchar(64) |
| Signature | `str[64]` | varchar(128) |
| Tai64Timestamp | | varchar(128) |
| Timestamp | `u64` | timestamp |
| U128 | | numeric(39, 0) |
| U32 | `u32` | integer |
| U64 | `u64` | numeric(20, 0) |
| U8 | `u8` | integer |
| UID | | varchar(64) |
| UInt1 | `u8` | integer |
| UInt4 | `u32` | integer |
| UInt8 | `u64` | numeric(20, 0) |
| UInt16 | | numeric(39, 0) |
| Virtual | | json |
| String | `str[]` | varchar(255) |

## Example

Expand All @@ -59,7 +50,7 @@ The corresponding GraphQL schema to mirror this `Event` struct would resemble:
type Event @entity {
id: ID!
account: Address!
block_height: UInt8!
block_height: U64!
}
```

Expand Down
Loading

0 comments on commit f02438a

Please sign in to comment.