apollo-link-multipart
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -42,4 +42,4 @@ 'use strict'; | ||
headers: { | ||
accept: 'application/json, multipart/mixed', | ||
...context.headers, | ||
accept: 'application/json, multipart/mixed', | ||
}, | ||
@@ -58,21 +58,21 @@ }; | ||
.then(async (parts) => { | ||
if (parts[Symbol.asyncIterator] < 'u') { | ||
if (isAsyncIterable(parts)) { | ||
const cache = context.cache; | ||
let first = true; | ||
for await (const part of parts) { | ||
if (!part.json) | ||
throw new Error(`Expected part to be of json type but got:\n${part.headers}\n${part.body}`); | ||
if (cache === undefined) { | ||
observer.next(part); | ||
// @ts-ignore | ||
observer.next(part.body); | ||
continue; | ||
} | ||
// TODO: Fix types | ||
const payload = part.body; | ||
if (first) { | ||
observer.next({ | ||
data: part.data, | ||
}); | ||
observer.next(payload); | ||
first = false; | ||
} | ||
else { | ||
const patch_data = nestie.nestie({ | ||
[part.path.join('.')]: part.data, | ||
}); | ||
const original_data = cache.read({ | ||
const data = cache.read({ | ||
query: operation.query, | ||
@@ -84,3 +84,6 @@ variables: operation.variables, | ||
}); | ||
const new_result = deepmerge__default['default'](original_data, patch_data); | ||
const patch_data = nestie.nestie({ | ||
[payload.path.join('.')]: payload.data, | ||
}); | ||
const new_result = deepmerge__default['default'](data, patch_data); | ||
cache.write({ | ||
@@ -92,5 +95,3 @@ result: new_result, | ||
}); | ||
observer.next({ | ||
data: part.data, | ||
}); | ||
observer.next(payload); | ||
} | ||
@@ -107,3 +108,12 @@ } | ||
}; | ||
function isAsyncIterable(input) { | ||
return (typeof input === 'object' && | ||
input !== null && | ||
// The AsyncGenerator check is for Safari on iOS which currently does not have | ||
// Symbol.asyncIterator implemented | ||
// That means every custom AsyncIterable must be built using a AsyncGeneratorFunction (async function * () {}) | ||
(input[Symbol.toStringTag] === 'AsyncGenerator' || | ||
(Symbol.asyncIterator && Symbol.asyncIterator in input))); | ||
} | ||
exports.createMultipartLink = createMultipartLink; |
{ | ||
"name": "apollo-link-multipart", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "An Apollo link for multipart responses", | ||
@@ -37,3 +37,3 @@ "keywords": [ | ||
"prepublishOnly": "yarn build", | ||
"test": "uvu -r ts-node/register tests", | ||
"test": "uvu -r ts-node/register -i mocks tests", | ||
"typecheck": "tsc --noEmit" | ||
@@ -52,17 +52,17 @@ }, | ||
"deepmerge": "^4.2.2", | ||
"meros": "^1.0.0-beta.4", | ||
"meros": "^1.1.2", | ||
"nestie": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"@apollo/client": "^3.3.0-rc.0", | ||
"@apollo/client": "3.3.9", | ||
"@marais/tsconfig": "0.0.1", | ||
"@rollup/plugin-node-resolve": "10.0.0", | ||
"@types/node": "14.14.7", | ||
"graphql": "^15.4.0", | ||
"@rollup/plugin-node-resolve": "11.1.1", | ||
"@types/node": "14.14.26", | ||
"graphql": "^15.5.0", | ||
"graphql-tag": "^2.11.0", | ||
"prettier": "2.1.2", | ||
"rollup": "2.33.1", | ||
"prettier": "2.2.1", | ||
"rollup": "2.38.5", | ||
"rollup-plugin-typescript2": "0.29.0", | ||
"ts-node": "^9.0.0", | ||
"typescript": "4.0.5", | ||
"ts-node": "9.1.1", | ||
"typescript": "4.1.5", | ||
"uvu": "0.4.1", | ||
@@ -75,5 +75,5 @@ "zen-observable": "^0.8.15" | ||
"volta": { | ||
"node": "15.1.0", | ||
"yarn": "1.22.5" | ||
"node": "15.8.0", | ||
"yarn": "1.22.10" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
13558
215
2
Updatedmeros@^1.1.2