[{"data":1,"prerenderedAt":984,"buildId":985},["ShallowReactive",2],{"page:\u002Fextensions\u002Fkubb-labs\u002Fplugin-react-query\u002Fguides\u002Fquery-keys":3},{"id":4,"frontmatter":5,"title":6,"heading":6,"body":7,"path":983,"source":4},"extensions\u002Fkubb-labs\u002Fplugin-react-query\u002Fguides\u002Fquery-keys.md",{},"TanStack Query keys",{"type":8,"value":9,"toc":974},"minimark",[10,14,19,43,398,451,455,461,485,489,507,611,615,629,637,950,966],[11,12,13],"p",{},"See the query key each generated React Query hook uses, invalidate or read the cache with it, and add your own prefix to the default key.",[15,16,18],"h2",{"id":17},"the-default-query-key","The default query key",[11,20,21,22,26,27,30,31,34,35,38,39,42],{},"When you call ",[23,24,25],"code",{},"invalidateQueries",", ",[23,28,29],{},"getQueryData",", or ",[23,32,33],{},"setQueryData",", take the key from the ",[23,36,37],{},"\u003Coperation>QueryKey"," helper in each hook file. It builds ",[23,40,41],{},"[{ url, params }, query, body]",":",[44,45,46,243],"code-group",{},[47,48,53],"pre",{"language":49,"filename":50,"code":51,"class":52},"typescript","Generated","\u002F\u002F src\u002Fgen\u002Fhooks\u002FuseGetPetById.ts\nexport const getPetByIdQueryKey = ({ path }: Omit\u003CGetPetByIdOptions, 'headers'>) => [{ url: '\u002Fpet\u002F:petId', params: path }] as const\n\n\u002F\u002F src\u002Fgen\u002Fhooks\u002FuseFindPetsByTags.ts\nexport const findPetsByTagsQueryKey = ({ query }: Omit\u003CFindPetsByTagsOptions, 'headers'> = {}) =>\n [{ url: '\u002Fpet\u002FfindByTags' }, ...(query ? [query] : [])] as const","highlights",[23,54,56,65,66,65,149,65,151,65,156,65,196],{"class":55},"language-typescript",[57,58,61],"span",{"class":59,"style":60},"line","display: inline",[57,62,64],{"style":63},"color:#6a737d;--hls-dark:#6a737d","\u002F\u002F src\u002Fgen\u002Fhooks\u002FuseGetPetById.ts","\n",[57,67,68,72,75,79,82,86,89,92,95,99,102,105,107,111,114,117,120,123,126,128,131,133,136,138,140,143,146],{"class":59,"style":60},[57,69,71],{"style":70},"color:#d73a49;--hls-dark:#f97583","export ",[57,73,74],{"style":70},"const ",[57,76,78],{"style":77},"color:#24292e;--hls-dark:#e1e4e8","getPetByIdQueryKey ",[57,80,81],{"style":70},"= ",[57,83,85],{"style":84},"color:#005cc5;--hls-dark:#79b8ff","({ ",[57,87,88],{"style":77},"path ",[57,90,91],{"style":84},"}",[57,93,94],{"style":77},": ",[57,96,98],{"style":97},"color:#6f42c1;--hls-dark:#b392f0","Omit",[57,100,101],{"style":70},"\u003C",[57,103,104],{"style":97},"GetPetByIdOptions",[57,106,26],{"style":70},[57,108,110],{"style":109},"color:#032f62;--hls-dark:#9ecbff","'headers'",[57,112,113],{"style":70},">",[57,115,116],{"style":84},") ",[57,118,119],{"style":70},"=> ",[57,121,122],{"style":84},"[{ ",[57,124,125],{"style":84},"url",[57,127,94],{"style":70},[57,129,130],{"style":109},"'\u002Fpet\u002F:petId'",[57,132,26],{"style":70},[57,134,135],{"style":84},"params",[57,137,94],{"style":70},[57,139,88],{"style":77},[57,141,142],{"style":84},"}] ",[57,144,145],{"style":70},"as ",[57,147,148],{"style":70},"const",[57,150],{"class":59,"style":60},[57,152,153],{"class":59,"style":60},[57,154,155],{"style":63},"\u002F\u002F src\u002Fgen\u002Fhooks\u002FuseFindPetsByTags.ts",[57,157,158,160,162,165,167,169,172,174,176,178,180,183,185,187,190,193],{"class":59,"style":60},[57,159,71],{"style":70},[57,161,74],{"style":70},[57,163,164],{"style":77},"findPetsByTagsQueryKey ",[57,166,81],{"style":70},[57,168,85],{"style":84},[57,170,171],{"style":77},"query ",[57,173,91],{"style":84},[57,175,94],{"style":77},[57,177,98],{"style":97},[57,179,101],{"style":70},[57,181,182],{"style":97},"FindPetsByTagsOptions",[57,184,26],{"style":70},[57,186,110],{"style":109},[57,188,189],{"style":70},"> = ",[57,191,192],{"style":84},"{}) ",[57,194,195],{"style":70},"=>",[57,197,198,201,203,205,207,210,212,214,217,220,222,225,228,231,234,236,239,241],{"class":59,"style":60},[57,199,200],{"style":70}," ",[57,202,122],{"style":84},[57,204,125],{"style":84},[57,206,94],{"style":70},[57,208,209],{"style":109},"'\u002Fpet\u002FfindByTags' ",[57,211,91],{"style":84},[57,213,26],{"style":70},[57,215,216],{"style":70},"...",[57,218,219],{"style":84},"(",[57,221,171],{"style":77},[57,223,224],{"style":70},"? ",[57,226,227],{"style":84},"[",[57,229,230],{"style":77},"query",[57,232,233],{"style":84},"] ",[57,235,94],{"style":70},[57,237,238],{"style":84},"[])] ",[57,240,145],{"style":70},[57,242,148],{"style":70},[47,244,247],{"language":49,"filename":245,"code":246,"class":52},"Usage","import { getPetByIdQueryKey } from '.\u002Fgen\u002Fhooks\u002FuseGetPetById'\nimport { findPetsByTagsQueryKey } from '.\u002Fgen\u002Fhooks\u002FuseFindPetsByTags'\nimport { queryClient } from '.\u002FqueryClient'\n\ngetPetByIdQueryKey({ path: { petId: 1 } }) \u002F\u002F [{ url: '\u002Fpet\u002F:petId', params: { petId: 1 } }]\nfindPetsByTagsQueryKey({ query: { tags: ['dog'] } }) \u002F\u002F [{ url: '\u002Fpet\u002FfindByTags' }, { tags: ['dog'] }]\n\nconst pet = queryClient.getQueryData(getPetByIdQueryKey({ path: { petId: 1 } }))",[23,248,249,65,268,65,283,65,299,65,301,65,329,65,358,65,360],{"class":55},[57,250,251,254,257,259,262,265],{"class":59,"style":60},[57,252,253],{"style":70},"import ",[57,255,256],{"style":84},"{ ",[57,258,78],{"style":77},[57,260,261],{"style":84},"} ",[57,263,264],{"style":70},"from ",[57,266,267],{"style":109},"'.\u002Fgen\u002Fhooks\u002FuseGetPetById'",[57,269,270,272,274,276,278,280],{"class":59,"style":60},[57,271,253],{"style":70},[57,273,256],{"style":84},[57,275,164],{"style":77},[57,277,261],{"style":84},[57,279,264],{"style":70},[57,281,282],{"style":109},"'.\u002Fgen\u002Fhooks\u002FuseFindPetsByTags'",[57,284,285,287,289,292,294,296],{"class":59,"style":60},[57,286,253],{"style":70},[57,288,256],{"style":84},[57,290,291],{"style":77},"queryClient ",[57,293,261],{"style":84},[57,295,264],{"style":70},[57,297,298],{"style":109},"'.\u002FqueryClient'",[57,300],{"class":59,"style":60},[57,302,303,306,308,311,313,315,318,320,323,326],{"class":59,"style":60},[57,304,305],{"style":97},"getPetByIdQueryKey",[57,307,85],{"style":84},[57,309,310],{"style":84},"path",[57,312,94],{"style":70},[57,314,256],{"style":84},[57,316,317],{"style":84},"petId",[57,319,94],{"style":70},[57,321,322],{"style":84},"1 ",[57,324,325],{"style":84},"} }) ",[57,327,328],{"style":63},"\u002F\u002F [{ url: '\u002Fpet\u002F:petId', params: { petId: 1 } }]",[57,330,331,334,336,338,340,342,345,347,349,352,355],{"class":59,"style":60},[57,332,333],{"style":97},"findPetsByTagsQueryKey",[57,335,85],{"style":84},[57,337,230],{"style":84},[57,339,94],{"style":70},[57,341,256],{"style":84},[57,343,344],{"style":84},"tags",[57,346,94],{"style":70},[57,348,227],{"style":84},[57,350,351],{"style":109},"'dog'",[57,353,354],{"style":84},"] } }) ",[57,356,357],{"style":63},"\u002F\u002F [{ url: '\u002Fpet\u002FfindByTags' }, { tags: ['dog'] }]",[57,359],{"class":59,"style":60},[57,361,362,364,367,369,372,375,377,379,381,383,385,387,389,391,393,395],{"class":59,"style":60},[57,363,74],{"style":70},[57,365,366],{"style":77},"pet ",[57,368,81],{"style":70},[57,370,371],{"style":77},"queryClient",[57,373,374],{"style":70},".",[57,376,29],{"style":97},[57,378,219],{"style":84},[57,380,305],{"style":97},[57,382,85],{"style":84},[57,384,310],{"style":84},[57,386,94],{"style":70},[57,388,256],{"style":84},[57,390,317],{"style":84},[57,392,94],{"style":70},[57,394,322],{"style":84},[57,396,397],{"style":84},"} }))",[399,400,401,413,418,427,438,445],"ul",{},[402,403,404,406,407,410,411,374],"li",{},[23,405,125],{}," is the spec path with ",[23,408,409],{},":name"," placeholders, such as ",[23,412,130],{},[402,414,415,417],{},[23,416,135],{}," holds the path parameters, when the path has any.",[402,419,420,422,423,426],{},[23,421,230],{}," and ",[23,424,425],{},"body"," follow when the operation has them and the call passes them.",[402,428,429,430,433,434,437],{},"Headers and cookies stay out of the default key. A custom ",[23,431,432],{},"queryKey"," transformer can include the generated ",[23,435,436],{},"headers"," binding.",[402,439,440,441,444],{},"Infinite variants add ",[23,442,443],{},"infinite: true"," to the first entry, so they never share a cache entry with the plain query.",[402,446,447,448,450],{},"Each hook returns the key it used as ",[23,449,432],{}," on its result.",[15,452,454],{"id":453},"invalidate-every-call-of-an-operation","Invalidate every call of an operation",[11,456,457,458,460],{},"TanStack Query matches a key by its prefix, and an object entry by the fields you pass. A key built without ",[23,459,230],{}," matches every cached call of that operation with the same path parameters, infinite ones included:",[47,462,464],{"language":49,"code":463,"class":52},"queryClient.invalidateQueries({ queryKey: findPetsByTagsQueryKey() })",[23,465,466],{"class":55},[57,467,468,470,472,474,476,478,480,482],{"class":59,"style":60},[57,469,371],{"style":77},[57,471,374],{"style":70},[57,473,25],{"style":97},[57,475,85],{"style":84},[57,477,432],{"style":84},[57,479,94],{"style":70},[57,481,333],{"style":97},[57,483,484],{"style":84},"() })",[15,486,488],{"id":487},"mutation-keys","Mutation keys",[11,490,491,492,495,496,499,500,503,504,42],{},"Each mutation gets a ",[23,493,494],{},"\u003Coperation>MutationKey"," helper that returns ",[23,497,498],{},"[{ url }]",", for filters such as ",[23,501,502],{},"useIsMutating"," or ",[23,505,506],{},"useMutationState",[44,508,509,550],{},[47,510,512],{"language":49,"filename":50,"code":511,"class":52},"\u002F\u002F src\u002Fgen\u002Fhooks\u002FuseUpdatePet.ts\nexport const updatePetMutationKey = () => [{ url: '\u002Fpet' }] as const",[23,513,514,65,519],{"class":55},[57,515,516],{"class":59,"style":60},[57,517,518],{"style":63},"\u002F\u002F src\u002Fgen\u002Fhooks\u002FuseUpdatePet.ts",[57,520,521,523,525,528,530,533,535,537,539,541,544,546,548],{"class":59,"style":60},[57,522,71],{"style":70},[57,524,74],{"style":70},[57,526,527],{"style":77},"updatePetMutationKey ",[57,529,81],{"style":70},[57,531,532],{"style":84},"() ",[57,534,119],{"style":70},[57,536,122],{"style":84},[57,538,125],{"style":84},[57,540,94],{"style":70},[57,542,543],{"style":109},"'\u002Fpet' ",[57,545,142],{"style":84},[57,547,145],{"style":70},[57,549,148],{"style":70},[47,551,553],{"language":49,"filename":245,"code":552,"class":52},"import { useIsMutating } from '@tanstack\u002Freact-query'\nimport { updatePetMutationKey } from '.\u002Fgen\u002Fhooks\u002FuseUpdatePet'\n\nconst saving = useIsMutating({ mutationKey: updatePetMutationKey() })",[23,554,555,65,571,65,586,65,588],{"class":55},[57,556,557,559,561,564,566,568],{"class":59,"style":60},[57,558,253],{"style":70},[57,560,256],{"style":84},[57,562,563],{"style":77},"useIsMutating ",[57,565,261],{"style":84},[57,567,264],{"style":70},[57,569,570],{"style":109},"'@tanstack\u002Freact-query'",[57,572,573,575,577,579,581,583],{"class":59,"style":60},[57,574,253],{"style":70},[57,576,256],{"style":84},[57,578,527],{"style":77},[57,580,261],{"style":84},[57,582,264],{"style":70},[57,584,585],{"style":109},"'.\u002Fgen\u002Fhooks\u002FuseUpdatePet'",[57,587],{"class":59,"style":60},[57,589,590,592,595,597,599,601,604,606,609],{"class":59,"style":60},[57,591,74],{"style":70},[57,593,594],{"style":77},"saving ",[57,596,81],{"style":70},[57,598,502],{"style":97},[57,600,85],{"style":84},[57,602,603],{"style":84},"mutationKey",[57,605,94],{"style":70},[57,607,608],{"style":97},"updatePetMutationKey",[57,610,484],{"style":84},[15,612,614],{"id":613},"extend-the-default-key","Extend the default key",[11,616,617,618,624,625,628],{},"When you need your own entry, such as an API version, set ",[619,620,622],"a",{"href":621},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fplugin-react-query\u002Foptions#querykey",[23,623,432],{}," and spread ",[23,626,627],{},"queryKeyTransformer",". Do not read single entries of its result: they can change between releases.",[630,631,633,634,374],"blockquote",{"as":632},"warning","Returned strings are copied into the generated code as written. Wrap a string literal in ",[23,635,636],{},"JSON.stringify(...)",[44,638,639,882],{},[47,640,643],{"language":49,"filename":641,"code":642,"class":52},"kubb.config.ts","import { defineConfig } from 'kubb\u002Fconfig'\nimport { pluginTs } from '@kubb\u002Fplugin-ts'\nimport { pluginFetch } from '@kubb\u002Fplugin-fetch'\nimport { pluginReactQuery, queryKeyTransformer } from '@kubb\u002Fplugin-react-query'\n\nexport default defineConfig({\n input: '.\u002FpetStore.yaml',\n output: { path: '.\u002Fsrc\u002Fgen' },\n plugins: [\n pluginTs(),\n pluginFetch(),\n pluginReactQuery({\n queryKey: (props) => [JSON.stringify('v2'), ...queryKeyTransformer(props)],\n }),\n ],\n})",[23,644,645,65,661,65,677,65,693,65,714,65,716,65,729,65,744,65,766,65,777,65,790,65,801,65,809,65,860,65,869,65,878],{"class":55},[57,646,647,649,651,654,656,658],{"class":59,"style":60},[57,648,253],{"style":70},[57,650,256],{"style":84},[57,652,653],{"style":77},"defineConfig ",[57,655,261],{"style":84},[57,657,264],{"style":70},[57,659,660],{"style":109},"'kubb\u002Fconfig'",[57,662,663,665,667,670,672,674],{"class":59,"style":60},[57,664,253],{"style":70},[57,666,256],{"style":84},[57,668,669],{"style":77},"pluginTs ",[57,671,261],{"style":84},[57,673,264],{"style":70},[57,675,676],{"style":109},"'@kubb\u002Fplugin-ts'",[57,678,679,681,683,686,688,690],{"class":59,"style":60},[57,680,253],{"style":70},[57,682,256],{"style":84},[57,684,685],{"style":77},"pluginFetch ",[57,687,261],{"style":84},[57,689,264],{"style":70},[57,691,692],{"style":109},"'@kubb\u002Fplugin-fetch'",[57,694,695,697,699,702,704,707,709,711],{"class":59,"style":60},[57,696,253],{"style":70},[57,698,256],{"style":84},[57,700,701],{"style":77},"pluginReactQuery",[57,703,26],{"style":70},[57,705,706],{"style":77},"queryKeyTransformer ",[57,708,261],{"style":84},[57,710,264],{"style":70},[57,712,713],{"style":109},"'@kubb\u002Fplugin-react-query'",[57,715],{"class":59,"style":60},[57,717,718,720,723,726],{"class":59,"style":60},[57,719,71],{"style":70},[57,721,722],{"style":70},"default ",[57,724,725],{"style":97},"defineConfig",[57,727,728],{"style":84},"({",[57,730,731,733,736,738,741],{"class":59,"style":60},[57,732,200],{"style":84},[57,734,735],{"style":84},"input",[57,737,94],{"style":70},[57,739,740],{"style":109},"'.\u002FpetStore.yaml'",[57,742,743],{"style":70},",",[57,745,746,748,751,753,755,757,759,762,764],{"class":59,"style":60},[57,747,200],{"style":70},[57,749,750],{"style":84},"output",[57,752,94],{"style":70},[57,754,256],{"style":84},[57,756,310],{"style":84},[57,758,94],{"style":70},[57,760,761],{"style":109},"'.\u002Fsrc\u002Fgen' ",[57,763,91],{"style":84},[57,765,743],{"style":70},[57,767,768,770,773,775],{"class":59,"style":60},[57,769,200],{"style":70},[57,771,772],{"style":84},"plugins",[57,774,94],{"style":70},[57,776,227],{"style":84},[57,778,779,782,785,788],{"class":59,"style":60},[57,780,781],{"style":84}," ",[57,783,784],{"style":97},"pluginTs",[57,786,787],{"style":84},"()",[57,789,743],{"style":70},[57,791,792,794,797,799],{"class":59,"style":60},[57,793,781],{"style":70},[57,795,796],{"style":97},"pluginFetch",[57,798,787],{"style":84},[57,800,743],{"style":70},[57,802,803,805,807],{"class":59,"style":60},[57,804,781],{"style":70},[57,806,701],{"style":97},[57,808,728],{"style":84},[57,810,811,814,816,818,820,823,825,827,829,832,834,837,839,842,845,847,849,851,853,855,858],{"class":59,"style":60},[57,812,813],{"style":84}," ",[57,815,432],{"style":84},[57,817,94],{"style":70},[57,819,219],{"style":84},[57,821,822],{"style":77},"props",[57,824,116],{"style":84},[57,826,119],{"style":70},[57,828,227],{"style":84},[57,830,831],{"style":84},"JSON",[57,833,374],{"style":70},[57,835,836],{"style":97},"stringify",[57,838,219],{"style":84},[57,840,841],{"style":109},"'v2'",[57,843,844],{"style":84},")",[57,846,26],{"style":70},[57,848,216],{"style":70},[57,850,627],{"style":97},[57,852,219],{"style":84},[57,854,822],{"style":77},[57,856,857],{"style":84},")]",[57,859,743],{"style":70},[57,861,862,864,867],{"class":59,"style":60},[57,863,781],{"style":70},[57,865,866],{"style":84},"})",[57,868,743],{"style":70},[57,870,871,873,876],{"class":59,"style":60},[57,872,200],{"style":70},[57,874,875],{"style":84},"]",[57,877,743],{"style":70},[57,879,880],{"class":59,"style":60},[57,881,866],{"style":84},[47,883,885],{"language":49,"filename":50,"code":884,"class":52},"export const getPetByIdQueryKey = ({ path }: Omit\u003CGetPetByIdOptions, 'headers'>) => [\"v2\", { url: '\u002Fpet\u002F:petId', params: path }] as const",[23,886,887],{"class":55},[57,888,889,891,893,895,897,899,901,903,905,907,909,911,913,915,917,919,921,923,926,928,930,932,934,936,938,940,942,944,946,948],{"class":59,"style":60},[57,890,71],{"style":70},[57,892,74],{"style":70},[57,894,78],{"style":77},[57,896,81],{"style":70},[57,898,85],{"style":84},[57,900,88],{"style":77},[57,902,91],{"style":84},[57,904,94],{"style":77},[57,906,98],{"style":97},[57,908,101],{"style":70},[57,910,104],{"style":97},[57,912,26],{"style":70},[57,914,110],{"style":109},[57,916,113],{"style":70},[57,918,116],{"style":84},[57,920,119],{"style":70},[57,922,227],{"style":84},[57,924,925],{"style":109},"\"v2\"",[57,927,26],{"style":70},[57,929,256],{"style":84},[57,931,125],{"style":84},[57,933,94],{"style":70},[57,935,130],{"style":109},[57,937,26],{"style":70},[57,939,135],{"style":84},[57,941,94],{"style":70},[57,943,88],{"style":77},[57,945,142],{"style":84},[57,947,145],{"style":70},[57,949,148],{"style":70},[11,951,952,953,956,957,962,963,374],{},"The builder also gets the ",[23,954,955],{},"variant",", so it can return a different key for suspense or infinite hooks. ",[619,958,960],{"href":959},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fplugin-react-query\u002Foptions#mutationkey",[23,961,603],{}," works the same way with ",[23,964,965],{},"mutationKeyTransformer",[11,967,968,969,973],{},"Next, ",[619,970,972],{"href":971},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fplugin-react-query\u002Fguides\u002Finfinite-queries","generate infinite queries"," for paginated endpoints.",{"title":975,"searchDepth":976,"depth":976,"links":977},"",5,[978,980,981,982],{"id":17,"depth":979,"text":18},2,{"id":453,"depth":979,"text":454},{"id":487,"depth":979,"text":488},{"id":613,"depth":979,"text":614},"\u002Fextensions\u002Fkubb-labs\u002Fplugin-react-query\u002Fguides\u002Fquery-keys",1795727686234,"1b64b1eb-29b7-4f90-ad41-6f24721e1669"]