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

TanStack react query v5 marks queryKey as required #975

Closed
leniency opened this issue Oct 20, 2023 · 21 comments
Closed

TanStack react query v5 marks queryKey as required #975

leniency opened this issue Oct 20, 2023 · 21 comments
Assignees
Labels
bug Something isn't working

Comments

@leniency
Copy link
Contributor

This makes adding additional query options annoying as it forces overriding the query key that gets set in the generated code.

This only appears to affect queries and not mutations.

@leniency leniency changed the title TanStack v5 marks queryKey as required TanStack react query v5 marks queryKey as required Oct 20, 2023
@melloware melloware added the bug Something isn't working label Oct 20, 2023
@melloware
Copy link
Collaborator

This was released in 6.19.1 can you test @leniency please?

@leniency
Copy link
Contributor Author

Yup all good now, thanks!

@ruiaraujo012
Copy link

ruiaraujo012 commented Jan 4, 2024

Still happens, any fix?
Version 6.22.1 doesn't have the problem.

@melloware
Copy link
Collaborator

Not many changes since 6.22.1 so look through the commits and see if you can spot it: v6.22.1...master

@ruiaraujo012
Copy link

ruiaraujo012 commented Jan 4, 2024

The generated code is different, something is removing the Partial<>

(6.23.0) query?: UseQueryOptions<Awaited<ReturnType<typeof getDomainValues>>, TError, TData>;
(6.22.1) query?: Partial<UseQueryOptions<Awaited<ReturnType<typeof getDomainValues>>, TError, TData>>;

@melloware
Copy link
Collaborator

@anymaniax I don't see any commit between 6.22.1 and 6.23.0 that would affect this Partial not being generated? @Maxim-Mazurok @codebutler @soartec-lab

@soartec-lab
Copy link
Member

@melloware

So you want to know the reason why Partial is no longer generated?
if me question is correct, I'll search into it. and, I will also make corrections if possible.

I also read this as well.

@melloware
Copy link
Collaborator

Yes I don't see what changed that would cause this between 6.22.1 and 6.23.0.

@soartec-lab
Copy link
Member

@maapteh @ruiaraujo012 @melloware

Hi, I checked the operation using PetStore, and the source code was generated with Partial existing as intended.

export const getListPetsQueryOptions = <TData = Awaited<ReturnType<typeof listPets>>, TError = AxiosError<Error>>(params?: ListPetsParams, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof listPets>>, TError, TData>>, axios?: AxiosRequestConfig}
) => {

using orval version is bellow:

$ npm list --depth=0 | grep orval
+-- orval@6.23.0

I also checked the source code, but could not find any part that would reproduce the problem.
If possible, could you please share the minimal OpenAPI definition file?

@ruiaraujo012
Copy link

You're right, I tried again with v6.23.0, and it worked, it created the Partial.
I don't know what happened here, but it's working. Sorry for wasting your time.

@soartec-lab
Copy link
Member

@ruiaraujo012
it's okay. thank you for retry. I'm glad it went well 🙌

@maapteh
Copy link

maapteh commented Jan 5, 2024

I thought this would be an easy one. But not. When i isolate the package from my pnpm monorepo and only install what is used in the setup for this generating and just use my own open-api yaml and the petstore yaml from your codebase i do see the Partial.

https://github.com/maapteh/orval-maybe-bug/blob/main/src/api/index.ts#L159
so there it is correct :(

@soartec-lab
Copy link
Member

@maapteh

Thank you for checking too.
Is it okay to conclude that this is not a bug and end the discussion on this issue? And if you have any problems, could you open a new issue by sharing your OpenAPI definition and generated codebase?

@maapteh
Copy link

maapteh commented Jan 5, 2024

Yes i will ask some extra eyes in our monorepo, the weird thing is that when i run pnpm why i do see the correct versions :(
Thanks for taking the time btw!!! much appreciated

@maapteh
Copy link

maapteh commented Jan 5, 2024

found the cullprit.

  const hasQueryV5 = true /* query.version === 5 || isQueryV5(
    context.packageJson,
    outputClient
  ); */

The V5 version detection was always false. When i override it to true i saw the Partial. Now i have to look why in a pnpm monorepo it cant find the correct version, which has been set in the workspace root (one of the requirements when we build with Bazel unfortunately).

For now i just also add it to the workspace itself... :) took me too much time to figure out it was figuring out the correct version itself. Maybe nice to log the version while creating the react-query to confirm this visually :)

@anymaniax
Copy link
Collaborator

anymaniax commented Jan 5, 2024

@maapteh thanks for the investigation. Great idea to add the version detected when running. Could you create a feature request for that please? Like that we can also add a warning when we don't find it and provide the default one

@maapteh
Copy link

maapteh commented Jan 5, 2024

Thanks for the wonderful work Victor. Ticket is created at #1144

@tlrobinson
Copy link

I had the same issue when running Orval in a npm workspace that had react-query as a peerDependency. It would be nice if it correctly detected that.

@anymaniax
Copy link
Collaborator

@tlrobinson you can specify which version you want in the config too now

@NielsCodes
Copy link

NielsCodes commented Apr 17, 2024

@tlrobinson you can specify which version you want in the config too now

Could you show an example? I don't see this version option mentioned anywhere in the docs or examples.

I am facing the same issue. I have a PNPM Workspace, which uses Orval to generate the hooks for my frontend package based on the OpenAPI spec of the backend package. Since the generation runs on the Workspace level and not in my frontend package itself, I assume this version check is failing.

@anymaniax
Copy link
Collaborator

something like this

 module.exports = {
   petstore: {
     output: {
       ...
       override: {
         query: {
           version: the version you want
         },
       },
     },
     ...
   },
 };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants