barrymichaeldoyle/supabase-react-query-codegen

Improving the hook naming conventions to deal with table names like `parties`, `people` etc.

Closed this issue · 1 comments

Motivation

I want to open this project up for potential new contributors, so here's a nice first issue.

What to change

Currently we have a toHookName function in our project that is used to name the hooks based off the table names in our schema.

The will take a table like users and generate hooks like useGetUser or useGetAllUsers.

However, if we have a table like people, it generates useDeletePeopl when it should actually be useDeletePerson, bare in mind that useGetAllPeople should remain unchanged. Another example is a table called parties, this generates useDeletePartie, when it should be useDeleteParty.

There might not be a silver bullet solution for this, but there may be useful libraries out there for de-pluralizing words so that our hook names. That's up to you to do the research.

Tests

When coming up for a solution, please also add test cases for the people and parties table name cases. The test file can be found here.

How to contribute

  • Please fork this project and then clone it locally.
  • Assuming you're using VSCode, the recommended extensions should pop up and I highly encourage you to download them.
  • Create a new branch called hook-naming-conventions.
  • Run npm install to install required node_modules
  • Make sure that the tests are all passing by running npm run tests
  • Add new test cases for people and parties for the desired result and run them (expect the non-GetAll cases to fail)
  • Come up with a neat solution
  • Retest to make sure the new cases now pass (and that old cases still work)
  • Commit and push your changes and open a PR linking to this issue.

Conclusion

Good luck and thank you!

Please don't hesitate to ask questions here!

I've ended up resolving this using the pluralize npm library.