You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Functions returning SETOF a composite type (e.g. a table type, record type, or another type with "column"-like attributes): adds the orderBy argument to this connection, allowing to sort the set by its columns/attributes.
HOWEVER: an orderBy field does not appear when I created my own composite data type using CREATE TYPE.
This commit put the sortablility in place -- however, it only ever tested record types from tables, and not custom created ones. This is likely why the bug got through.
Steps to reproduce
Create the following test database:
-- All this occurs in a database called 'test_db' -- run `createdb test_db`dropschema if exists test cascade;
createschematest;
-- Create a basic table which we'll use to get some values.droptable if exists test.basic_data;
createtabletest.basic_data(
a intprimary key,
b int,
c text
);
-- populate the table with a bit of dummy datainsert intotest.basic_data(a, b, c) values
(1, 2, 'hi'),
(3, 4, 'there'),
(5, 6, 'friend');
-- A compound type we'll later try to querydroptype if exists test.compound_type;
createtypetest.compound_type as (
x int,
y text
);
comment on type test.compound_type is E'@sortable'; -- Hail Mary comment, hoping it would work.-------------------------------------------- This IS SORTABLE: A basic table select function worksdropfunction if exists test.f;
createfunctiontest.f() returns setof test.basic_dataas $$ select*fromtest.basic_data $$ language sql stable;
comment on function test.f is E'@sortable';
-- However, this function is NOT sortable: a function returning a compound selection is NOT sortable (no orderBy field)dropfunction if exists test.g;
createfunctiontest.g() returns setof test.compound_typeas $$
select a as x, c as y fromtest.basic_data
$ language sql stable;
comment on function test.g is E'@sortable';
Order/condition types are only generated for selectable types currently; so although the @filterable/@Sortable comments enable the use of these types, since the types don't exist nothing happens.
Summary
The docs state that:
HOWEVER: an
orderBy
field does not appear when I created my own composite data type usingCREATE TYPE
.This commit put the sortablility in place -- however, it only ever tested record types from tables, and not custom created ones. This is likely why the bug got through.
Steps to reproduce
Create the following test database:
A little script to start the server:
npx postgraphile \ -c postgres://localhost/test_db \ --schema "test" \ --enhance-graphiql \ --allow-explain \ --watch
Below is a screenshot from the PostGraphIQL query explorer. Note that function
f
CAN be sorted, butg
CANNOT be.Expected results
Expected to see an 'OrderBy' field in
g
.Actual results
You don't see an 'OrderBy' field in
g
, but you do inf
.Additional context
MacOS Catalina, 10.15.2
Node: 15.6
Postgraphile: 14.11.0
Postgres: 13.1
The text was updated successfully, but these errors were encountered: