1

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

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your answer! I changed type in my dart code, but I have still error: GraphQLError(message: A string is expected for type: _int4) I'm trying pass value like {1, 2, 3, 4} so it's weird why in this error is "String" type. Do you know why?
Like I mentioned in my comment, its expected that you pass it as a string. Notice how I added quotes around the the example. Its on the Hasura roadmap to have better built in support for array columns in the future but this is the way you have to do it right now

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.