Closed danielbuechele closed 7 years ago
Another, simpler option would be to add type casting here: https://github.com/postgraphql/postgraphql/blob/master/src/postgres/inventory/type/PgEnumType.ts#L33 or here: https://github.com/postgraphql/postgraphql/blob/master/src/postgres/inventory/type/PgListType.ts#L40
So that it generates either:
array['x'::article_type, 'y'::article_type]
…or:
array['x', 'y']::article_type[]
Please feel free to submit a PR adding this casting! The former is easier and so probably what we want.
If someone fancied simply testing if this works in v4 that would be super helpful 👍
(I think it will.)
Yep; it works:
$ createdb test
$ psql test
[test] # create type test_enum as enum('ONE', 'TWO', 'THREE');
CREATE TYPE
Time: 63.477 ms
[test] # create function second(options test_enum[]) returns test_enum as $$ select options[2]; $$ language sql stable;
CREATE FUNCTION
Time: 8.991 ms
[test] # select second(ARRAY['TWO', 'THREE', 'ONE']::test_enum[]);
second
--------
THREE
(1 row)
Time: 0.429 ms
$ postgraphile -c postgres://localhost/test
{
second(options: [TWO, THREE, ONE])
}
{
"data": {
"second": "THREE"
}
}
I created a procedure accepting an array of enums as argument, like this:
which creates a GraphQL field that can be queried like this:
However, this fails in SQL, saying function
searchArticles(text[])
does not exists. The problem seems to be, that the array of enums is translated to a text array. Probably because in JavaScript the argument creates an array['VIDEO','PHOTO']
, because JavaScript is not aware of existing enums, which is then transformed to SQL.On a first look, it looks like we can add some special case here: https://github.com/postgraphql/postgraphql/blob/master/src/postgraphql/schema/procedures/createPgProcedureSqlCall.ts#L36