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

Query key different in generated prefetch.ts vs generated queries.ts #121

Closed
TomWebbio opened this issue May 24, 2024 · 2 comments
Closed

Comments

@TomWebbio
Copy link

Describe the bug
I generated the files for nextjs approuter using fetch. I noticed the prefetch isnt working, because the queryKey is generated differently in the generated code, meaning that React-query think it's 2 different queries.

See the querykey in the prefetch.ts:

queryClient.prefetchQuery({ queryKey: [ Common.useQuestionairesServiceQuestionaireControllerFindKey, [{ filterId, limit, page, search, searchBy, sortBy }] ], queryFn: () => QuestionairesService.questionaireControllerFind({ filterId, limit, page, search, searchBy, sortBy }) });

Now see the querykey in the queries.ts:

useQuery<TData, TError>({ queryKey: Common.UseQuestionairesServiceQuestionaireControllerFindKeyFn( { filterId, limit, page, search, searchBy, sortBy }, queryKey ), queryFn: () => QuestionairesService.questionaireControllerFind({ filterId, limit, page, search, searchBy, sortBy }) as TData, ...options });

This results in 2 different keys in queries:
image

To Reproduce
Steps to reproduce the behavior:

Generate the files using this script:

"codegen": "rimraf ./openapi && openapi-rq -i https://our-url/api.json -c fetch && prettier --write .",

I can easily fix this in the generated code by using the same querykey generation method in the queries.ts as in the prefetch.ts

If there's any way for you guys to fix this, or to give me a solid work around, that'd be great!

@7nohe
Copy link
Owner

7nohe commented May 26, 2024

This is a duplicate of #102. Currently working on #103.

@TomWebbio
Copy link
Author

Thanks, I will close this issue and keep track of those.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants