Replies: 5 comments 1 reply
-
How would you call this endpoint with a regular Don't know if I understand your issue correctly but could you use a mutation with an empty body? Something like const { data, error } = await api.useMutation('post', '/api/someendpoint').mutate({}) https://tanstack.com/query/latest/docs/framework/react/reference/useMutation |
Beta Was this translation helpful? Give feedback.
-
I'm using Vercel's According to the [current documentation](https://openapi-ts.dev/swr-openapi/use-mutate), |
Beta Was this translation helpful? Give feedback.
-
Ahh, I see. Looking at the SWR part of the docs, could not the same thing technique be applied to the Out of curiosity, why is the |
Beta Was this translation helpful? Give feedback.
-
Not the original author but I wanted to highlight that if the underlying endpoint is used to retrieve data, one would want to get the benefits offered by There can be practical reasons why an endpoint is |
Beta Was this translation helpful? Give feedback.
-
This is an interesting use case @bonniss. For background, the SWR fetcher defined inside swr-openapi looks like this: async ([_, path, init]) => {
const res = await client.GET(path, init);
if (res.error) {
throw res.error;
}
return res.data;
} As you can see, the GET method is used out of the box, which is why the types for the query hook only permit paths with GET requests. It sounds like you may need to drop down to SWR itself for your purposes. Here is a pattern that comes to mind: import useSWR from "swr";
import createClient from "openapi-fetch";
import type { paths } from "./your-api-types";
const client = createClient<paths>();
export function useExample() {
const body = {
something: "here",
};
return useSWR(["/api/example", body], async ([path, body]) => {
const res = await client.POST(path, { body });
if (res.error) {
throw res.error;
}
return res.data;
});
} If you want a reusable hook in the style of swr-openapi |
Beta Was this translation helpful? Give feedback.
-
Description
In my case, some endpoints are
POST
, but for getting data only. I cannot/do not want to change the API.The docs state that
path
can only beany endpoint that supports GET requests
.Proposal
Can we add one version of
useQuery
, kinda likeuseQueryFull
(okay, naming sucks) that supports valid paths regardless of method?Extra
Beta Was this translation helpful? Give feedback.
All reactions