feat(hasura): add support for Hasura JSONB/array operators and arbitr…#7307
feat(hasura): add support for Hasura JSONB/array operators and arbitr…#7307sytabaresa wants to merge 1 commit intorefinedev:mainfrom
Conversation
🦋 Changeset detectedLatest commit: a1a97fc The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
alicanerdurmaz
left a comment
There was a problem hiding this comment.
Hey @sytabaresa, thanks for the PR! JSONB/array operator support is a good addition.
A few things:
- The fallback is a breaking change
Previously, unknown operators threw an error (throw new Error("Operator X is not supported")). Now they silently pass through. Users who rely on catching this error will break. Was this intentional? If so, the changeset should be major, not minor. But we don't want to release major just for this.
I'd prefer keeping the error for unknown operators. If someone needs a custom operator, they can extend the hasuraFilters map.
- Missing tests for generateNestedFilterQuery
Tests were added for handleFilterValue only. Can you add tests for the new JSONB operators going through generateNestedFilterQuery too?
- Small typo
"Hashura" in the docs should be "Hasura".
Description
This PR introduces explicit support for Postgres JSONB and array operators (
_contains,_contained_in,_has_key,_has_keys_any, and_has_keys_all) to the@refinedev/hasuradata provider. Additionally, it adds robust fallback handling for arbitrary generic operators.PR Checklist
Bugs / Features
What is the current behavior?
Currently, trying to use essential JSONB or array operators in filters causes the data provider to throw an "Operator X is not supported" error. Users are restricted to a highly specific subset of CrudOperators available in the core library mapping, limiting their ability to interface fully with Hasura's rich querying syntax.
What is the new behavior?
The
hasuraFiltersmapping and generateFilters.ts now officially support the missing JSONB/array operators.Furthermore, instead of explicitly throwing errors on unrecognized operators, the generateNestedFilterQuery function now gracefully passes arbitrary operators through to the query payload. It intelligently acts as a fallback layer, attaching a
_prefix if needed, ensuring developers can invoke Custom Hasura Operations seamlessly out-of-the-box.Notes for reviewers
Tested cases covering objects and array filters for the new
_contains/_contained_inoperators were added ingenerateFilters.spec.ts.