Icon LinkTypes

Below is a mapping of GraphQL schema types to their Sway and database equivalents.

Sway TypeGraphQL Schema TypePostgres Type
b256Addressvarchar(64)
b256ContractIdvarchar(64)
boolBooleanbool
i64Timestamptimestamp
str[]Blobbytes
str[4]Bytes4varchar(16)
str[8]Bytes8varchar(64)
str[32]Bytes32varchar(64)
str[32]AssetIdvarchar(64)
str[32]MessageIdvarchar(64)
str[32]Saltvarchar(64)
u32UInt4integer
u64IDbigint primary key
u64UInt8bigint
Jsonjson
Charfieldvarchar(255)
Blobvarchar(10485760)

Icon LinkExample

Let's define an Event struct in a Sway contract:

struct Event {
    id: u64,
    address: Address,
    block_height: u64,
}

The corresponding GraphQL schema to mirror this Event struct would resemble:

type Event {
    id: ID!
    account: Address!
    block_height: UInt8!
}

And finally, this GraphQL schema will generate the following Postgres schema:

                                           Table "schema.event"
    Column   |     Type    | Collation | Nullable | Default | Storage  | Compression | Stats target | Description
--------------+-------------+-----------+----------+---------+----------+-------------+--------------+-------------
 id           |    bigint   |           | not null |         | plain    |             |              |
 block_height |    bigint   |           | not null |         | plain    |             |              |
 address      | varchar(64) |           | not null |         | plain    |             |              |
 object       |    bytea    |           | not null |         | extended |             |              |
Indexes:
    "event_pkey" PRIMARY KEY, btree (id)
Access method: heap
Icon ListDetailsOn this page