Search code examples
postgresqlflutterdartgraphqlhasura

Insert List<int> to Hasura Postgresql


How can I insert list of Integers to Hasura Postgresql?

I'm not sure what should be column_type - when I set type as "Integer[]" - that type in Hasura was automatically changed to int4[] - it might be okey, but I don't know what type I should declare in my mutation.

gqlInsert = """
    mutation InsertMutation(
      \$is_enabled: Boolean,
      \$weekdays: [Int], <-- what type should be in this place?
      \$name: String
    ) {
      insert_reminder_one(object: {
        is_enabled: \$is_enabled
        weekdays: \$weekdays
        name: \$name
      }) {
        id
      }
    }
    """;

If I have type as [Int] I have error like that:

GraphQLError(message: variable repeated_weekdays of type [Int] is used in position expecting _int4

Solution

  • The expected type is listed in your error message. It's supposed to be _int4. The underscore prefix on the front indicates its an array (a Hasura convention).

    Hasura doesn't have great support at the moment for native array columns and you're supposed to pass array values in as a Postgres array literal string as documented here.

    It should be $weekdays: _int4 and the value you pass in should look like '{1, 2, 3}' (as a string).

    You might want to consider using a jsonb column instead of an array for now.