Why Hasura Has No array Type
Hasura exposes a type dropdown for row columns, but array and map are not among its options. The concept of an array can still be captured, and Hasura offers a few distinct routes to it. Each has slightly different benefits. The three approaches below start with a literal Postgres array, move to a relational alternative, and finish with JSONB.
Option A: Postgres Arrays, Declared by Hand
Although Hasura does not list array as a type, selecting "Text" and appending square brackets to the type name produces a text[] column. Hasura then prompts you to populate the array in one of two ways.
["one", "two"]
// or
{"one", "two"}
![insertion of row with type {"foo", "bar"} or ["foo", "bar"]](https://css-tricks.com/wp-content/uploads/2020/12/CleanShot-2020-12-12-at-20.00.50@2x.png)
Option B: Model the Array as a Relationship
A second route is to store the elements as rows in a second table and connect it to the original one.
- In the original table, create the row that will hold a text value (or an integer, or whatever the data requires).
- Use Add Table in the sidebar to create a new table with a
typethat matches thetypeyou need. - Open the Relationships tab, choose Array Relationship, give it a name, and point it at the original table.
The link is made between the id of the first table and the id of the table you just created.

After saving, the relationship appears in the same tab, with an arrow showing its direction.
users.gameId → favoriteGames.id
The array can then be queried from the GraphiQL tab.

Option C: Store the Array in a JSONB Column
Picking JSONB from the type dropdown is a third approach, and it can be notably performant. Once the column exists, Hasura prompts for the array contents in much the same way it does for text[].

A filled-in column looks like this:

Beyond returning the arrays in a query, JSONB lets you search by tag across multiple indexes, and GraphiQL makes that easy to explore. Here the tags are filtered to those containing "animation":
query MyQuery {
codesamples(where: {tags: {_contains: "animation"}}) {
userId
name
id
}
}

That kind of lookup is not necessarily performant out of the box, especially once the data volume grows. The fix is to declare which fields should be indexed: open the Data tab, choose the SQL group in the side panel, and define the index there. In this example the index goes on the tags field.
create index codesample_gin on codesamples using gin(tags)
Running the statement applies the index to that lookup, which makes future queries against it more performant.
Choosing Between Them
None of the three methods is exclusive of the others. Declaring text[] keeps the values inside a single column, the relationship approach spreads them across related rows, and JSONB keeps them in one document-shaped field that supports indexed tag searches once an index is defined.



