hasura / graphql-engine

Blazing fast, instant realtime GraphQL APIs on your DB with fine grained access control, also trigger webhooks on database events.
https://hasura.io
Apache License 2.0
31.06k stars 2.76k forks source link

Inconsistent schema types for postgres arrays with Hasura server >= 2.29 #9902

Open psstoev opened 11 months ago

psstoev commented 11 months ago

Version Information

Server Version: 2.33.4 CLI Version (for CLI related issue):

Environment

Local Docker 2.33.4 images, Postgres v14 Database.

What is the current behaviour?

Hasura version 2.29 and above supports Postgres arrays and corresponding return and input types are marked in the GraphQL schema as e.g. [Int!], for integer[] arrays. However, with custom functions that accept arrays as arguments the input type is still marked as _int4 is the GraphQL schema.

What is the expected behaviour?

Custom functions accepting arrays as arguments should have the arrays marked as arrays in the input type.

How to reproduce the issue?

Create a table with an array column and a function that accepts array as an argument, track both:

CREATE TABLE IF NOT EXISTS ARRAYS_WITH_LENGTH(
    ARR integer[],
    LENGTH integer
);

CREATE OR REPLACE FUNCTION ADD_NEW_ARRAY(NEW_ARRAY integer[])
    RETURNS ARRAYS_WITH_LENGTH
    LANGUAGE SQL
    AS $$
    INSERT INTO arrays_with_length(arr, length)
        VALUES(new_array, array_length(new_array, 1))
    RETURNING
        *;
$$;

Inspect the schema and observe the differences between the input types:

input arrays_with_length_insert_input {
    arr: [Int!]
    length: Int
}

input add_new_array_args {
    new_array: _int4
}

Any possible solutions/workarounds you're aware of?

Adding disable_postgres_arrays to HASURA_GRAPHQL_EXPERIMENTAL_FEATURES seemed like a viable option, but it still produces inconsistent input types, _integer vs. _in4:

input arrays_with_length_insert_input {
    arr: _integer
    length: Int
}

input add_new_array_args {
    new_array: _int4
}

And I’m not aware of any other workarounds.

Keywords

postgres arrays _int4 compatibility

Fudal commented 11 months ago

I have the same problem.

Fudal commented 11 months ago

@SamirTalwar @vijayprasanna13 do you have any idea how can we manage it?

I want to update Hasura from 2.19.0 to 2.32.0 but I couldn’t. I've added disable_postgres_arrays as HASURA_GRAPHQL_EXPERIMENTAL_FEATURES to my env but now I have problem with error: variable is declared as '_int4', but used where '_integer' is expected

Fudal commented 11 months ago

@manasag any idea with that issue?

narendra-paiteq commented 1 month ago

Hi, @Fudal @psstoev have you found a solution to this issue?

Fudal commented 1 month ago

@narendra-paiteq no, I had to keep old hasura version without upgrade