fetch-multipart-graphql
Advanced tools
Comparing version 1.0.10 to 1.0.11
@@ -55,2 +55,4 @@ 'use strict'; | ||
PatchResolver.prototype.handleChunk = function (data) { | ||
var _this = this; | ||
this.chunkBuffer += data; | ||
@@ -63,13 +65,6 @@ | ||
this.chunkBuffer = newBuffer; | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
try { | ||
for (var _iterator = parts[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var part = _step.value; | ||
if (this.processedChunks === 0) { | ||
this.previousResponse = part; | ||
this.onResponse(this.previousResponse); | ||
if (parts.length) { | ||
parts.forEach(function (part) { | ||
if (_this.processedChunks === 0) { | ||
_this.previousResponse = part; | ||
} else { | ||
@@ -79,25 +74,12 @@ if (!(Array.isArray(part.path) && typeof part.data !== 'undefined')) { | ||
} | ||
this.previousResponse = Object.assign({}, this.previousResponse, { | ||
data: applyPatch(this.previousResponse.data, part.path, part.data), | ||
errors: mergeErrors(this.previousResponse.errors, part.errors) | ||
_this.previousResponse = Object.assign({}, _this.previousResponse, { | ||
data: applyPatch(_this.previousResponse.data, part.path, part.data), | ||
errors: mergeErrors(_this.previousResponse.errors, part.errors) | ||
}); | ||
this.onResponse(this.previousResponse); | ||
} | ||
this.processedChunks += 1; | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
_this.processedChunks += 1; | ||
}); | ||
// don't need to re-trigger every intermediate state | ||
this.onResponse(this.previousResponse); | ||
} | ||
}; |
{ | ||
"name": "fetch-multipart-graphql", | ||
"version": "1.0.10", | ||
"version": "1.0.11", | ||
"description": "Cross browser function to fetch and parse streaming multipart graphql responses.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -133,3 +133,2 @@ import { PatchResolver } from '../PatchResolver'; | ||
expect(onResponse.mock.calls[0][0]).toMatchSnapshot(); | ||
expect(onResponse.mock.calls[1][0]).toMatchSnapshot(); | ||
}); | ||
@@ -149,3 +148,2 @@ | ||
expect(onResponse.mock.calls[0][0]).toMatchSnapshot(); | ||
expect(onResponse.mock.calls[1][0]).toMatchSnapshot(); | ||
onResponse.mockClear(); | ||
@@ -152,0 +150,0 @@ |
@@ -49,20 +49,21 @@ import { parseMultipartHttp } from './parseMultipartHttp'; | ||
this.chunkBuffer = newBuffer; | ||
for (const part of parts) { | ||
if (this.processedChunks === 0) { | ||
this.previousResponse = part; | ||
this.onResponse(this.previousResponse); | ||
} else { | ||
if (!(Array.isArray(part.path) && typeof part.data !== 'undefined')) { | ||
throw new Error('invalid patch format ' + JSON.stringify(part, null, 2)); | ||
if (parts.length) { | ||
parts.forEach(part => { | ||
if (this.processedChunks === 0) { | ||
this.previousResponse = part; | ||
} else { | ||
if (!(Array.isArray(part.path) && typeof part.data !== 'undefined')) { | ||
throw new Error('invalid patch format ' + JSON.stringify(part, null, 2)); | ||
} | ||
this.previousResponse = { | ||
...this.previousResponse, | ||
data: applyPatch(this.previousResponse.data, part.path, part.data), | ||
errors: mergeErrors(this.previousResponse.errors, part.errors), | ||
}; | ||
} | ||
this.previousResponse = { | ||
...this.previousResponse, | ||
data: applyPatch(this.previousResponse.data, part.path, part.data), | ||
errors: mergeErrors(this.previousResponse.errors, part.errors), | ||
}; | ||
this.onResponse(this.previousResponse); | ||
} | ||
this.processedChunks += 1; | ||
this.processedChunks += 1; | ||
}); | ||
// don't need to re-trigger every intermediate state | ||
this.onResponse(this.previousResponse); | ||
} | ||
}; |
Sorry, the diff of this file is not supported yet
170206
683