UNPKG

@graphql-tools/executor-http

Version:

A set of utils for faster development of GraphQL tools

26 lines (25 loc) 978 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.handleAsyncIterable = void 0; /* eslint-disable no-labels */ const fetch_1 = require("@whatwg-node/fetch"); const textDecoder = new fetch_1.TextDecoder(); async function* handleAsyncIterable(asyncIterable) { outer: for await (const chunk of asyncIterable) { const chunkStr = typeof chunk === 'string' ? chunk : textDecoder.decode(chunk, { stream: true }); for (const part of chunkStr.split('\n\n')) { if (part) { const eventStr = part.split('event: ')[1]; const dataStr = part.split('data: ')[1]; if (eventStr === 'complete') { break outer; } if (dataStr) { const data = JSON.parse(dataStr); yield data.payload || data; } } } } } exports.handleAsyncIterable = handleAsyncIterable;