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

Fix mutations with camelCase table names #8740

Merged
merged 1 commit into from
Nov 26, 2024

Conversation

Weiko
Copy link
Member

@Weiko Weiko commented Nov 25, 2024

Context

Some mutations are not working properly, workspaceMember soft deletion for example. workspaceMember being a camelCase table name, it's probably not propagated properly to pgql (which needs double quote for the table name to keep it as camelCase)

I didn't have time to dig too much but if the where is before softDelete, the query is WHERE workspaceMember.id = $1 while if it's after, the query becomes WHERE id = $1.
Probably due to the fact that once you call delete/softDelete/update, the standard builder (SelectQueryBuilder) becomes a DeleteQueryBuilder/etc... and filters are not handled the same way.

const nonFormattedDeletedObjectRecords = await queryBuilder
.where(`"${tableName}".id = :id`, {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already wanted to fix that bug earlier by computing the table name in the destroy endpoint but it was not done everywhere. Let's use the new fix so we don't have the compute it.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

This PR fixes issues with camelCase table names in mutations by reordering query builder method chains, particularly affecting the workspaceMember table's soft deletion functionality.

  • Reordered .where() clause to come after .softDelete() in graphql-query-delete-one-resolver.service.ts to preserve proper table name casing
  • Modified query builder chain in graphql-query-destroy-one-resolver.service.ts to simplify table name handling
  • Adjusted graphql-query-restore-one-resolver.service.ts to place .restore() before .where() for consistent casing behavior
  • Fixed issue where table names weren't properly quoted in SQL queries when using certain QueryBuilder methods

3 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings | Greptile

@charlesBochet charlesBochet merged commit 64b8fd5 into main Nov 26, 2024
19 checks passed
@charlesBochet charlesBochet deleted the c--fix-mutations-with-camel-case-table-names branch November 26, 2024 09:47
Weiko added a commit that referenced this pull request Nov 26, 2024
## Context
Some mutations are not working properly, workspaceMember soft deletion
for example. workspaceMember being a camelCase table name, it's probably
not propagated properly to pgql (which needs double quote for the table
name to keep it as camelCase)

I didn't have time to dig too much but if the `where` is before
`softDelete`, the query is `WHERE workspaceMember.id = $1` while if it's
after, the query becomes `WHERE id = $1`.
Probably due to the fact that once you call delete/softDelete/update,
the standard builder (SelectQueryBuilder) becomes a
DeleteQueryBuilder/etc... and filters are not handled the same way.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants