Diizzayy / nuxt-graphql-client

⚡️ Minimal GraphQL Client + Code Generation for Nuxt3
https://nuxt-graphql-client.web.app
MIT License
366 stars 43 forks source link

add timeout feature #481

Open tasiotas opened 7 months ago

tasiotas commented 7 months ago

Your use case

Hi,

I am not sure if its currently possible to handle long requests by specifying timeout and catching it.

useFetch/$fetch/ofetch does support it very nicely.

await $fetch('https://httpbin.org/delay/10', {
  timeout: 1000,
}).catch(() => {
  console.log('timeout')
})

The solution you'd like

I would like to specify timeout per composable and define global default in config

await useAsyncGql({
  operation: 'product',
  variables: { slug },
  options: {
    timeout: 1000,
  },
}).catch(() => {
  console.log('error')
})

Possible alternatives

Not aware of any. Adding timeout to options of useAsyncGql doesnt work

Additional information

No response

toknT commented 7 months ago

find a timeout feature too, I set a timeout function globally in flutter's graphql client .In this library current I do like this

 showLoading();
 GqlLogin({ username: form.username, password: form.password }).then((data) => {
        // your code after login success
    }).catch((error) => {
        setTimeout(() => {
            closeLoading();
            if (error.gqlErrors[0].message) {
                showErrorToast(error.gqlErrors[0].message);
            } else {
                showErrorToast('network error');
            }
        }, 300)
    });

Because I can get gqlErrors from my server , if not it maybe timeout. lol