Cancellation
It is possible to cancel a request using an AbortController
signal.
<script setup>
import { gql } from 'nuxt-graphql-request/utils';
const { $graphql } = useNuxtApp();
const fetchSomething = async () => {
const query = gql``;
const abortController = new AbortController();
const planets = await $graphql.default.request({
document: query,
signal: abortController.signal,
});
abortController.abort();
};
</script>
In Node environment, AbortController is supported since version v14.17.0. For Node.js v12 you can use abort-controller polyfill.
import 'abort-controller/polyfill';
const abortController = new AbortController();