Skip to content

Extend queryFunctions & mutationFunctions logic for custom cases #2030

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

Open
RicardoMizzta opened this issue May 9, 2025 · 3 comments
Open
Labels
feature 🚀 New feature or request

Comments

@RicardoMizzta
Copy link

Hello, congrats on this awesome lib, it is really been handy for our projects and saves a lot of time.

I have just a small question, been looking at open issues but can't really find one about this particular topic.

Most of the times, when we use a queryFn or mutationFn, we do the request and return the data directly, but in some cases, we want to do some extra logic after the response is returned. For example, on requesting lists, we want to access the headers and return a custom object, such as

const getUsersQuery = (params?: BaseListParams) => ({ queryKey: ['users', params], queryFn: async () => { try { const { data, headers } = await api.getUsersApi(params); return { data, totalCount: headers.totalCount, nextPage: headers.nextPage }; } catch (err: unknown) { throw err; } } });

Also on mutations, after we create an entity, we want to create the images after the post request is successfull, so we add this logic on the same mutationFn that creates the entity.

The bottom line is, can we add extra "code" or logic when we call the getUserOptions method or postUserMutation generated by the hey-api codegen, or this is not really correct implementation and we should really just separate the logic into separate functions and methods and call them accordingly at each step?

Thank you for the attention

I'm always available for new info or questions

@mrlubos
Copy link
Member

mrlubos commented May 9, 2025

I'd need to think about this!

@RicardoMizzta
Copy link
Author

Sure! I just think it would be a nice to have, since i think this is a common use case that other developers may eventually need, to add custom logic before the return, but i'm also not sure how to do this, maybe add a callback or something, but yeah, just giving some feedback. Thanks for the reply, will be checking in for updates!

@mrlubos
Copy link
Member

mrlubos commented May 9, 2025

Yep totally no problem, appreciate any feedback! Let's see if more people run into it and comment here, it's good that you started a new issue

@mrlubos mrlubos added the feature 🚀 New feature or request label May 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature 🚀 New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants