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

Filtering on computed table type column #131

Open
ekulabuhov opened this issue Jun 7, 2020 · 4 comments
Open

Filtering on computed table type column #131

ekulabuhov opened this issue Jun 7, 2020 · 4 comments

Comments

@ekulabuhov
Copy link

Thank you for making this amazing library!

I wonder what's the reason for not supporting table types in computed columns?

@PaulMcMillan
Copy link

I also am wondering about this, I think this is what I need.

@lcalisto
Copy link

lcalisto commented Nov 6, 2020

Are there any plans to add this functionality? I also wonder whats the reason behind this. I definitely need this feature.

@mattbretl
Copy link
Member

If someone can provide an example SQL schema and GraphQL query you'd like to see supported, I can try to dig into this.

Are you thinking of a function similar to this one from the test suite?

create function p.filterable_computed_child(f p.filterable) returns p.child as $$
  select p.child.*
  from p.child
  where filterable_id = f.id
  limit 1;
$$ language sql stable;

If so, would the intent be to allow filtering on one of more columns of p.child?

@lucassith
Copy link

lucassith commented Oct 24, 2022

@mattbretl It seems that I have similar problem/request.

Let's say I have following DB structure:

create table users (
  id varchar NOT NULL
);

create table posts (
  created_by varchar  NOT NULL,
  updated_by  varchar
);

create function "users_postsByCreatedOrUpdatedBy"(usr users)
            returns setof posts as $$
            select posts.*
            from posts
            where usr.id = posts.created_by or usr.id =  posts.updated_by
        $$ language sql stable;

insert into users (id) values ('1');
insert into users (id) values ('2');
insert into users (id) values ('3');
insert into users (id) values ('4');

insert into posts (created_by, updated_by) values ('1', null);
insert into posts (created_by, updated_by) values ('3','4');

I would like to call a following query:

query MyQuery {
  allUsers(filter: {postsByCreatedOrUpdatedByExist: true}) {
    edges {
      node {
        id
      }
    }
  }
}

I can see that the filter appears when I create the relation between created_by and user or updated_by and user, but my requirement is to find users who have created or updated at lest one post. In this example, I should see only users with ids 1, 3 and 4.

PS. I have explicitly set graphileBuildOptions but the Exist filter doesn't appear when I create computed field like described above.

graphileBuildOptions: {
  connectionFilterComputedColumns: true,
  connectionFilterSetofFunctions: true,
  connectionFilterRelations: true,
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants