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

Add filter on array and jsonb field types #6784

Closed
Tracked by #6445
ijreilly opened this issue Aug 29, 2024 · 6 comments · Fixed by #7839
Closed
Tracked by #6445

Add filter on array and jsonb field types #6784

ijreilly opened this issue Aug 29, 2024 · 6 comments · Fixed by #7839
Assignees
Labels
prio: med scope: back+front Issues requiring full-stack knowledge type: feature

Comments

@ijreilly
Copy link
Collaborator

Scope & Context

So far we had left out the possibility to filter on field types involving jsonB and array columns (ex: Links, Emails...).
It is now doable thanks to the recent work that replaced pg_graphql (@Weiko ).

Let's introduce filter features for these fields !

@charlesBochet
Copy link
Member

We are still waiting on full pg_graphql deprecation to move forward on this one!

Copy link
Contributor

gitstart-app bot commented Sep 13, 2024

Here is the GitStart Ticket for this issue: https://clients.gitstart.com/twenty/5449/tickets/TWNTY-6784

@charlesBochet
Copy link
Member

@gitstart-twenty to work on this issue you currently need the IsQueryRunnerTwentyORMEnabled feature flag to be enable on your workspace

We have introduced new resolvers that do not use pg_graphql (pg_graphql does not support filter on Array fields / jsonb fields)

Please reach out to @Weiko to prepare this ticket if needed

@ijreilly
Copy link
Collaborator Author

ijreilly commented Oct 8, 2024

@lucasbordeau fyi

@charlesBochet
Copy link
Member

@ijreilly @gitstart-twenty while investigating this last week, it seems that these types are already present in the graphql schema, not sure they are applied by the graphql-api-runner though

@Weiko
Copy link
Member

Weiko commented Oct 10, 2024

@charlesBochet I've tried on main and indeed the API exposes some filters already but they are not implemented (or broken). Some are missing as well (in the schema). See screenshots below.

Json Filter

  • isFilter: allows us to filter out NULL or NOT_NULL records. [Implemented already]
  • containsFilter, this one is missing and should be very naive and not leverage jsonb comparisons but only search in the whole json (not the values). Later we might add "hasKey", "containsValues", etc... [To do]
Screenshot 2024-10-10 at 17 38 37

Array Filter

containsFilter, containsAnyFilter, notContains are self explanatory. Those are exposed via the API already but the filter is not implemented when building the ORM query so they will throw an error.
Screenshot 2024-10-10 at 17 38 19

Backend implementation

Check packages/twenty-server/src/engine/api/graphql/workspace-schema-builder/graphql-types/input folder to define Filter types. This is used to generate the types in the gql schema.
Check packages/twenty-server/src/engine/api/graphql/graphql-query-runner/graphql-query-parsers/graphql-query-filter/graphql-query-filter-condition.parser.ts to see how gql filters are parsed and converted to ORM conditions.
You can activate debug mode with DEBUG_MODE=true to see the queries that are generated or use getSql() in the query builder in GraphqlQueryFindManyResolverService if this can help.

Weiko added a commit that referenced this issue Oct 21, 2024
This PR was created by [GitStart](https://gitstart.com/) to address the
requirements from this ticket:
[TWNTY-6784](https://clients.gitstart.com/twenty/5449/tickets/TWNTY-6784).
This ticket was imported from:
[TWNTY-6784](#6784)

 --- 

### Description

- Add filter on array and jsonb field types
- We did not implement the contains any filter for arrays on the
frontend because we would need to change the UI design since this should
be an array of values, and now we have only one input

### Demo


<https://www.loom.com/share/0facf752b63f4120b5d4ea4ee9772d35?sid=d7bde469-e6a9-4298-a637-d81d40695a86>

Fixes #6784

---------

Co-authored-by: gitstart-twenty <[email protected]>
Co-authored-by: gitstart-twenty <[email protected]>
Co-authored-by: Weiko <[email protected]>
@github-project-automation github-project-automation bot moved this from 🆕 New to ✅ Done in Product development ✅ Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
prio: med scope: back+front Issues requiring full-stack knowledge type: feature
Projects
Status: ✅ Done
Development

Successfully merging a pull request may close this issue.

5 participants