hasura / graphql-engine

Blazing fast, instant realtime GraphQL APIs on your DB with fine grained access control, also trigger webhooks on database events.
https://hasura.io
Apache License 2.0
31.06k stars 2.76k forks source link

citus: support relationships in a function's response #7186

Open 0x777 opened 3 years ago

0x777 commented 3 years ago

Similar to https://github.com/hasura/graphql-engine/issues/7185.

create function search_disasters(search text)
returns setof disaster as $$
begin
    return query select *
    from disaster
    where
      name ilike ('%' || search || '%');
end;
$$ language plpgsql stable;

However, trying to use a relationship will result in an error:

query function {
  search_disasters(args: {search: "sarga"}) {
    name
    affected_states {
      state_id
    }
  }
}
message: "cannot pushdown the subquery",
status_code: "0A000",
description: "Complex subqueries and CTEs cannot be in the outer part of the outer join"

We'll need to use the primary key columns of the table that the function returns and change the LHS to

select * from table_the_function_returns where pkey_columns in (select pkey_columns from function(args))

from

select * from function(args)
minhdtb commented 1 year ago

Anything update? I got the same problem when using Citus