I'm implementing autocomplete right now using apollo-link-rest. Everytime the search term changes, apollo client (useQuery) will kick off a new request. However, I don't want to have my server keep doing expensive search ranking for a result that I'm going to ignore so I'd like to cancel the request.
maybe something like?
const MyComponent = () => {
const abortController = useRef(new AbortController());
const [searchTerm, setSearchTerm] = useState("");
useEffect(() => {
abortController.current.abort()
abortController.current = new AbortController()
}, [searchTerm])
const { error, loading, data } = useQuery(SearchQuery, {
variables: { searchTerm }
context: { fetchOptions: { signal: abortController.current.signal } }
})
}
All you really have to do is grab this fetchOptions field from context and make it available in requestOptions and everything should workout correctly
I'm implementing autocomplete right now using apollo-link-rest. Everytime the search term changes, apollo client (useQuery) will kick off a new request. However, I don't want to have my server keep doing expensive search ranking for a result that I'm going to ignore so I'd like to cancel the request.
maybe something like?
All you really have to do is grab this fetchOptions field from context and make it available in requestOptions and everything should workout correctly