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 is not compatible with asClass services #1090

Closed
prenaissance opened this issue Sep 25, 2024 · 5 comments · Fixed by #1096
Closed

@tanstack/react-query is not compatible with asClass services #1090

prenaissance opened this issue Sep 25, 2024 · 5 comments · Fixed by #1096
Labels
bug 🔥 Something isn't working prioritized 🚚 This issue has been prioritized and will be worked on soon

Comments

@prenaissance
Copy link

Description

Turning on both asClass services and the tanstack query plugin resulting in wrong imports in the react-query.gen.ts file:

import {
  client,
  getFlatServiceEp1, /* Module '"../services.gen"' has no exported member 'getFlatServiceEp1' */
  getFlatServiceEp2, /* Module '"../services.gen"' has no exported member 'getFlatServiceEp2' */
} from "../services.gen";

Reproducible example or configuration

import { defineConfig } from "@hey-api/openapi-ts";

export default defineConfig({
  client: "@hey-api/client-fetch",
  input: "http://localhost:3080/swagger/json",
  output: {
    path: "src/client",
    format: "prettier",
    lint: "eslint",
  },
  services: {
    asClass: true,
  },
  plugins: ["@tanstack/react-query"],
});

OpenAPI specification (optional)

No response

System information (optional)

OS - Ubuntu 22.04 on WSL2,
Package manager - pnpm 9.10.0
Node version - 22.9.0
openapi-ts version - 0.53.4
typescript version - 5.6.2

@prenaissance prenaissance added the bug 🔥 Something isn't working label Sep 25, 2024
@mrlubos mrlubos added the prioritized 🚚 This issue has been prioritized and will be worked on soon label Sep 26, 2024
@mrlubos
Copy link
Member

mrlubos commented Sep 26, 2024

Hey! What would you expect the resulting code to look like?

@prenaissance
Copy link
Author

Hey! What would you expect the resulting code to look like?

Hello. I would expect the grouped services to be imported instead. The generated services look the following way:

export class MyService {
  public static getEp1<
    ThrowOnError extends boolean = false,
  >(options) {/*...*/}

  public static getEp2<
    ThrowOnError extends boolean = false,
  >(options) {/*...*/}
}

so the import should be:

import {
  client,
  MyService
} from "../services.gen";

I would expect the static classes to be imported. Instead, the plugin always assumes a flat structure.

@mrlubos
Copy link
Member

mrlubos commented Sep 26, 2024

@prenaissance Do you expect the TanStack functions to be flat? Grouped?

@prenaissance
Copy link
Author

@mrlubos I don't have a preference about that. The issues is that react-query.gen.ts imports non-existings functions from services.gen.ts when the asClass option is turned on. I can try to make a sandbox example if it's not clear.

@mrlubos
Copy link
Member

mrlubos commented Sep 26, 2024

No need, that much is clear. Why do you have a preference for using asClass: true but no preference for TanStack functions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🔥 Something isn't working prioritized 🚚 This issue has been prioritized and will be worked on soon
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants