graphql-yoga
Version:
<div align="center"><img src="./website/public/cover.png" width="720" /></div>
21 lines (20 loc) • 930 B
JavaScript
import { isAsyncIterable } from '@graphql-tools/utils';
import { getResponseInitByRespectingErrors } from '../../error.js';
import { jsonStringifyResult } from './stringify.js';
export function processRegularResult(executionResult, fetchAPI, acceptedHeader) {
if (isAsyncIterable(executionResult)) {
return new fetchAPI.Response(null, {
status: 406,
statusText: 'Not Acceptable',
headers: {
accept: 'application/json; charset=utf-8, application/graphql-response+json; charset=utf-8',
},
});
}
const headersInit = {
'Content-Type': acceptedHeader + '; charset=utf-8',
};
const responseInit = getResponseInitByRespectingErrors(executionResult, headersInit, acceptedHeader === 'application/json');
const responseBody = jsonStringifyResult(executionResult);
return new fetchAPI.Response(responseBody, responseInit);
}