Types

Below is a mapping of GraphQL schema types to their Postgres equivalents, referencing Postgres 14 data types.

Sway TypeGraphQL Schema TypePostgres Type
u64IDbigint primary key
b256Addressvarchar(64)
str[4]Bytes4varchar(16)
str[8]Bytes8varchar(64)
str[32]Bytes32varchar(64)
str[32]AssetIdvarchar(64)
b256ContractIdvarchar(64)
str[32]Saltvarchar(64)
u32Int4integer
u64Int8bigint
u64Timestamptimestamp
str[]Blobbytes

Example

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

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

Our GraphQL schema should resemble:

type Event {
    id: ID!
    account: Address! @indexed
    block_height: Int8! @indexed
}

This will generate the following Postgres schema:

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

The source code for these types can be found here.