dosco / graphjin

GraphJin - Build NodeJS / GO APIs in 5 minutes not weeks

Home Page:https://graphjin.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support `returns table (like <tablename>)` in stored procedure record returns.

shanna opened this issue · comments

I saw this example on discord:

query {
  get_oldest_users(limit: 2, user_count: 4, tag: $tag) {
    tag_name @skip(if: $skipTag)
    id
    full_name
    is_admin(user_id: 5)
  }
}

I tried it out for myself as a way to filter records by complex queries but I notice it doesn't work unless you provide all the individual columns in the return table (...) in postgres. It would be neat if return table (like users) worked as it removes a load of overhead redefining your query functions every time you modify the users table and would like to make all columns available to the graphql query.

create or replace function get_user_by_complex(arg1 text, arg2 text) returns table (like users) as $$
begin
  return query select u.*
  from users u
  where
     1=1
     -- some complex conditions: ltree, jsonb @> jsonb_...
  ;
end;
$$ language plpgsql immutable parallel safe;

-- This works and returns all the user columns.
-- select * from get_users_by_complex('foo', 'bar');

The returns table (like users) works on the postgres side in postgres14 but in graphjin over on the graphql side you get the error unknown column get_user_by_complex.<column> for any column you try to access in the result. I'm guessing because the postgres introspection graphjin does can't figure out all the column types of the table referenced in the return value.

commented

Traveling will look at this deeper next week. Just a short FYI the query you have above has changed in v3 all args have to be passed in using the args param. Eg.

get_oldest_users(limit: 2, args: { user_count: 4, tag: $tag }) {