1 | import { __rest } from "tslib";
|
2 | import equal from "@wry/equality";
|
3 | import { createFragmentMap, getFragmentDefinitions, getFragmentFromSelection, getMainDefinition, isField, resultKeyNameFromField, shouldInclude, } from "../utilities/index.js";
|
4 |
|
5 |
|
6 | export function equalByQuery(query, _a, _b, variables) {
|
7 | var aData = _a.data, aRest = __rest(_a, ["data"]);
|
8 | var bData = _b.data, bRest = __rest(_b, ["data"]);
|
9 | return (equal(aRest, bRest) &&
|
10 | equalBySelectionSet(getMainDefinition(query).selectionSet, aData, bData, {
|
11 | fragmentMap: createFragmentMap(getFragmentDefinitions(query)),
|
12 | variables: variables,
|
13 | }));
|
14 | }
|
15 | function equalBySelectionSet(selectionSet, aResult, bResult, context) {
|
16 | if (aResult === bResult) {
|
17 | return true;
|
18 | }
|
19 | var seenSelections = new Set();
|
20 |
|
21 |
|
22 |
|
23 | return selectionSet.selections.every(function (selection) {
|
24 |
|
25 |
|
26 | if (seenSelections.has(selection))
|
27 | return true;
|
28 | seenSelections.add(selection);
|
29 |
|
30 | if (!shouldInclude(selection, context.variables))
|
31 | return true;
|
32 |
|
33 |
|
34 | if (selectionHasNonreactiveDirective(selection))
|
35 | return true;
|
36 | if (isField(selection)) {
|
37 | var resultKey = resultKeyNameFromField(selection);
|
38 | var aResultChild = aResult && aResult[resultKey];
|
39 | var bResultChild = bResult && bResult[resultKey];
|
40 | var childSelectionSet = selection.selectionSet;
|
41 | if (!childSelectionSet) {
|
42 |
|
43 |
|
44 | return equal(aResultChild, bResultChild);
|
45 | }
|
46 | var aChildIsArray = Array.isArray(aResultChild);
|
47 | var bChildIsArray = Array.isArray(bResultChild);
|
48 | if (aChildIsArray !== bChildIsArray)
|
49 | return false;
|
50 | if (aChildIsArray && bChildIsArray) {
|
51 | var length_1 = aResultChild.length;
|
52 | if (bResultChild.length !== length_1) {
|
53 | return false;
|
54 | }
|
55 | for (var i = 0; i < length_1; ++i) {
|
56 | if (!equalBySelectionSet(childSelectionSet, aResultChild[i], bResultChild[i], context)) {
|
57 | return false;
|
58 | }
|
59 | }
|
60 | return true;
|
61 | }
|
62 | return equalBySelectionSet(childSelectionSet, aResultChild, bResultChild, context);
|
63 | }
|
64 | else {
|
65 | var fragment = getFragmentFromSelection(selection, context.fragmentMap);
|
66 | if (fragment) {
|
67 |
|
68 |
|
69 | if (selectionHasNonreactiveDirective(fragment))
|
70 | return true;
|
71 | return equalBySelectionSet(fragment.selectionSet,
|
72 |
|
73 |
|
74 |
|
75 |
|
76 | aResult, bResult, context);
|
77 | }
|
78 | }
|
79 | });
|
80 | }
|
81 | function selectionHasNonreactiveDirective(selection) {
|
82 | return (!!selection.directives && selection.directives.some(directiveIsNonreactive));
|
83 | }
|
84 | function directiveIsNonreactive(dir) {
|
85 | return dir.name.value === "nonreactive";
|
86 | }
|
87 |
|
\ | No newline at end of file |