hasura / hasura/graphql-engine
Introduce a mechanism to allow subqueries to inherit filters from ancestor queries
- Dominant language
- TypeScript
- Stars
- 32.1k
- Forks
- 3k
- PR merge metrics
- PR metrics pending
Description
### Is your proposal related to a problem?
My team and I find the way filtering relationships works in Hasura not intuitive which can lead to performance problems.
### Describe the solution you'd like
A new keyword or some other mechanism to control the behaviour in order to have filtering apply to nested queries / relationships.
### Describe alternatives you've considered
Here's a simplified query of a problem we recently discovered on production which was causing the CPU on our DB to pin at 100%:
```
query DeviceDetailsQuery($deviceId: uuid!) {
device(where: { id: { _eq: $deviceId } }) {
id
serial
qa_reports(order_by: { created_at: desc }) {
body
status
id
created_at
}
device_sensor_tests(order_by: { created_at: desc }) {
started_at
ended_at
}
}
}
```
Here's the a simplified query demonstrating the solution we opted for:
```
query DeviceDetailsQuery($deviceId: uuid!) {
device(where: { id: { _eq: $deviceId } }) {
id
serial
qa_reports(where: { id: { _eq: $deviceId } }, order_by: { created_at: desc }) {
body
status
id
created_at
}
device_sensor_tests(where: { id: { _eq: $deviceId } }, order_by: { created_at: desc }) {
started_at
ended_at
}
}
}
```
This works and resolves the performance issue, but it would be nice to have subqueries inherit the filtering of their parents / ancestors, rather than having to specify them manually at each level as illustrated above with `deviceId`.
Contributor guide
Assessment
This issue has not been assessed yet.