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

Commit

Permalink
chore: update columntypes (#1333)
Browse files Browse the repository at this point in the history
Co-authored-by: Rashad Alston <[email protected]>
  • Loading branch information
ra0x3 and Rashad Alston authored Sep 5, 2023
1 parent d749813 commit 27538fc
Show file tree
Hide file tree
Showing 24 changed files with 509 additions and 353 deletions.
85 changes: 6 additions & 79 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions docs/src/data-types/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ Below is a mapping of GraphQL schema types to their Sway and database equivalent
| str[32] | AssetId | varchar(64) |
| str[32] | MessageId | varchar(64) |
| str[32] | Salt | varchar(64) |
| u32 | UInt4 | integer |
| u32 | U32 | integer |
| u64 | ID | bigint primary key |
| u64 | UInt8 | bigint |
| u64 | U64 | bigint |
| | Json | json |
| | Charfield | varchar(255) |
| | Blob | varchar(10485760) |
Expand All @@ -40,7 +40,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
10 changes: 5 additions & 5 deletions docs/src/project-components/schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,25 @@ In its most basic form, a Fuel indexer GraphQL schema should have a `schema` def
```graphql
type FirstThing @entity {
id: ID!
value: UInt8!
value: U64!
}

type SecondThing @entity {
id: ID!
optional_value: UInt8
optional_value: U64
timestamp: Timestamp!
}
```

The types you see above (e.g., `ID`, `UInt8`, etc) are Fuel abstractions that were created to more seamlessly integrate with the Fuel VM and are not native to GraphQL. A deeper explanation on these
The types you see above (e.g., `ID`, `U64`, etc) are Fuel abstractions that were created to more seamlessly integrate with the Fuel VM and are not native to GraphQL. A deeper explanation on these
types can be found in [the Types section](../data-types/types.md).

> Important: It is up to developers to manage their own unique IDs for each type, meaning that a data structure's `ID` field needs to be manually generated prior to saving it to the database. This generation can be as simple or complex as you want in order to fit your particular situation; the only requirement is that the developer implement their own custom generation.

## Required and Optional Fields

Required fields are denoted with a `!` following its type; for example, the `value` field of the `FirstThing` type is a `UInt8` and is required to be present for the indexer to successfully persist the entity. If a certain piece of information is essential to your use case, then you should mark that field as required.
Required fields are denoted with a `!` following its type; for example, the `value` field of the `FirstThing` type is a `U64` and is required to be present for the indexer to successfully persist the entity. If a certain piece of information is essential to your use case, then you should mark that field as required.

In contrast, optional fields are not required to be present for the indexer to persist the entity in storage. You can denote an optional field by just using the type name; for example, the `optional_value` field of the `SecondThing` type is optional, and should be a `UInt8` if present. If it's possible that a value might not always exist in the data you wish to index, consider making that the corresponding field optional. In your indexer code, you will need to use the `Option` Rust type when assigning a value to an optional field; values that are present should be assigned after being wrapped in `Some(..)` while absent values should be assigned using `None`.
In contrast, optional fields are not required to be present for the indexer to persist the entity in storage. You can denote an optional field by just using the type name; for example, the `optional_value` field of the `SecondThing` type is optional, and should be a `U64` if present. If it's possible that a value might not always exist in the data you wish to index, consider making that the corresponding field optional. In your indexer code, you will need to use the `Option` Rust type when assigning a value to an optional field; values that are present should be assigned after being wrapped in `Some(..)` while absent values should be assigned using `None`.

> Important: The `ID` field is _always_ required. An indexer **will** return an error if an optional value is used for the `ID` field.
Loading

0 comments on commit 27538fc

Please sign in to comment.