forked from christfellowshipchurch/web-app-v2
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathhttpLink.js
More file actions
34 lines (32 loc) · 1.11 KB
/
httpLink.js
File metadata and controls
34 lines (32 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import fetch from 'cross-fetch';
import { HttpLink } from '@apollo/client';
const httpLink = new HttpLink({
uri:
process.env.NEXT_PUBLIC_APOLLOS_API || 'https://longhollow-cdn.global.ssl.fastly.net', // Server URL (must be absolute)
credentials: 'same-origin', // Additional fetch() options like `credentials` or `headers`
fetch: (url, options) => {
// Strip excess whitespace to help mitigate query length issue
const compressedUrl = url.replace(/(%20)+/g, '%20');
return fetch(compressedUrl, options).then(async response => {
if (process.env.NODE_ENV !== 'production' && !response.ok) {
let bodyText = null;
try {
bodyText = await response.clone().text();
} catch (error) {
bodyText = null;
}
console.error('[ApolloNetworkError]', {
url: compressedUrl,
status: response.status,
statusText: response.statusText,
method: options?.method,
headers: options?.headers,
bodyText,
});
}
return response;
});
},
useGETForQueries: true,
});
export default httpLink;