hasura / hasura/graphql-engine
Ability to reference custom logic in Hasura's generated `BoolExp`s
- Dominant language
- TypeScript
- Stars
- 32.1k
- Forks
- 3k
- PR merge metrics
- PR metrics pending
Description
### Is your proposal related to a problem?
Currently, if a user would like to expose features such as full text search or fuzzy search in the Hasura Graphql schema, they must create a postgres function and track it within Hasura. This works up to a point, but it doesn't play nicely with Hasura's generated `BoolExp`s.
For example, say the client wishes to perform a fuzzy search on post body content. The client might perform the following pseudo graphql query:
```gql
query MySearchQuery($bodyContentQuery: String!) {
searchThreads(
args: { search: $bodyContentQuery }
) {
...fields
}
}
```
Well what if the client wishes to search for posts that contain post body content OR which were sentAt a specific time? This can't easily be done because the `$bodyContentQuery` value cannot be used in the `_or` section of a `where` BoolExp.
### Describe the solution you'd like
I desire to do something like the following:
```gql
query MySearchQuery($bodyContentQuery: String!, $sentAtTime: String!) {
searchThreads(
where: {
_or: [
{ body: { _fuzzysearch: $bodyContentQuery } },
{ sentAt: { _eq: $sentAtTime } },
]
}
) {
...fields
}
}
```
Alternatively, it would also be acceptable if I could reference [table computed fields](https://hasura.io/docs/latest/schema/postgres/computed-fields/#2-table-computed-fields) in `BoolExp`. For example
```gql
query MySearchQuery($bodyContentQuery: String!, $sentAtTime: String!) {
threads(
where: {
_or: [
{ searchThreads: { args: $bodyContentQuery } },
{ sentAt: { _eq: $sentAtTime } },
]
}
) {
...fields
}
}
```
The second approach seems more flexible than the first.
### Describe alternatives you've considered
The only alternative I'm aware of is to not use Hasura's generated `BoolExp` (i.e. not use the `where` option) and instead build equivalent custom functionality in a postgres function. This seems very time consuming.
I initially got excited thinking that [Table Computed Fields](https://hasura.io/docs/latest/schema/postgres/computed-fields/#2-table-computed-fields) might solve this problem, but they don't appear to be added as options to the relevant `BoolExp`.
Contributor guide
Research direction
Start by examining how Hasura's generated GraphQL BoolExp inputs are built and how PostgreSQL functions and table computed fields are represented. Compare the requested custom logic and computed-field examples, then define completion as allowing that logic to participate in BoolExp _or conditions while preserving the existing sentAt filter behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, postgresql
- Domain
- backend-api-design, databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100