@n1ru4l/graphql-live-query-patch-jsondiffpatch
Version:
[](https://www.npmjs.com/package/@n1ru4l/graphql-live-query-patch-jsondiffpatch) [ • 1.15 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateJSONDiffPatch = void 0;
const graphql_live_query_patch_1 = require("@n1ru4l/graphql-live-query-patch");
const json_patch_plus_1 = require("@n1ru4l/json-patch-plus");
/**
* We use common connection/pagination fields for
* generating more efficient list patches.
*/
const objectHash = (object) => {
if (object["__typename"] != null && object["id"] != null) {
return `${object["__typename"]}:${object["id"]}`;
}
else if (object["id"] != null) {
return object["id"];
}
else if (object["node"] != null) {
return objectHash(object["node"]);
}
else if (object["cursor"] != null) {
return object["cursor"];
}
else if (object["_id"] != null) {
return object["_id"];
}
};
const generateJSONDiffPatch = (left, right) => {
const delta = (0, json_patch_plus_1.diff)({ left, right }, {
objectHash,
});
if (delta === undefined) {
return graphql_live_query_patch_1.noDiffSymbol;
}
return delta;
};
exports.generateJSONDiffPatch = generateJSONDiffPatch;