Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Support for Request cancellation #251

Open
wgottschalk opened this issue May 12, 2020 · 1 comment · May be fixed by #296
Open

Add Support for Request cancellation #251

wgottschalk opened this issue May 12, 2020 · 1 comment · May be fixed by #296
Labels
enhancement💡 feature Feature: new addition or enhancement to existing solutions

Comments

@wgottschalk
Copy link

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

@fbartho
Copy link
Collaborator

fbartho commented Jun 25, 2020

This seems like a neat feature! Be aware that master includes ApolloClient @ 3.0 code in it, and they've delayed launching that version of ApolloClient so-- adding this feature may be a bit tricky depending on which version you want to ship it for.

@fbartho fbartho added enhancement💡 feature Feature: new addition or enhancement to existing solutions labels Jun 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement💡 feature Feature: new addition or enhancement to existing solutions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants