1

I have a table I created in the Hasura console. A few of the columns are integer int types and I get the expected data type: Maybe<Scalars['Int']>.

However, a few needed to be an array of integers so I created those in the Hasura SQL tab:

ALTER TABLE my_table
    add my_ids integer[];

If I populate those in GraphiQL with the following query variable everything works just fine:

{
  "my_ids": "{1200, 1201, 1202}",
}

However, when I try to make the same request from my front-end client, I received the following error: A string is expected for type : _int4. Looking at the datatype, it is slightly different than the preset (in the data type dropdown) integer types: Maybe<Scalars['_int4']>.

Is there a way to get the array of integers to be Maybe<Scalars['Int']> like the preset integer types? Or if there isn't, how can resolve the issue with my request throwing errors for this _int4 type?

3
  • Are you making the request using "{1200, 1201, 1202}" i.e. as a string? or are you trying to use a an array? i.e. [1200, 1201, 1202] Commented May 19, 2020 at 19:17
  • The values are being returned to me as integers when I query for them. I followed the PostgreSQL documentation that was referenced from the Hasura docs link. Commented May 19, 2020 at 19:49
  • Actually, It looks like they are not available yet. github.com/hasura/graphql-engine/pull/2243 You'll have to use JSONB for now. Commented May 19, 2020 at 23:03

1 Answer 1

1

Hasura cannot process array but it can process array literals.

I've written a function to help you to transform your array into array literal before mutation:

const toArrayLiteral = (arr) => (JSON.stringify(arr).replace('[', '{').replace(']', '}'))
...
myObject.array = toArrayLiteral(myObject.array) // will make ['friend'] to {'friend'}

Good luck

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

Comments

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.