flat-fuchsia
flat-fuchsia6mo ago

How can one disable retry on failed queries ?

I have a valid case of checking if entity is present, the api responds with 404 as it should and I need to adjust the UI. In current default behavior, the 404 is retried, but it should not retry as 404 is expected.
5 Replies
kapa.ai
kapa.ai6mo ago
Hi @i.stoica. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- You can disable retry on failed queries by setting the retry option to false in the queryOptions property of hooks like useList, useCreate, useTable, useForm, etc. Here's an example:
const { data, mutate } = useShow({
resource: "posts",
id: "1",
queryOptions: {
retry: false,
},
});
const { data, mutate } = useShow({
resource: "posts",
id: "1",
queryOptions: {
retry: false,
},
});
If you want to disable retries globally, you can do so in the reactQueryClientConfig prop of the <Refine> component. Here's an example:
<Refine
reactQueryClientConfig={{
defaultOptions: {
queries: {
retry: false,
},
},
}}
>
{/* Your app content */}
</Refine>
<Refine
reactQueryClientConfig={{
defaultOptions: {
queries: {
retry: false,
},
},
}}
>
{/* Your app content */}
</Refine>
You can also set custom retry logic. For example, you can disable retries when the status code is 404:
<Refine
reactQueryClientConfig={{
defaultOptions: {
queries: {
retry: (retryCount, error) => {
if (error.statusCode === 404) {
return false;
}
return true;
},
},
},
}}
>
{/* Your app content */}
</Refine>
<Refine
reactQueryClientConfig={{
defaultOptions: {
queries: {
retry: (retryCount, error) => {
if (error.statusCode === 404) {
return false;
}
return true;
},
},
},
}}
>
{/* Your app content */}
</Refine>
For more information, you can refer to the React Query documentation on query retries (https://react-query.tanstack.com/guides/query-retries#_top) and the Refine documentation on the Refine component (https://refine.dev/docs/core/components/refine-config/#reactqueryclientconfig). Sources: - Github Issue (closed): [BUG] @pankod/refine-nhost is not handling graphQL error responses > Comments Part 4 (https://github.com/refinedev/refine/issues/1794) - Github Issue (closed): [BUG] @pankod/refine-nhost is not handling graphQL error responses > Comments Part 6 (https://github.com/refinedev/refine/issues/1794) ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai6mo ago
<@180601470268211200> kapa.ai is still learning and improving, please let us know how it did by reacting below
flat-fuchsia
flat-fuchsia6mo ago
Refine component has no such reactQueryClientConfig option The queryOptions retry: false in useShow is not respected, I still see the query being performed twice.
conscious-sapphire
conscious-sapphire6mo ago
Hello @i.stoica - you can change client config like this https://example.admin.refine.dev/orders/show/1 - it's performed twice probably because of this https://example.admin.refine.dev/orders/show/1
Finefoods Ant Design Admin Panel - refine
Web site created using refine
flat-fuchsia
flat-fuchsia6mo ago
Thank you @Alican Erdurmaz