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

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

Open
shanna opened this issue Mar 9, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@shanna
Copy link

shanna commented Mar 9, 2023

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.

@shanna shanna added the enhancement New feature or request label Mar 9, 2023
@shanna shanna changed the title Support like in stored procedure record returns. Support returns table (like <tablename>) in stored procedure record returns. Mar 9, 2023
@dosco
Copy link
Owner

dosco commented Mar 11, 2023

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 }) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants