fetch-multipart-graphql
Advanced tools
Comparing version 1.0.7 to 1.0.8
@@ -67,4 +67,5 @@ 'use strict'; | ||
rest = rest.replace(terminatingBoundary, ''); | ||
var uint = new TextEncoder().encode(rest); | ||
if (rest.length < contentLength) { | ||
if (uint.length < contentLength) { | ||
// still waiting for more body to be sent; | ||
@@ -77,4 +78,4 @@ return { | ||
var body = rest.substring(0, contentLength); | ||
var nextBuffer = rest.substring(contentLength); | ||
var body = new TextDecoder().decode(uint.subarray(0, contentLength)); | ||
var nextBuffer = new TextDecoder().decode(uint.subarray(contentLength)); | ||
var part = JSON.parse(body); | ||
@@ -81,0 +82,0 @@ var newParts = [].concat(_toConsumableArray(previousParts), [part]); |
{ | ||
"name": "fetch-multipart-graphql", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"description": "Cross browser function to fetch and parse streaming multipart graphql responses.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -37,2 +37,2 @@ # fetch-multipart-graphql | ||
Tested in the latest Chrome, Firefox, Safari, Edge, and Internet Explorer 11. | ||
Tested in the latest Chrome, Firefox, Safari, Edge, and Internet Explorer 11. Requires a polyfill for TextEncoder/Decoder. Since only utf-8 encoding is required, it's recommended to use [text-encoding-utf-8](https://www.npmjs.com/package/text-encoding-utf-8) to minimize impact on bundle size. |
import { PatchResolver } from '../PatchResolver'; | ||
import { TextEncoder, TextDecoder } from 'util'; | ||
// polyfill TextDecoder/Encoder for node | ||
global.TextEncoder = TextEncoder; | ||
global.TextDecoder = TextDecoder; | ||
@@ -25,5 +29,5 @@ const chunk1 = [ | ||
'Content-Type: application/json', | ||
'Content-Length: 84', | ||
'Content-Length: 85', | ||
'', | ||
'{"path":["viewer","currencies"],"data":["USD","GBP","EUR","CAD","AUD","CHF","MXN"]}\n', | ||
'{"path":["viewer","currencies"],"data":["USD","GBP","EUR","CAD","AUD","CHF","😂"]}\n', // test unicode | ||
].join('\r\n'); | ||
@@ -35,5 +39,5 @@ | ||
'Content-Type: application/json', | ||
'Content-Length: 126', | ||
'Content-Length: 127', | ||
'', | ||
'{"path":["viewer","currencies"],"data":["USD","GBP","EUR","CAD","AUD","CHF","MXN"],"errors":[{"message":"Not So Bad Error"}]}\n', | ||
'{"path":["viewer","currencies"],"data":["USD","GBP","EUR","CAD","AUD","CHF","😂"],"errors":[{"message":"Not So Bad Error"}]}\n', | ||
].join('\r\n'); | ||
@@ -68,3 +72,3 @@ | ||
viewer: { | ||
currencies: ['USD', 'GBP', 'EUR', 'CAD', 'AUD', 'CHF', 'MXN'], | ||
currencies: ['USD', 'GBP', 'EUR', 'CAD', 'AUD', 'CHF', '😂'], | ||
user: { profile: null }, | ||
@@ -79,3 +83,3 @@ }, | ||
viewer: { | ||
currencies: ['USD', 'GBP', 'EUR', 'CAD', 'AUD', 'CHF', 'MXN'], | ||
currencies: ['USD', 'GBP', 'EUR', 'CAD', 'AUD', 'CHF', '😂'], | ||
user: { profile: { displayName: 'Steven Seagal' } }, | ||
@@ -118,3 +122,3 @@ }, | ||
viewer: { | ||
currencies: ['USD', 'GBP', 'EUR', 'CAD', 'AUD', 'CHF', 'MXN'], | ||
currencies: ['USD', 'GBP', 'EUR', 'CAD', 'AUD', 'CHF', '😂'], | ||
user: { profile: null }, | ||
@@ -138,3 +142,3 @@ }, | ||
viewer: { | ||
currencies: ['USD', 'GBP', 'EUR', 'CAD', 'AUD', 'CHF', 'MXN'], | ||
currencies: ['USD', 'GBP', 'EUR', 'CAD', 'AUD', 'CHF', '😂'], | ||
user: { profile: { displayName: 'Steven Seagal' } }, | ||
@@ -159,3 +163,3 @@ }, | ||
viewer: { | ||
currencies: ['USD', 'GBP', 'EUR', 'CAD', 'AUD', 'CHF', 'MXN'], | ||
currencies: ['USD', 'GBP', 'EUR', 'CAD', 'AUD', 'CHF', '😂'], | ||
user: { profile: null }, | ||
@@ -184,3 +188,3 @@ }, | ||
viewer: { | ||
currencies: ['USD', 'GBP', 'EUR', 'CAD', 'AUD', 'CHF', 'MXN'], | ||
currencies: ['USD', 'GBP', 'EUR', 'CAD', 'AUD', 'CHF', '😂'], | ||
user: { profile: null }, | ||
@@ -198,3 +202,3 @@ }, | ||
viewer: { | ||
currencies: ['USD', 'GBP', 'EUR', 'CAD', 'AUD', 'CHF', 'MXN'], | ||
currencies: ['USD', 'GBP', 'EUR', 'CAD', 'AUD', 'CHF', '😂'], | ||
user: { profile: { displayName: 'Steven Seagal' } }, | ||
@@ -225,3 +229,3 @@ }, | ||
viewer: { | ||
currencies: ['USD', 'GBP', 'EUR', 'CAD', 'AUD', 'CHF', 'MXN'], | ||
currencies: ['USD', 'GBP', 'EUR', 'CAD', 'AUD', 'CHF', '😂'], | ||
user: { profile: null }, | ||
@@ -249,3 +253,3 @@ }, | ||
viewer: { | ||
currencies: ['USD', 'GBP', 'EUR', 'CAD', 'AUD', 'CHF', 'MXN'], | ||
currencies: ['USD', 'GBP', 'EUR', 'CAD', 'AUD', 'CHF', '😂'], | ||
user: { profile: null }, | ||
@@ -261,3 +265,3 @@ }, | ||
viewer: { | ||
currencies: ['USD', 'GBP', 'EUR', 'CAD', 'AUD', 'CHF', 'MXN'], | ||
currencies: ['USD', 'GBP', 'EUR', 'CAD', 'AUD', 'CHF', '😂'], | ||
user: { profile: { displayName: 'Steven Seagal' } }, | ||
@@ -264,0 +268,0 @@ }, |
@@ -50,4 +50,5 @@ const boundary = '\r\n---\r\n'; | ||
rest = rest.replace(terminatingBoundary, ''); | ||
const uint = new TextEncoder().encode(rest); | ||
if (rest.length < contentLength) { | ||
if (uint.length < contentLength) { | ||
// still waiting for more body to be sent; | ||
@@ -60,4 +61,4 @@ return { | ||
const body = rest.substring(0, contentLength); | ||
const nextBuffer = rest.substring(contentLength); | ||
const body = new TextDecoder().decode(uint.subarray(0, contentLength)); | ||
const nextBuffer = new TextDecoder().decode(uint.subarray(contentLength)); | ||
const part = JSON.parse(body); | ||
@@ -64,0 +65,0 @@ const newParts = [...previousParts, part]; |
163715
765