Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return new Observable(observer => {
fetch(uri, options)
.then(response => {
operation.setContext({ response })
return response
})
.then(parseAndCheckHttpResponse(operation))
.then(result => {
// we have data and can send it to back up the link chain
observer.next(result)
observer.complete()
return result
})
.catch(err => {
if (err.result && err.result.errors && err.result.data) {
observer.next(err.result)
}
observer.error(err)
})
})
} else {
return new Observable(observer => {
fetcher(chosenURI, options)
.then(response => {
// Make the raw response available in the context.
operations.forEach(operation => operation.setContext({ response }));
return response;
})
.then(parseAndCheckHttpResponse(operations))
.then(result => {
// we have data and can send it to back up the link chain
observer.next(result);
observer.complete();
return result;
})
.catch(err => {
// fetch was cancelled so its already been cleaned up in the unsubscribe
if (err.name === 'AbortError') return;
// if it is a network error, BUT there is graphql result info
// fire the next observer before calling error
// this gives apollo-client (and react-apollo) the `graphqlErrors` and `networErrors`
// to pass to UI
// this should only happen if we *also* have data as part of the response key per
// the spec
if (err.result && err.result.errors && err.result.data) {
return new Observable(observer => {
fetcher(chosenURI, options)
.then(response => {
operation.setContext({ response });
return response;
})
.then(parseAndCheckHttpResponse(operation))
.then(result => {
// we have data and can send it to back up the link chain
observer.next(result);
observer.complete();
return result;
})
.catch(err => {
// fetch was cancelled so it's already been cleaned up in the unsubscribe
if (err.name === 'AbortError') return;
// if it is a network error, BUT there is graphql result info
// fire the next observer before calling error
// this gives apollo-client (and react-apollo) the `graphqlErrors` and `networErrors`
// to pass to UI
// this should only happen if we *also* have data as part of the response key per
// the spec
if (err.result && err.result.errors && err.result.data) {
return new Observable(observer => {
// Allow aborting fetch, if supported.
const { controller, signal } = createSignalIfSupported()
if (controller) options.signal = signal
linkFetch(uri, options)
.then(response => {
// Forward the response on the context.
operation.setContext({ response })
return response
})
.then(parseAndCheckHttpResponse(operation))
.then(result => {
observer.next(result)
observer.complete()
})
.catch(error => {
if (error.name === 'AbortError')
// Fetch was aborted.
return
if (error.result && error.result.errors && error.result.data)
// There is a GraphQL result to forward.
observer.next(error.result)
observer.error(error)
})