Repository URL to install this package:
|
Version:
7.1.2 ▾
|
import { OneResponse, OneResponseSerialized } from '../typings'
import { fromHeadersToSerialized } from './fromHeadersToSerialized'
/**
* @see https://github.com/bitinn/node-fetch/tree/master/src
* @see https://github.com/apollographql/apollo-server/blob/master/packages/apollo-server-env/src/index.ts
* @see https://github.com/apollographql/apollo-server/blob/master/packages/apollo-server-env/src/index.d.ts *
*/
export function fromResponseToSerialized(
response: OneResponse | Response
): OneResponseSerialized {
const temp: any = {} as any
const clean: any = {} as OneResponseSerialized
Object.getOwnPropertySymbols(response).forEach(symbol => {
// String(symbol) !== 'Symbol(Body internals)'
if (!response[symbol].body) {
temp[String(symbol)] = response[symbol]
}
})
// const combined = { ...temp, ...response, ...temp['Symbol(Body internals)'] }
const asResponse = response as Response
const asOneResponse = response as OneResponse
if (asResponse.type) {
clean.type = asResponse.type
}
if (asResponse.status) {
clean.status = asResponse.status
}
if (asResponse.statusText) {
clean.statusText = asResponse.statusText
}
if (asResponse.url) {
clean.url = asResponse.url
}
if (asResponse.headers) {
clean.headers = fromHeadersToSerialized(asResponse.headers)
}
if (asOneResponse.data) {
clean.data = asOneResponse.data
}
if (asOneResponse.prettyError) {
// not that helpful, is on clean already
}
return clean
}