graphql-engine icon indicating copy to clipboard operation
graphql-engine copied to clipboard

Allow filtering by computed fields

Open mikyoengine opened this issue 6 years ago • 35 comments

If you have a computed field such as full_name, it would be very useful to be able to filter by this value. E.g.

{
  users(where: { full_name: { _eq: "John Smith"}) {
  ...UserDetails
  }
}

mikyoengine avatar Jan 24 '20 20:01 mikyoengine

Yes exactly the same usecase for me. I output a datatable module and I want the user to be able to filter and sort by any value inside the datatable. Right now I have to disable those features for any computed field, which is really unintuitive.

MatthiasGrandl avatar Feb 19 '20 08:02 MatthiasGrandl

+1 now receiving "field "computed" not found in type: 'table_order_by'" when trying to sort by computed field. any chance to get this feature?

barmaley-banned avatar Mar 30 '20 15:03 barmaley-banned

Interestingly on surface there are no visible limitations because this is working

SELECT public.calculate_something(entity) AS something FROM entity
WHERE public.calculate_something(entity) = 'something'

esseswann avatar Apr 11 '20 19:04 esseswann

Just to add in on this, it could be useful to use a computed field as primary key Example: I generate a slug for my projects and I want to get them with a query like:

query {
  projects_by_pk(slug: "example") {
    id
    name
  }
}

Or

query {
  projects(where: {slug: { _eq: "example"}}) {
    id
    name
  }
}

Kosai106 avatar Apr 19 '20 17:04 Kosai106

Also related, it would be neat if we could select computed columns for permission checks.

MatthiasGrandl avatar Apr 26 '20 10:04 MatthiasGrandl

@marionschleifer @coco98 any chance of getting this into 1.3?

maxcan avatar May 11 '20 18:05 maxcan

+1

productdevbook avatar Jul 03 '20 09:07 productdevbook

Just to add in on this, it could be useful to use a computed field as primary key Example: I generate a slug for my projects and I want to get them with a query like:

query {
  projects_by_pk(slug: "example") {
    id
    name
  }
}

Or

query {
  projects(where: {slug: { _eq: "example"}}) {
    id
    name
  }
}

@Kosai106 Does this actually work?

MarcelloTheArcane avatar Jul 03 '20 10:07 MarcelloTheArcane

@MarcelloTheArcane No, it's a request.

Kosai106 avatar Jul 03 '20 15:07 Kosai106

It looks fairly simple to implement, even though I might be mistaken.

Currently, my workaround is to create a SQL View, with all my table's field, and the computed field itself.

That's ugly, and prevents you from updating the whole view (you need to switch between two GraphQL root fields), but hey at least it works in queries.

If you need it to work in mutations, you need to create a new view with your computed field, add a relationship between your root table and the view, and filter from there. It requires a JOIN, which could hurt performance on an often queried table, and will be ugly, but it will work.

Since we're already at v1.3.0-beta4, I wouldn't expect the Hasura's team to ship this feature in v1.3.0. However, if they could, it would be awesome 💯

TheMrZZ avatar Jul 06 '20 15:07 TheMrZZ

This would be a great feature!!

brittanyroddy avatar Aug 05 '20 16:08 brittanyroddy

This is a must-have for my team

gengue avatar Sep 01 '20 16:09 gengue

+1 is much needed to have this!

marcfalk avatar Sep 07 '20 13:09 marcfalk

+1 - very important for our team.

crieggalder avatar Sep 08 '20 07:09 crieggalder

+1

alisonvalente avatar Sep 18 '20 15:09 alisonvalente

Adding my voice to this. Would really love to see this added!

jrnxf avatar Oct 01 '20 04:10 jrnxf

This issue is the 4th most upvoted feature. Do you have any update on when this will be available? Please help us.

sawankumarbundelkhandi avatar Oct 21 '20 09:10 sawankumarbundelkhandi

+1

alexmarqs avatar Nov 02 '20 10:11 alexmarqs

+1

cardosojc avatar Nov 02 '20 12:11 cardosojc

+1

Victormeriqui avatar Nov 02 '20 15:11 Victormeriqui