hasura / hasura/graphql-engine
Inconsistent schema types for postgres arrays with Hasura server >= 2.29
- Dominant language
- TypeScript
- Stars
- 32.1k
- Forks
- 3k
- PR merge metrics
- PR metrics pending
Description
### 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:
```sql
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:
```graphql
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`:
```graphql
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
Contributor guide
Research direction
Reproduce the issue with the provided PostgreSQL table and custom function on Hasura 2.33.4, then inspect the generated GraphQL schema for the insert input and function argument types. The work is done when array arguments for custom functions use the same array representation as corresponding table inputs, including when the experimental PostgreSQL array setting is enabled.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, postgres
- Domain
- api, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100