Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functions of compound types not sortable (despite smart tag) #1450

Closed
jsimonlane opened this issue Mar 9, 2021 · 2 comments
Closed

Functions of compound types not sortable (despite smart tag) #1450

jsimonlane opened this issue Mar 9, 2021 · 2 comments

Comments

@jsimonlane
Copy link

Summary

The docs state that:

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`

drop schema if exists test cascade;
create schema test;

-- Create a basic table which we'll use to get some values.
drop table if exists test.basic_data;
create table test.basic_data(
    a int primary key,
    b int,
    c text
);

-- populate the table with a bit of dummy data
insert into test.basic_data(a, b, c) values
(1, 2, 'hi'),
(3, 4, 'there'),
(5, 6, 'friend');

-- A compound type we'll later try to query
drop type if exists test.compound_type;
create type test.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 works
drop function if exists test.f;
create function test.f() returns setof test.basic_data as $$ select * from test.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)
drop function if exists test.g;
create function test.g() returns setof test.compound_type as $$ 
    select a as x, c as y from test.basic_data 
$ language sql stable;
comment on function test.g is E'@sortable';

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, but g CANNOT be.

schema

Expected results

Expected to see an 'OrderBy' field in g.

Actual results

You don't see an 'OrderBy' field in g, but you do in f.

Additional context

MacOS Catalina, 10.15.2
Node: 15.6
Postgraphile: 14.11.0
Postgres: 13.1

@jsimonlane jsimonlane added the 🐛 bug Something isn't working label Mar 9, 2021
@benjie benjie added 💅 enhancement and removed 🐛 bug Something isn't working labels Mar 15, 2021
@benjie
Copy link
Member

benjie commented Mar 15, 2021

I've fixed the docs: graphile/graphile.github.io@63aeb64

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.

Leaving this open as a feature request.

@benjie
Copy link
Member

benjie commented Oct 4, 2023

In V5, composite types can be made sortable or filterable via the behavior system.

@benjie benjie closed this as completed Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

2 participants