[{"data":1,"prerenderedAt":1007,"buildId":1008},["ShallowReactive",2],{"page:\u002Fextensions\u002Fkubb-labs\u002Fplugin-vue-query\u002Fguides\u002Fcalling-operations":3},{"id":4,"frontmatter":5,"title":6,"heading":6,"body":7,"path":1006,"source":4},"extensions\u002Fkubb-labs\u002Fplugin-vue-query\u002Fguides\u002Fcalling-operations.md",{},"Call operations",{"type":8,"value":9,"toc":996},"minimark",[10,14,19,27,133,137,166,688,692,695,817,821,827,944,962,966,976],[11,12,13],"p",{},"Use the generated TanStack Query composables and factories in Vue: queries, mutations, and infinite lists with reactive parameters.",[15,16,18],"h2",{"id":17},"what-each-plugin-generates","What each plugin generates",[11,20,21,22,26],{},"Each composable and its helpers live in a file named after the composable, such as ",[23,24,25],"code",{},"src\u002Fgen\u002Fhooks\u002FuseGetPetById.ts",".",[28,29,30,43],"table",{},[31,32,33],"thead",{},[34,35,36,40],"tr",{},[37,38,39],"th",{},"Operation",[37,41,42],{},"Exports",[44,45,46,76,103,125],"tbody",{},[34,47,48,60],{},[49,50,51,52,55,56,59],"td",{},"Query (",[23,53,54],{},"GET",", ",[23,57,58],{},"QUERY",")",[49,61,62,55,65,68,69,72,73],{},[23,63,64],{},"getPetByIdQueryKey",[23,66,67],{},"getPetByIdQueryOptions",", plus ",[23,70,71],{},"useGetPetById"," with ",[23,74,75],{},"hooks",[34,77,78,93],{},[49,79,80,81,55,84,55,87,55,90,59],{},"Mutation (",[23,82,83],{},"POST",[23,85,86],{},"PUT",[23,88,89],{},"PATCH",[23,91,92],{},"DELETE",[49,94,95,68,98,72,101],{},[23,96,97],{},"updatePetMutationKey",[23,99,100],{},"useUpdatePet",[23,102,75],{},[34,104,105,114],{},[49,106,107,108,111,112],{},"Infinite, with ",[23,109,110],{},"infinite"," and ",[23,113,75],{},[49,115,116,55,119,55,122],{},[23,117,118],{},"findPetsByTagsInfiniteQueryKey",[23,120,121],{},"findPetsByTagsInfiniteQueryOptions",[23,123,124],{},"useFindPetsByTagsInfinite",[34,126,127,130],{},[49,128,129],{},"Server-Sent Events or JSON Lines",[49,131,132],{},"Nothing. Call the client function directly.",[15,134,136],{"id":135},"call-a-composable","Call a composable",[11,138,139,140,143,144,151,152,155,156,159,160,26],{},"The examples set ",[23,141,142],{},"hooks: true",", and ",[145,146,148],"a",{"href":147},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fadapter-oas\u002Foptions#integertype",[23,149,150],{},"integerType: 'number'"," on the adapter so ",[23,153,154],{},"petId"," is a ",[23,157,158],{},"number",". Path keys keep their spec names unless you set ",[145,161,163],{"href":162},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fadapter-oas\u002Foptions#pathparamscasing",[23,164,165],{},"pathParamsCasing",[167,168,169,352,526],"tabs",{},[170,171,173,204],"tabs-item",{"label":172},"Query",[11,174,175,176,55,179,55,182,185,186,188,189,192,193,196,197,200,201,26],{},"The first argument takes the request groups (",[23,177,178],{},"path",[23,180,181],{},"query",[23,183,184],{},"headers","), each as a value, a ref, or a getter. The second takes TanStack Query options in ",[23,187,181],{},", with ",[23,190,191],{},"query.client"," for the ",[23,194,195],{},"QueryClient",", and request config such as ",[23,198,199],{},"baseURL"," in ",[23,202,203],{},"client",[205,206,210],"pre",{"language":207,"code":208,"class":209},"typescript","import { useFindPetsByTags } from '.\u002Fgen\u002Fhooks\u002FuseFindPetsByTags'\n\nconst { data, error, isLoading } = useFindPetsByTags(\n { query: { tags: ['dog'] } },\n { query: { staleTime: 60_000 }, client: { baseURL: 'https:\u002F\u002Fapi.example.com\u002Fv1' } },\n)","highlights",[23,211,213,240,241,240,243,240,275,240,304,240,348],{"class":212},"language-typescript",[214,215,218,222,226,230,233,236],"span",{"class":216,"style":217},"line","display: inline",[214,219,221],{"style":220},"color:#d73a49;--hls-dark:#f97583","import ",[214,223,225],{"style":224},"color:#005cc5;--hls-dark:#79b8ff","{ ",[214,227,229],{"style":228},"color:#24292e;--hls-dark:#e1e4e8","useFindPetsByTags ",[214,231,232],{"style":224},"} ",[214,234,235],{"style":220},"from ",[214,237,239],{"style":238},"color:#032f62;--hls-dark:#9ecbff","'.\u002Fgen\u002Fhooks\u002FuseFindPetsByTags'","\n",[214,242],{"class":216,"style":217},[214,244,245,248,250,253,255,258,260,263,265,268,272],{"class":216,"style":217},[214,246,247],{"style":220},"const ",[214,249,225],{"style":224},[214,251,252],{"style":228},"data",[214,254,55],{"style":220},[214,256,257],{"style":228},"error",[214,259,55],{"style":220},[214,261,262],{"style":228},"isLoading ",[214,264,232],{"style":224},[214,266,267],{"style":220},"= ",[214,269,271],{"style":270},"color:#6f42c1;--hls-dark:#b392f0","useFindPetsByTags",[214,273,274],{"style":224},"(",[214,276,277,280,282,285,287,290,292,295,298,301],{"class":216,"style":217},[214,278,279],{"style":224}," { ",[214,281,181],{"style":224},[214,283,284],{"style":220},": ",[214,286,225],{"style":224},[214,288,289],{"style":224},"tags",[214,291,284],{"style":220},[214,293,294],{"style":224},"[",[214,296,297],{"style":238},"'dog'",[214,299,300],{"style":224},"] } }",[214,302,303],{"style":220},",",[214,305,306,309,311,313,315,317,320,322,325,328,330,332,334,336,338,340,343,346],{"class":216,"style":217},[214,307,308],{"style":220}," ",[214,310,225],{"style":224},[214,312,181],{"style":224},[214,314,284],{"style":220},[214,316,225],{"style":224},[214,318,319],{"style":224},"staleTime",[214,321,284],{"style":220},[214,323,324],{"style":224},"60_000 ",[214,326,327],{"style":224},"}",[214,329,55],{"style":220},[214,331,203],{"style":224},[214,333,284],{"style":220},[214,335,225],{"style":224},[214,337,199],{"style":224},[214,339,284],{"style":220},[214,341,342],{"style":238},"'https:\u002F\u002Fapi.example.com\u002Fv1' ",[214,344,345],{"style":224},"} }",[214,347,303],{"style":220},[214,349,350],{"class":216,"style":217},[214,351,59],{"style":224},[170,353,355,371],{"label":354},"Mutation",[11,356,357,358,111,361,363,364,367,368,26],{},"A mutation composable takes only the options object, with ",[23,359,360],{},"mutation",[23,362,203],{},". Pass the request groups to ",[23,365,366],{},"mutate"," or ",[23,369,370],{},"mutateAsync",[205,372,374],{"language":207,"code":373,"class":209},"import { useQueryClient } from '@tanstack\u002Fvue-query'\nimport { useUpdatePetWithForm } from '.\u002Fgen\u002Fhooks\u002FuseUpdatePetWithForm'\n\nconst queryClient = useQueryClient()\nconst { mutate } = useUpdatePetWithForm({\n mutation: { onSuccess: () => queryClient.invalidateQueries() },\n})\n\nmutate({ path: { petId: 1 }, query: { name: 'Fluffy' } })",[23,375,376,240,392,240,408,240,410,240,425,240,444,240,478,240,483,240,485],{"class":212},[214,377,378,380,382,385,387,389],{"class":216,"style":217},[214,379,221],{"style":220},[214,381,225],{"style":224},[214,383,384],{"style":228},"useQueryClient ",[214,386,232],{"style":224},[214,388,235],{"style":220},[214,390,391],{"style":238},"'@tanstack\u002Fvue-query'",[214,393,394,396,398,401,403,405],{"class":216,"style":217},[214,395,221],{"style":220},[214,397,225],{"style":224},[214,399,400],{"style":228},"useUpdatePetWithForm ",[214,402,232],{"style":224},[214,404,235],{"style":220},[214,406,407],{"style":238},"'.\u002Fgen\u002Fhooks\u002FuseUpdatePetWithForm'",[214,409],{"class":216,"style":217},[214,411,412,414,417,419,422],{"class":216,"style":217},[214,413,247],{"style":220},[214,415,416],{"style":228},"queryClient ",[214,418,267],{"style":220},[214,420,421],{"style":270},"useQueryClient",[214,423,424],{"style":224},"()",[214,426,427,429,431,434,436,438,441],{"class":216,"style":217},[214,428,247],{"style":220},[214,430,225],{"style":224},[214,432,433],{"style":228},"mutate ",[214,435,232],{"style":224},[214,437,267],{"style":220},[214,439,440],{"style":270},"useUpdatePetWithForm",[214,442,443],{"style":224},"({",[214,445,446,448,450,452,454,457,459,462,465,468,470,473,476],{"class":216,"style":217},[214,447,308],{"style":224},[214,449,360],{"style":224},[214,451,284],{"style":220},[214,453,225],{"style":224},[214,455,456],{"style":224},"onSuccess",[214,458,284],{"style":220},[214,460,461],{"style":224},"() ",[214,463,464],{"style":220},"=> ",[214,466,467],{"style":228},"queryClient",[214,469,26],{"style":220},[214,471,472],{"style":270},"invalidateQueries",[214,474,475],{"style":224},"() }",[214,477,303],{"style":220},[214,479,480],{"class":216,"style":217},[214,481,482],{"style":224},"})",[214,484],{"class":216,"style":217},[214,486,487,489,492,494,496,498,500,502,505,507,509,511,513,515,518,520,523],{"class":216,"style":217},[214,488,366],{"style":270},[214,490,491],{"style":224},"({ ",[214,493,178],{"style":224},[214,495,284],{"style":220},[214,497,225],{"style":224},[214,499,154],{"style":224},[214,501,284],{"style":220},[214,503,504],{"style":224},"1 ",[214,506,327],{"style":224},[214,508,55],{"style":220},[214,510,181],{"style":224},[214,512,284],{"style":220},[214,514,225],{"style":224},[214,516,517],{"style":224},"name",[214,519,284],{"style":220},[214,521,522],{"style":238},"'Fluffy' ",[214,524,525],{"style":224},"} })",[170,527,529,548,618],{"label":528},"Infinite",[11,530,531,532,535,536,539,540,543,544,26],{},"Only operations that declare ",[23,533,534],{},"infinite.queryParam"," get an infinite composable. Point ",[23,537,538],{},"nextParam"," at the cursor in the response, and give ",[23,541,542],{},"initialPageParam"," the type of the query parameter. See ",[145,545,547],{"href":546},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fplugin-vue-query\u002Fguides\u002Finfinite-queries","Infinite queries",[205,549,552],{"language":207,"filename":550,"code":551,"class":209},"kubb.config.ts","pluginVueQuery({\n hooks: true,\n infinite: { queryParam: 'page', initialPageParam: 0, nextParam: 'pagination.next.cursor' },\n})",[23,553,554,240,561,240,574,240,614],{"class":212},[214,555,556,559],{"class":216,"style":217},[214,557,558],{"style":270},"pluginVueQuery",[214,560,443],{"style":224},[214,562,563,565,567,569,572],{"class":216,"style":217},[214,564,308],{"style":224},[214,566,75],{"style":224},[214,568,284],{"style":220},[214,570,571],{"style":224},"true",[214,573,303],{"style":220},[214,575,576,578,580,582,584,587,589,592,594,596,598,601,603,605,607,610,612],{"class":216,"style":217},[214,577,308],{"style":220},[214,579,110],{"style":224},[214,581,284],{"style":220},[214,583,225],{"style":224},[214,585,586],{"style":224},"queryParam",[214,588,284],{"style":220},[214,590,591],{"style":238},"'page'",[214,593,55],{"style":220},[214,595,542],{"style":224},[214,597,284],{"style":220},[214,599,600],{"style":224},"0",[214,602,55],{"style":220},[214,604,538],{"style":224},[214,606,284],{"style":220},[214,608,609],{"style":238},"'pagination.next.cursor' ",[214,611,327],{"style":224},[214,613,303],{"style":220},[214,615,616],{"class":216,"style":217},[214,617,482],{"style":224},[205,619,621],{"language":207,"code":620,"class":209},"import { useFindPetsByTagsInfinite } from '.\u002Fgen\u002Fhooks\u002FuseFindPetsByTagsInfinite'\n\nconst { data, fetchNextPage, hasNextPage } = useFindPetsByTagsInfinite({ query: () => ({ tags: ['dog'] }) })",[23,622,623,240,639,240,641],{"class":212},[214,624,625,627,629,632,634,636],{"class":216,"style":217},[214,626,221],{"style":220},[214,628,225],{"style":224},[214,630,631],{"style":228},"useFindPetsByTagsInfinite ",[214,633,232],{"style":224},[214,635,235],{"style":220},[214,637,638],{"style":238},"'.\u002Fgen\u002Fhooks\u002FuseFindPetsByTagsInfinite'",[214,640],{"class":216,"style":217},[214,642,643,645,647,649,651,654,656,659,661,663,665,667,669,671,673,675,677,679,681,683,685],{"class":216,"style":217},[214,644,247],{"style":220},[214,646,225],{"style":224},[214,648,252],{"style":228},[214,650,55],{"style":220},[214,652,653],{"style":228},"fetchNextPage",[214,655,55],{"style":220},[214,657,658],{"style":228},"hasNextPage ",[214,660,232],{"style":224},[214,662,267],{"style":220},[214,664,124],{"style":270},[214,666,491],{"style":224},[214,668,181],{"style":224},[214,670,284],{"style":220},[214,672,461],{"style":224},[214,674,464],{"style":220},[214,676,491],{"style":224},[214,678,289],{"style":224},[214,680,284],{"style":220},[214,682,294],{"style":224},[214,684,297],{"style":238},[214,686,687],{"style":224},"] }) })",[15,689,691],{"id":690},"refetch-when-parameters-change","Refetch when parameters change",[11,693,694],{},"Pass a ref or a getter instead of a value. A change updates the query key and fetches again:",[205,696,698],{"language":207,"code":697,"class":209},"import { ref } from 'vue'\nimport { useFindPetsByTags } from '.\u002Fgen\u002Fhooks\u002FuseFindPetsByTags'\n\nconst tags = ref(['dog'])\nconst { data } = useFindPetsByTags({ query: () => ({ tags: tags.value }) })\n\ntags.value = ['cat'] \u002F\u002F fetches the cat list",[23,699,700,240,716,240,730,240,732,240,752,240,793,240,795],{"class":212},[214,701,702,704,706,709,711,713],{"class":216,"style":217},[214,703,221],{"style":220},[214,705,225],{"style":224},[214,707,708],{"style":228},"ref ",[214,710,232],{"style":224},[214,712,235],{"style":220},[214,714,715],{"style":238},"'vue'",[214,717,718,720,722,724,726,728],{"class":216,"style":217},[214,719,221],{"style":220},[214,721,225],{"style":224},[214,723,229],{"style":228},[214,725,232],{"style":224},[214,727,235],{"style":220},[214,729,239],{"style":238},[214,731],{"class":216,"style":217},[214,733,734,736,739,741,744,747,749],{"class":216,"style":217},[214,735,247],{"style":220},[214,737,738],{"style":228},"tags ",[214,740,267],{"style":220},[214,742,743],{"style":270},"ref",[214,745,746],{"style":224},"([",[214,748,297],{"style":238},[214,750,751],{"style":224},"])",[214,753,754,756,758,761,763,765,767,769,771,773,775,777,779,781,783,785,787,790],{"class":216,"style":217},[214,755,247],{"style":220},[214,757,225],{"style":224},[214,759,760],{"style":228},"data ",[214,762,232],{"style":224},[214,764,267],{"style":220},[214,766,271],{"style":270},[214,768,491],{"style":224},[214,770,181],{"style":224},[214,772,284],{"style":220},[214,774,461],{"style":224},[214,776,464],{"style":220},[214,778,491],{"style":224},[214,780,289],{"style":224},[214,782,284],{"style":220},[214,784,289],{"style":228},[214,786,26],{"style":220},[214,788,789],{"style":224},"value ",[214,791,792],{"style":224},"}) })",[214,794],{"class":216,"style":217},[214,796,797,799,801,803,805,807,810,813],{"class":216,"style":217},[214,798,289],{"style":228},[214,800,26],{"style":220},[214,802,789],{"style":224},[214,804,267],{"style":220},[214,806,294],{"style":224},[214,808,809],{"style":238},"'cat'",[214,811,812],{"style":224},"] ",[214,814,816],{"style":815},"color:#6a737d;--hls-dark:#6a737d","\u002F\u002F fetches the cat list",[15,818,820],{"id":819},"prefetch-and-invalidate","Prefetch and invalidate",[11,822,823,824,826],{},"The factories work without ",[23,825,75],{},", so you can prefetch or invalidate outside a component:",[205,828,830],{"language":207,"code":829,"class":209},"import { findPetsByTagsQueryKey, findPetsByTagsQueryOptions } from '.\u002Fgen\u002Fhooks\u002FuseFindPetsByTags'\nimport { queryClient } from '.\u002FqueryClient' \u002F\u002F the QueryClient you pass to VueQueryPlugin\n\nawait queryClient.prefetchQuery(findPetsByTagsQueryOptions({ query: { tags: ['dog'] } }))\nqueryClient.invalidateQueries({ queryKey: findPetsByTagsQueryKey({ query: { tags: ['dog'] } }) })",[23,831,832,240,852,240,870,240,872,240,908],{"class":212},[214,833,834,836,838,841,843,846,848,850],{"class":216,"style":217},[214,835,221],{"style":220},[214,837,225],{"style":224},[214,839,840],{"style":228},"findPetsByTagsQueryKey",[214,842,55],{"style":220},[214,844,845],{"style":228},"findPetsByTagsQueryOptions ",[214,847,232],{"style":224},[214,849,235],{"style":220},[214,851,239],{"style":238},[214,853,854,856,858,860,862,864,867],{"class":216,"style":217},[214,855,221],{"style":220},[214,857,225],{"style":224},[214,859,416],{"style":228},[214,861,232],{"style":224},[214,863,235],{"style":220},[214,865,866],{"style":238},"'.\u002FqueryClient' ",[214,868,869],{"style":815},"\u002F\u002F the QueryClient you pass to VueQueryPlugin",[214,871],{"class":216,"style":217},[214,873,874,877,879,881,884,886,889,891,893,895,897,899,901,903,905],{"class":216,"style":217},[214,875,876],{"style":220},"await ",[214,878,467],{"style":228},[214,880,26],{"style":220},[214,882,883],{"style":270},"prefetchQuery",[214,885,274],{"style":224},[214,887,888],{"style":270},"findPetsByTagsQueryOptions",[214,890,491],{"style":224},[214,892,181],{"style":224},[214,894,284],{"style":220},[214,896,225],{"style":224},[214,898,289],{"style":224},[214,900,284],{"style":220},[214,902,294],{"style":224},[214,904,297],{"style":238},[214,906,907],{"style":224},"] } }))",[214,909,910,912,914,916,918,921,923,925,927,929,931,933,935,937,939,941],{"class":216,"style":217},[214,911,467],{"style":228},[214,913,26],{"style":220},[214,915,472],{"style":270},[214,917,491],{"style":224},[214,919,920],{"style":224},"queryKey",[214,922,284],{"style":220},[214,924,840],{"style":270},[214,926,491],{"style":224},[214,928,181],{"style":224},[214,930,284],{"style":220},[214,932,225],{"style":224},[214,934,289],{"style":224},[214,936,284],{"style":220},[214,938,294],{"style":224},[214,940,297],{"style":238},[214,942,943],{"style":224},"] } }) })",[11,945,946,950,951,111,956,26],{},[145,947,949],{"href":948},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fplugin-vue-query\u002Fguides\u002Fquery-keys","TanStack Query keys"," shows the default keys. To change them, set ",[145,952,954],{"href":953},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fplugin-vue-query\u002Foptions#querykey",[23,955,920],{},[145,957,959],{"href":958},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fplugin-vue-query\u002Foptions#mutationkey",[23,960,961],{},"mutationKey",[15,963,965],{"id":964},"handle-errors","Handle errors",[11,967,968,969,972,973,975],{},"Each composable calls the client with ",[23,970,971],{},"throwOnError: true",", so a failed request sets TanStack Query's ",[23,974,257],{},", typed from the spec's error responses.",[11,977,978,979,55,983,55,987,991,992,26],{},"Next, set the base URL, auth, and interceptors on your client plugin: ",[145,980,982],{"href":981},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fplugin-fetch","plugin-fetch",[145,984,986],{"href":985},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fplugin-axios","plugin-axios",[145,988,990],{"href":989},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fplugin-ky","plugin-ky",", or your own module with ",[145,993,995],{"href":994},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fplugin-client\u002Fguides\u002Fwrite-your-client","plugin-client",{"title":997,"searchDepth":998,"depth":998,"links":999},"",5,[1000,1002,1003,1004,1005],{"id":17,"depth":1001,"text":18},2,{"id":135,"depth":1001,"text":136},{"id":690,"depth":1001,"text":691},{"id":819,"depth":1001,"text":820},{"id":964,"depth":1001,"text":965},"\u002Fextensions\u002Fkubb-labs\u002Fplugin-vue-query\u002Fguides\u002Fcalling-operations",1795727687005,"1b64b1eb-29b7-4f90-ad41-6f24721e1669"]