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

rtk-query Codegen OperationNameSuffix not appended in hook names #4668

Open
victorterraga opened this issue Oct 16, 2024 · 0 comments
Open

Comments

@victorterraga
Copy link

I am using operationNameSuffix variable to generate the code, and it is appended correctly to the operationIds of the generated code. But in the exported hooks, the suffix is not being appended and them cannot be used.

Config file example:

{
  "schemaFile": "./swagger.yml",
  "apiFile": "./apiSlice.ts",
  "apiImport": "testApi",
  "outputFile": "./testApi.ts",
  "exportName": "testApi",
  "filterEndpoints": [
    "ListTestEndpoints"
  ],
  "hooks": true,
  "operationNameSuffix": "_testsuffix"
}

Example:

import { apiSlice as api } from './apiSlice';
const injectedRtkApi = api.injectEndpoints({
  endpoints: (build) => ({
    ListTestEndpoints_testsuffix: build.query({
      query: (queryArg) => ({
        url: `/${queryArg.partid}`,
        params: {
          quantity: queryArg.quantity,
          lastKey: queryArg.lastKey
        }
      })
    })
  }),
  overrideExisting: false
});
export { injectedRtkApi as testApi };
export type ErrorResponse = any;
export const { useListTestEndpointsQuery } = injectedRtkApi;

I think it should be:

import { apiSlice as api } from './apiSlice';
const injectedRtkApi = api.injectEndpoints({
  endpoints: (build) => ({
    ListTestEndpoints_testsuffix: build.query({
      query: (queryArg) => ({
        url: `/${queryArg.partid}`,
        params: {
          quantity: queryArg.quantity,
          lastKey: queryArg.lastKey
        }
      })
    })
  }),
  overrideExisting: false
});
export { injectedRtkApi as testApi };
export type ErrorResponse = any;
export const { useListTestEndpoints_testsuffixQuery } = injectedRtkApi;

If not, we have to manually update the hooks export in the file.

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

No branches or pull requests

2 participants