Skip to content

Commit ce9e05d

Browse files
committed
Expose endpoints.someEndpoint.name field
1 parent 90283e9 commit ce9e05d

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

packages/toolkit/src/query/core/module.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ export interface ApiEndpointQuery<
412412
// eslint-disable-next-line @typescript-eslint/no-unused-vars
413413
Definitions extends EndpointDefinitions
414414
> {
415+
name: string
415416
/**
416417
* All of these are `undefined` at runtime, purely to be used in TypeScript declarations!
417418
*/
@@ -425,6 +426,7 @@ export interface ApiEndpointMutation<
425426
// eslint-disable-next-line @typescript-eslint/no-unused-vars
426427
Definitions extends EndpointDefinitions
427428
> {
429+
name: string
428430
/**
429431
* All of these are `undefined` at runtime, purely to be used in TypeScript declarations!
430432
*/
@@ -603,6 +605,7 @@ export const coreModule = (): Module<CoreModule> => ({
603605
safeAssign(
604606
anyApi.endpoints[endpointName],
605607
{
608+
name: endpointName,
606609
select: buildQuerySelector(endpointName, definition),
607610
initiate: buildInitiateQuery(endpointName, definition),
608611
},
@@ -612,6 +615,7 @@ export const coreModule = (): Module<CoreModule> => ({
612615
safeAssign(
613616
anyApi.endpoints[endpointName],
614617
{
618+
name: endpointName,
615619
select: buildMutationSelector(),
616620
initiate: buildInitiateMutation(endpointName),
617621
},

packages/toolkit/src/query/tests/createApi.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
import { server } from './mocks/server'
1919
import { rest } from 'msw'
2020
import { SerializeQueryArgs } from '../defaultSerializeQueryArgs'
21+
import { string } from 'yargs'
2122

2223
const originalEnv = process.env.NODE_ENV
2324
beforeAll(() => void ((process.env as any).NODE_ENV = 'development'))
@@ -43,6 +44,9 @@ test('sensible defaults', () => {
4344
return { url: `user/${id}` }
4445
},
4546
}),
47+
updateUser: build.mutation<unknown, void>({
48+
query: () => '',
49+
}),
4650
}),
4751
})
4852
configureStore({
@@ -60,6 +64,9 @@ test('sensible defaults', () => {
6064
expectType<TagTypes>(ANY as never)
6165
// @ts-expect-error
6266
expectType<TagTypes>(0)
67+
68+
expect(api.endpoints.getUser.name).toBe('getUser')
69+
expect(api.endpoints.updateUser.name).toBe('updateUser')
6370
})
6471

6572
describe('wrong tagTypes log errors', () => {

0 commit comments

Comments
 (0)