Skip to content

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

Open
@victorterraga

Description

@victorterraga

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions