TypeScript RTK-Query
RTK Query codegen plugin for GraphQL. Generates React Hooks for GraphQL queries and mutations. Works with any GraphQL client.
- Version
- 4.0.4
- Weekly downloads
- 21k
- License
- MIT
- Updated
- Jun 23, 2026
Installation
npm i -D @graphql-codegen/typescript-rtk-query
yarn add -D @graphql-codegen/typescript-rtk-query
pnpm add -D @graphql-codegen/typescript-rtk-query
bun add -D @graphql-codegen/typescript-rtk-query
Config API Reference
importBaseApiFrom
type: string
Define where to import the base api to inject endpoints into
importBaseApiAlternateName
type: string
Change the import name of the baseApi from default ‘api’ Default value: “‘api’”
exportHooks
type: boolean
Whether to export React Hooks from the generated api. Enable only when using the "@reduxjs/toolkit/query/react" import of createApi
Default value: “false”
overrideExisting
type: string
Sets the overrideExisting option, for example to allow for hot module reloading when running graphql-codegen in watch mode.
Will directly be injected as code.
Default value: “undefined”
addTransformResponse
type: boolean
Sets the addTransformResponse option, which will automatically add a types transformResponse for query
Default value: “false”
Usage Examples
Using graphql-request
The generated src/app/api/generated.ts would try to
import { api } from 'src/app/api/baseApi'{:ts}, so you have to create that file:
From that point on, you can import the generated hooks from src/app/api/generated.ts:
Extending generated code
You can import the generated code into a new file and use api.enhanceEndpoints{:ts} to add
lifecycle hooks or providesTags/invalidatedTags information to your api:
Make sure that this file is referenced from your code so that the enhanced endpoints are usable. The easiest way to do this is to re-export the hooks in this file and import them exclusively from it.
Setting an authentication header after a Mutation
You can also use this to set an “authentication” header after a login mutation: