UNPKG

@n1ru4l/graphql-live-query-patch-jsondiffpatch

Version:

[![npm version](https://img.shields.io/npm/v/@n1ru4l/graphql-live-query-patch-jsondiffpatch.svg)](https://www.npmjs.com/package/@n1ru4l/graphql-live-query-patch-jsondiffpatch) [![npm downloads](https://img.shields.io/npm/dm/@n1ru4l/graphql-live-query-patc

33 lines (32 loc) 906 B
import { noDiffSymbol, } from "@n1ru4l/graphql-live-query-patch"; import { diff } from "@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"]; } }; export const generateJSONDiffPatch = (left, right) => { const delta = diff({ left, right }, { objectHash, }); if (delta === undefined) { return noDiffSymbol; } return delta; };