@jsb188/graphql 1.1.11 → 1.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/audience.d.ts +343 -0
- package/cache/config.ts +58 -24
- package/cache/index.chat-activity.test.ts +119 -0
- package/cache/index.chat.test.ts +92 -0
- package/cache/index.helpers.ts +96 -0
- package/cache/index.regression.test.ts +149 -0
- package/cache/index.test.ts +370 -42
- package/cache/index.ts +326 -799
- package/cache/optimistic-ui-runtime.ts +46 -0
- package/cache/optimistic-ui.ts +401 -0
- package/cache/persist.ts +98 -19
- package/cache/store.ts +22 -64
- package/cache/value.helpers.ts +17 -0
- package/{drafts/store.ts → client/draft-persistence-indexed-db.ts} +19 -3
- package/{drafts/index.ts → client/draft-persistence.ts} +5 -2
- package/client/index.ts +3 -2
- package/client/request.helpers.ts +14 -0
- package/client/request.ts +130 -215
- package/deno.lock +17 -0
- package/deno.test.json +2 -0
- package/gql/fragments/agentMemoryFragments.ts +5 -1
- package/gql/fragments/agentNoteFragments.ts +150 -0
- package/gql/fragments/aiChatFragments.ts +36 -10
- package/gql/fragments/audienceFragments.ts +141 -0
- package/gql/fragments/campaignFragments.ts +415 -126
- package/gql/fragments/dataTableFragments.ts +48 -80
- package/gql/fragments/emailFragments.ts +28 -23
- package/gql/fragments/fieldDocFragments.ts +222 -40
- package/gql/fragments/inboundContactFragments.ts +2 -0
- package/gql/fragments/logFragments.ts +93 -2
- package/gql/fragments/organizationFragments.ts +10 -0
- package/gql/fragments/qrCodeFragments.ts +29 -0
- package/gql/fragments/scheduleFragments.ts +652 -140
- package/gql/fragments/sheetFragments.ts +84 -373
- package/gql/fragments/storageFragments.ts +25 -1
- package/gql/fragments/workflowFragments.ts +13 -1
- package/gql/mutations/agentMemoryMutations.ts +32 -0
- package/gql/mutations/agentNoteMutations.ts +62 -0
- package/gql/mutations/aiChatMutations.ts +36 -4
- package/gql/mutations/audienceMutations.ts +71 -0
- package/gql/mutations/authMutations.ts +45 -1
- package/gql/mutations/billingMutations.ts +24 -0
- package/gql/mutations/campaignMutations.ts +170 -127
- package/gql/mutations/contactMutations.ts +23 -0
- package/gql/mutations/dataTableMutations.ts +18 -75
- package/gql/mutations/fieldDocMutations.ts +162 -13
- package/gql/mutations/index.ts +8 -5
- package/gql/mutations/organizationMutations.ts +6 -0
- package/gql/mutations/qrCodeMutations.ts +20 -0
- package/gql/mutations/scheduleMutations.ts +1052 -354
- package/gql/mutations/sheetMutations.ts +62 -118
- package/gql/mutations/storageMutations.ts +0 -1
- package/gql/mutations/workflowMutations.ts +18 -0
- package/gql/queries/agentMemoryQueries.ts +6 -0
- package/gql/queries/agentNoteQueries.ts +89 -0
- package/gql/queries/aiChatQueries.ts +56 -4
- package/gql/queries/audienceQueries.ts +128 -0
- package/gql/queries/authQueries.ts +6 -0
- package/gql/queries/billingQueries.ts +95 -6
- package/gql/queries/campaignQueries.ts +132 -23
- package/gql/queries/dataTableQueries.ts +24 -65
- package/gql/queries/emailQueries.ts +18 -61
- package/gql/queries/emailReplyReportQueries.ts +76 -0
- package/gql/queries/fieldDocQueries.ts +100 -92
- package/gql/queries/inboundContactQueries.ts +4 -0
- package/gql/queries/index.ts +3 -1
- package/gql/queries/logQueries.ts +62 -7
- package/gql/queries/organizationQueries.ts +13 -0
- package/gql/queries/qrCodeQueries.ts +20 -0
- package/gql/queries/scheduleQueries.ts +633 -257
- package/gql/queries/sheetQueries.ts +59 -152
- package/gql/queries/workflowQueries.ts +10 -4
- package/hooks/index.helpers.test.ts +50 -0
- package/hooks/index.helpers.ts +52 -0
- package/hooks/index.ts +863 -685
- package/hooks/use-agentMemory-mtn.ts +29 -31
- package/hooks/use-agentMemory-qry.ts +15 -3
- package/hooks/use-agentNote-mtn.ts +82 -0
- package/hooks/use-agentNote-qry.ts +190 -0
- package/hooks/use-agentNote-recovery.helpers.test.ts +68 -0
- package/hooks/use-agentNote-recovery.helpers.ts +58 -0
- package/hooks/use-agentNote-recovery.ts +72 -0
- package/hooks/use-aiChat-mtn.ts +96 -112
- package/hooks/use-aiChat-qry.helpers.test.ts +63 -0
- package/hooks/use-aiChat-qry.helpers.ts +124 -0
- package/hooks/use-aiChat-qry.ts +229 -383
- package/hooks/use-aiChat-stream-mtn.ts +14 -0
- package/hooks/use-audience-mtn.ts +194 -0
- package/hooks/use-audience-qry.helpers.test.ts +80 -0
- package/hooks/use-audience-qry.helpers.ts +63 -0
- package/hooks/use-audience-qry.ts +330 -0
- package/hooks/use-auth-mtn.ts +30 -1
- package/hooks/use-billing-mtn.ts +31 -0
- package/hooks/use-billing-qry.ts +76 -0
- package/hooks/use-campaign-generation-recovery.ts +53 -0
- package/hooks/use-campaign-mtn.ts +224 -165
- package/hooks/use-campaign-qry.helpers.ts +40 -0
- package/hooks/use-campaign-qry.ts +631 -54
- package/hooks/use-dataTable-mtn.ts +23 -115
- package/hooks/use-dataTable-qry.ts +66 -916
- package/hooks/use-email-qry.helpers.ts +37 -0
- package/hooks/use-email-qry.ts +33 -178
- package/hooks/use-emailCampaignReplyReport-qry.ts +27 -0
- package/hooks/use-fieldDoc-mtn.ts +244 -32
- package/hooks/use-fieldDoc-qry.helpers.test.ts +65 -0
- package/hooks/use-fieldDoc-qry.helpers.ts +49 -0
- package/hooks/use-fieldDoc-qry.ts +134 -102
- package/hooks/use-inboundContact-qry.ts +7 -9
- package/hooks/use-log-mtn.ts +25 -12
- package/hooks/use-log-qry.ts +99 -46
- package/hooks/use-organization-qry.ts +16 -60
- package/hooks/use-publicFormEmail-mtn.ts +27 -0
- package/hooks/use-qrCode-mtn.ts +40 -0
- package/hooks/use-qrCode-qry.ts +78 -0
- package/hooks/use-schedule-mtn.ts +506 -333
- package/hooks/use-schedule-qry.ts +682 -101
- package/hooks/use-schedule-reactive.ts +486 -0
- package/hooks/use-sheet-mtn.ts +91 -199
- package/hooks/use-sheet-qry.ts +84 -238
- package/hooks/use-storage-qry.ts +84 -61
- package/hooks/use-workflow-mtn.ts +39 -22
- package/hooks/use-workflow-qry.ts +40 -61
- package/libs/ai-chat-outgoing.helpers.ts +153 -0
- package/libs/ai-chat-outgoing.ts +11 -0
- package/libs/ai-chat-outgoing.types.ts +25 -0
- package/libs/ai-chat-run-realtime.ts +20 -0
- package/libs/ai-chat-submission-realtime.ts +150 -0
- package/libs/fragment-realtime-sequence.ts +55 -0
- package/libs/fragment-recovery.test.ts +326 -0
- package/libs/fragment-recovery.ts +325 -0
- package/libs/open-sheet.ts +138 -0
- package/libs/orchestrator-realtime.helpers.test.ts +229 -0
- package/libs/orchestrator-realtime.helpers.ts +317 -0
- package/libs/orchestrator-realtime.ts +433 -0
- package/libs/request-cache-regression.test.ts +122 -0
- package/{client → libs}/request-managed-session.test.ts +1 -1
- package/libs/request-no-store.test.ts +419 -0
- package/libs/sheet-command-batch.ts +44 -0
- package/libs/sheet-view-realtime-router.test.ts +214 -0
- package/libs/sheet-view-realtime-router.ts +99 -0
- package/loaders/campaign.test.ts +186 -0
- package/loaders/campaign.ts +56 -83
- package/loaders/emailPreference.ts +75 -0
- package/loaders/rest.ts +12 -0
- package/package.json +42 -17
- package/schedule.d.ts +1790 -0
- package/sse.helpers.ts +19 -0
- package/sse.ts +26 -115
- package/tests/agent-note-detail-cache.test.ts +120 -0
- package/tests/agent-note-search.test.ts +444 -0
- package/types.d.ts +46 -25
- package/client/data-table-realtime-subscriptions.test.ts +0 -740
- package/client/data-table-realtime-subscriptions.ts +0 -955
- package/client/data-table-realtime.test.ts +0 -792
- package/client/data-table-realtime.ts +0 -1218
- package/client/fragment-realtime-sequence.ts +0 -52
- package/client/open-sheet.ts +0 -137
- package/client/request-no-store.test.ts +0 -157
- package/gql/fragments/agentDocFragments.ts +0 -46
- package/gql/fragments/billingFragments.ts +0 -14
- package/gql/mutations/agentDocMutations.ts +0 -177
- package/gql/queries/agentDocQueries.ts +0 -120
- package/hooks/use-agentDoc-mtn.ts +0 -285
- package/hooks/use-agentDoc-qry.ts +0 -208
- /package/{client → libs}/sse-ticket.test.ts +0 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { FRAGMENT_NAMES, makeFragmentKey } from '@jsb188/mday/constants/graphqlReactivity.ts';
|
|
2
|
+
import { mergeAIChatRuns } from '@jsb188/mday/utils/aiChatWork.ts';
|
|
3
|
+
import { isOlderChatCheckpoint } from '../sse.helpers.ts';
|
|
4
|
+
import { graphQLValuesEqual } from './value.helpers.ts';
|
|
5
|
+
|
|
6
|
+
const FIELD_SELECTIONS = new WeakMap<any[], Map<string, any>>();
|
|
7
|
+
|
|
8
|
+
/* Reuse a fragment's field lookup instead of scanning its AST for every value. */
|
|
9
|
+
function getFieldSelections(selections: any[]) {
|
|
10
|
+
let fields = FIELD_SELECTIONS.get(selections);
|
|
11
|
+
if (!fields) {
|
|
12
|
+
fields = new Map(
|
|
13
|
+
selections
|
|
14
|
+
.filter((selection) => selection.kind === 'Field')
|
|
15
|
+
.map((selection) => [selection.alias?.value || selection.name.value, selection]),
|
|
16
|
+
);
|
|
17
|
+
FIELD_SELECTIONS.set(selections, fields);
|
|
18
|
+
}
|
|
19
|
+
return fields;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/*
|
|
23
|
+
* Merge partial GraphQL objects while replacing atomic JSON scalars, lists and
|
|
24
|
+
* nulls. Selected object fields may preserve unrequested children; a different
|
|
25
|
+
* entity id must never inherit the previous entity's fields. Equal values keep
|
|
26
|
+
* their references so downstream cache comparisons can stop immediately.
|
|
27
|
+
*/
|
|
28
|
+
export function mergeGraphQLObjectData(current: any, incoming: any, selections?: any[]): any {
|
|
29
|
+
if (current === incoming || incoming === undefined) return current;
|
|
30
|
+
if (incoming === null || typeof incoming !== 'object') return incoming;
|
|
31
|
+
if (Array.isArray(incoming)) return graphQLValuesEqual(current, incoming) ? current : [...incoming];
|
|
32
|
+
const previous =
|
|
33
|
+
current &&
|
|
34
|
+
typeof current === 'object' &&
|
|
35
|
+
!Array.isArray(current) &&
|
|
36
|
+
!(current.id != null && incoming.id != null && current.id !== incoming.id)
|
|
37
|
+
? current
|
|
38
|
+
: {};
|
|
39
|
+
const fields = selections ? getFieldSelections(selections) : null;
|
|
40
|
+
let result = previous;
|
|
41
|
+
for (const key of Object.keys(incoming)) {
|
|
42
|
+
if (incoming[key] === undefined) continue;
|
|
43
|
+
const field = fields?.get(key);
|
|
44
|
+
const value =
|
|
45
|
+
field && !field.selectionSet
|
|
46
|
+
? graphQLValuesEqual(previous[key], incoming[key])
|
|
47
|
+
? previous[key]
|
|
48
|
+
: incoming[key]
|
|
49
|
+
: mergeGraphQLObjectData(previous[key], incoming[key], field?.selectionSet?.selections);
|
|
50
|
+
if (!Object.hasOwn(previous, key) || value !== previous[key]) {
|
|
51
|
+
if (result === previous) result = { ...previous };
|
|
52
|
+
result[key] = value;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/*
|
|
59
|
+
* Chat snapshots race the durable SSE stream, so their versioned fields must
|
|
60
|
+
* merge monotonically at the shared normalization boundary. Other fragments
|
|
61
|
+
* retain the cache's existing merge behavior.
|
|
62
|
+
*/
|
|
63
|
+
export function reconcileAIChatCacheSnapshot(fragmentKey: string, current: any, incoming: any, readFragment: (key: string) => any) {
|
|
64
|
+
if (incoming == null) return incoming;
|
|
65
|
+
if (fragmentKey.startsWith(FRAGMENT_NAMES.aiChat + ':')) {
|
|
66
|
+
// Preserve newer activity through delayed HTTP results, metadata edits and websocket echoes.
|
|
67
|
+
return current?.updatedAt && (!incoming.updatedAt || Date.parse(current.updatedAt) > Date.parse(incoming.updatedAt))
|
|
68
|
+
? { ...incoming, updatedAt: current.updatedAt, activityOrder: current.activityOrder }
|
|
69
|
+
: incoming;
|
|
70
|
+
}
|
|
71
|
+
if (fragmentKey.startsWith(FRAGMENT_NAMES.aiChatRun + ':')) {
|
|
72
|
+
return mergeAIChatRuns(current ? { [current.id]: current } : {}, [incoming])[incoming.id];
|
|
73
|
+
}
|
|
74
|
+
if (!fragmentKey.startsWith(FRAGMENT_NAMES.aiChatMessage + ':')) return incoming;
|
|
75
|
+
const next = isOlderChatCheckpoint(current, incoming) ? { ...incoming, ...current } : incoming;
|
|
76
|
+
// Run settlement is versioned independently from the message text checkpoint.
|
|
77
|
+
let run = incoming.run;
|
|
78
|
+
if (current?.run && (!run || (current.run.id !== run.id && Date.parse(current.run.createdAt) > Date.parse(run.createdAt)))) {
|
|
79
|
+
run = current.run;
|
|
80
|
+
}
|
|
81
|
+
if (!run?.id) return next;
|
|
82
|
+
const canonical = readFragment(makeFragmentKey(FRAGMENT_NAMES.aiChatRun, run.id));
|
|
83
|
+
const previous = current?.run?.id === run.id ? current.run : null;
|
|
84
|
+
const received = incoming.run?.id === run.id ? incoming.run : null;
|
|
85
|
+
return { ...next, run: mergeAIChatRuns({}, [previous, received, canonical])[run.id] };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/*
|
|
89
|
+
* Read only references stored inside this query, never the global fragment
|
|
90
|
+
* cache. A cached document outside the list must still trigger recovery.
|
|
91
|
+
*/
|
|
92
|
+
export function queryReferencesFragment(value: unknown, fragmentKey: string): boolean {
|
|
93
|
+
if (!value || typeof value !== 'object') return false;
|
|
94
|
+
if (Array.isArray(value)) return value.some((item) => item === fragmentKey || queryReferencesFragment(item, fragmentKey));
|
|
95
|
+
return Object.values(value).some((item) => queryReferencesFragment(item, fragmentKey));
|
|
96
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { gql } from 'graphql-tag';
|
|
2
|
+
import { makeGraphQLVariablesKey } from '@jsb188/app/utils/logic.ts';
|
|
3
|
+
import { clearGraphQLClientCache, fetchCachedData, loadDataFromCache, loadFragment, setDataToCache } from './index.ts';
|
|
4
|
+
import { cacheStore } from './store.ts';
|
|
5
|
+
import { graphQLValuesEqual } from './value.helpers.ts';
|
|
6
|
+
import { makeQueryResetTarget, queryCacheKeyMatchesResetTarget } from '@jsb188/app/utils/queryReset.ts';
|
|
7
|
+
|
|
8
|
+
/* Assert response values without collapsing undefined, null or empty objects. */
|
|
9
|
+
function equal(actual: any, expected: any) {
|
|
10
|
+
if (!graphQLValuesEqual(actual, expected))
|
|
11
|
+
throw new Error(`Expected ${JSON.stringify(expected)}, received ${JSON.stringify(actual)}`);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const ORGANIZATIONS = gql`
|
|
15
|
+
fragment relationshipFragment on Relationship { id name }
|
|
16
|
+
query myOrganizations {
|
|
17
|
+
myOrganizations {
|
|
18
|
+
...relationshipFragment
|
|
19
|
+
billingAccess { enforcement planKey }
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
`;
|
|
23
|
+
|
|
24
|
+
Deno.test('nullable billing access remains complete through object/null transitions and legacy cache repair', () => {
|
|
25
|
+
clearGraphQLClientCache();
|
|
26
|
+
const variables = makeGraphQLVariablesKey(undefined);
|
|
27
|
+
for (const billingAccess of [null, { enforcement: 'ACTIVE', planKey: null }, null]) {
|
|
28
|
+
const data = { myOrganizations: [{ id: 'org-1', name: 'Marketday', billingAccess }] };
|
|
29
|
+
setDataToCache(data, ORGANIZATIONS);
|
|
30
|
+
equal(fetchCachedData(ORGANIZATIONS, variables), data);
|
|
31
|
+
equal(loadFragment('$relationshipFragment:org-1'), data.myOrganizations[0]);
|
|
32
|
+
}
|
|
33
|
+
cacheStore.fragments.set('$relationshipFragment:org-1.spreads', {
|
|
34
|
+
billingAccess: [
|
|
35
|
+
['enforcement', undefined],
|
|
36
|
+
['planKey', undefined],
|
|
37
|
+
],
|
|
38
|
+
});
|
|
39
|
+
cacheStore.fragments.set('$relationshipFragment:org-1', { id: 'org-1', name: 'Marketday' });
|
|
40
|
+
equal(fetchCachedData(ORGANIZATIONS, variables), null);
|
|
41
|
+
const healed = { myOrganizations: [{ id: 'org-1', name: 'Marketday', billingAccess: null }] };
|
|
42
|
+
setDataToCache(healed, ORGANIZATIONS);
|
|
43
|
+
equal(fetchCachedData(ORGANIZATIONS, variables), healed);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
Deno.test('a mutation can shrink or clear nested lists without resurrecting removed members', () => {
|
|
47
|
+
clearGraphQLClientCache();
|
|
48
|
+
const query = gql`fragment parentFragment on Parent { id } fragment childFragment on Child { id name }
|
|
49
|
+
query parent { parent { ...parentFragment children { ...childFragment } } }`;
|
|
50
|
+
const mutation = gql`fragment parentFragment on Parent { id } fragment childFragment on Child { id name }
|
|
51
|
+
mutation editParent { editParent { ...parentFragment children { ...childFragment } } }`;
|
|
52
|
+
const children = [
|
|
53
|
+
{ id: 'child-1', name: 'One' },
|
|
54
|
+
{ id: 'child-2', name: 'Two' },
|
|
55
|
+
];
|
|
56
|
+
setDataToCache({ parent: { id: 'parent-1', children } }, query);
|
|
57
|
+
for (const nextChildren of [children.slice(1), [], null, [null, children[0]]]) {
|
|
58
|
+
setDataToCache({ editParent: { id: 'parent-1', children: nextChildren } }, mutation);
|
|
59
|
+
equal(fetchCachedData(query, makeGraphQLVariablesKey(undefined)), { parent: { id: 'parent-1', children: nextChildren } });
|
|
60
|
+
}
|
|
61
|
+
cacheStore.fragments.delete('$childFragment:child-1');
|
|
62
|
+
equal(fetchCachedData(query, makeGraphQLVariablesKey(undefined)), null);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
Deno.test('explicit root null and scalar values replace old cache and are reusable', () => {
|
|
66
|
+
clearGraphQLClientCache();
|
|
67
|
+
const query = gql`query record { record { id } }`;
|
|
68
|
+
setDataToCache({ record: { id: 'record-1' } }, query);
|
|
69
|
+
setDataToCache({ record: null }, query);
|
|
70
|
+
equal(fetchCachedData(query, makeGraphQLVariablesKey(undefined)), { record: null });
|
|
71
|
+
equal(loadDataFromCache({ record: null }, query, makeGraphQLVariablesKey(undefined), undefined, { record: '$recordFragment:old' }), {
|
|
72
|
+
record: null,
|
|
73
|
+
});
|
|
74
|
+
const scalars = gql`query counts { count enabled message labels }`;
|
|
75
|
+
const data = { count: 0, enabled: false, message: '', labels: ['one', null, 'two'] };
|
|
76
|
+
setDataToCache(data, scalars);
|
|
77
|
+
equal(fetchCachedData(scalars, makeGraphQLVariablesKey(undefined)), data);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
Deno.test('nested aliases, nullable list members and direct inline fields round-trip', () => {
|
|
81
|
+
clearGraphQLClientCache();
|
|
82
|
+
const query = gql`query result { result { label: name entries { __typename ... on Entry { label: name } } } }`;
|
|
83
|
+
const data = { result: { label: 'Result', entries: [null, { __typename: 'Entry', label: 'Entry' }] } };
|
|
84
|
+
setDataToCache(data, query);
|
|
85
|
+
equal(fetchCachedData(query, makeGraphQLVariablesKey(undefined)), data);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
Deno.test('cache reads preserve empty JSON objects and equal writes retain memoized references', () => {
|
|
89
|
+
clearGraphQLClientCache();
|
|
90
|
+
const query = gql`fragment jsonFragment on Record { id settings } query record { record { ...jsonFragment } }`;
|
|
91
|
+
const settings = Object.freeze({});
|
|
92
|
+
const data = { record: { id: 'record-1', settings } };
|
|
93
|
+
setDataToCache(data, query);
|
|
94
|
+
const first = fetchCachedData(query, makeGraphQLVariablesKey(undefined));
|
|
95
|
+
equal(first, data);
|
|
96
|
+
setDataToCache({ record: { settings: {}, id: 'record-1' } }, query);
|
|
97
|
+
if (fetchCachedData(query, makeGraphQLVariablesKey(undefined)) !== first)
|
|
98
|
+
throw new Error('Equal writes invalidated the memoized result');
|
|
99
|
+
equal(settings, {});
|
|
100
|
+
equal(graphQLValuesEqual({ field: undefined }, {}), false);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
Deno.test('GraphQL cache identity preserves case, types, nulls and delimiters while resets remain compatible', () => {
|
|
104
|
+
const inputs = [
|
|
105
|
+
{ value: 'ABC' },
|
|
106
|
+
{ value: 'abc' },
|
|
107
|
+
{ value: 1 },
|
|
108
|
+
{ value: '1' },
|
|
109
|
+
{ value: null },
|
|
110
|
+
{ value: '' },
|
|
111
|
+
{},
|
|
112
|
+
{ value: '$other:1' },
|
|
113
|
+
];
|
|
114
|
+
const keys = inputs.map(makeGraphQLVariablesKey);
|
|
115
|
+
equal(new Set(keys).size, inputs.length);
|
|
116
|
+
equal(makeGraphQLVariablesKey({ b: { two: 2, one: 1 }, a: undefined }), makeGraphQLVariablesKey({ b: { one: 1, two: 2 } }));
|
|
117
|
+
const queryKey =
|
|
118
|
+
'#rows:' + makeGraphQLVariablesKey({ organizationId: 'ORG-A', filter: { schemaId: 'SCHEMA-A' }, text: '$organizationid:org-b' });
|
|
119
|
+
equal(
|
|
120
|
+
queryCacheKeyMatchesResetTarget(
|
|
121
|
+
queryKey,
|
|
122
|
+
makeQueryResetTarget('rows', { organizationId: 'ORG-A', 'filter.schemaId': 'SCHEMA-A' }),
|
|
123
|
+
),
|
|
124
|
+
true,
|
|
125
|
+
);
|
|
126
|
+
equal(queryCacheKeyMatchesResetTarget(queryKey, makeQueryResetTarget('rows', { organizationId: 'org-b' })), false);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
Deno.test('mutation responses update shared fragments without storing a reusable mutation root', () => {
|
|
130
|
+
clearGraphQLClientCache();
|
|
131
|
+
const mutation = gql`fragment recordFragment on Record { id name } mutation editRecord { editRecord { ...recordFragment } }`;
|
|
132
|
+
setDataToCache({ editRecord: { id: 'record-1', name: 'Updated' } }, mutation);
|
|
133
|
+
equal(loadFragment('$recordFragment:record-1'), { id: 'record-1', name: 'Updated' });
|
|
134
|
+
equal(fetchCachedData(mutation, makeGraphQLVariablesKey(undefined)), null);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
Deno.test('a server JSON scalar replaces deleted keys in fragment and inline object selections', () => {
|
|
138
|
+
clearGraphQLClientCache();
|
|
139
|
+
const query = gql`fragment settingsFragment on Record { id settings address { city region } } query record { record { ...settingsFragment } }`;
|
|
140
|
+
setDataToCache({ record: { id: 'record-1', settings: { removed: true }, address: { city: 'Old', region: 'Ontario' } } }, query);
|
|
141
|
+
setDataToCache({ record: { id: 'record-1', settings: {}, address: { city: 'New', region: 'Ontario' } } }, query);
|
|
142
|
+
equal(fetchCachedData(query, makeGraphQLVariablesKey(undefined)), {
|
|
143
|
+
record: { id: 'record-1', settings: {}, address: { city: 'New', region: 'Ontario' } },
|
|
144
|
+
});
|
|
145
|
+
const inline = gql`fragment inlineSettingsFragment on Record { id } query inlineRecord { inlineRecord { ...inlineSettingsFragment config { settings } } }`;
|
|
146
|
+
setDataToCache({ inlineRecord: { id: 'inline-1', config: { settings: { removed: true } } } }, inline);
|
|
147
|
+
setDataToCache({ inlineRecord: { id: 'inline-1', config: { settings: {} } } }, inline);
|
|
148
|
+
equal(fetchCachedData(inline, makeGraphQLVariablesKey(undefined)), { inlineRecord: { id: 'inline-1', config: { settings: {} } } });
|
|
149
|
+
});
|